Feature/null refactor (#173)

* WIP: rebase

* Make nullable fields use pointers
This commit is contained in:
a_bennassar
2020-10-06 10:34:49 +02:00
committed by GitHub
parent 7df9288977
commit 49366e3fa4
32 changed files with 422 additions and 240 deletions

View File

@@ -223,7 +223,7 @@ func TestMain(m *testing.M) {
panic("Token not found")
}
} else {
token = test.GetToken(genericTx.FromIdx, accs, tokens)
token = test.GetToken(*genericTx.FromIdx, accs, tokens)
}
var usd, loadUSD, feeUSD *float64
if token.USD != nil {
@@ -244,7 +244,7 @@ func TestMain(m *testing.M) {
Type: genericTx.Type,
Position: genericTx.Position,
FromIdx: genericTx.FromIdx,
ToIdx: genericTx.ToIdx,
ToIdx: *genericTx.ToIdx,
Amount: genericTx.Amount,
AmountFloat: genericTx.AmountFloat,
HistoricUSD: usd,
@@ -361,7 +361,7 @@ func TestGetHistoryTxs(t *testing.T) {
// idx
fetchedTxs = historyTxAPIs{}
limit = 4
idx := tc.allTxs[0].FromIdx
idx := tc.allTxs[0].ToIdx
path = fmt.Sprintf(
"%s?accountIndex=%s&limit=%d&offset=",
endpoint, idx, limit,
@@ -370,7 +370,8 @@ func TestGetHistoryTxs(t *testing.T) {
assert.NoError(t, err)
idxTxs := historyTxAPIs{}
for i := 0; i < len(tc.allTxs); i++ {
if tc.allTxs[i].FromIdx[6:] == idx[6:] {
if (tc.allTxs[i].FromIdx != nil && (*tc.allTxs[i].FromIdx)[6:] == idx[6:]) ||
tc.allTxs[i].ToIdx[6:] == idx[6:] {
idxTxs = append(idxTxs, tc.allTxs[i])
}
}
@@ -396,7 +397,6 @@ func TestGetHistoryTxs(t *testing.T) {
// type
txTypes := []common.TxType{
common.TxTypeExit,
common.TxTypeWithdrawn,
common.TxTypeTransfer,
common.TxTypeDeposit,
common.TxTypeCreateAccountDeposit,

View File

@@ -38,7 +38,7 @@ func (htx *historyTxsAPI) GetPagination() pagination { return htx.Pagination }
func (htx *historyTxsAPI) Len() int { return len(htx.Txs) }
type l1Info struct {
ToForgeL1TxsNum int64 `json:"toForgeL1TransactionsNum"`
ToForgeL1TxsNum *int64 `json:"toForgeL1TransactionsNum"`
UserOrigin bool `json:"userOrigin"`
FromEthAddr string `json:"fromHezEthereumAddress"`
FromBJJ string `json:"fromBJJ"`
@@ -58,7 +58,7 @@ type historyTxAPI struct {
TxID string `json:"id"`
Type common.TxType `json:"type"`
Position int `json:"position"`
FromIdx string `json:"fromAccountIndex"`
FromIdx *string `json:"fromAccountIndex"`
ToIdx string `json:"toAccountIndex"`
Amount string `json:"amount"`
BatchNum *common.BatchNum `json:"batchNum"`
@@ -76,7 +76,6 @@ func historyTxsToAPI(dbTxs []*historydb.HistoryTx) []historyTxAPI {
TxID: dbTxs[i].TxID.String(),
Type: dbTxs[i].Type,
Position: dbTxs[i].Position,
FromIdx: idxToHez(dbTxs[i].FromIdx, dbTxs[i].TokenSymbol),
ToIdx: idxToHez(dbTxs[i].ToIdx, dbTxs[i].TokenSymbol),
Amount: dbTxs[i].Amount.String(),
HistoricUSD: dbTxs[i].HistoricUSD,
@@ -95,12 +94,17 @@ func historyTxsToAPI(dbTxs []*historydb.HistoryTx) []historyTxAPI {
L1Info: nil,
L2Info: nil,
}
if dbTxs[i].FromIdx != nil {
fromIdx := new(string)
*fromIdx = idxToHez(*dbTxs[i].FromIdx, dbTxs[i].TokenSymbol)
apiTx.FromIdx = fromIdx
}
if dbTxs[i].IsL1 {
apiTx.IsL1 = "L1"
apiTx.L1Info = &l1Info{
ToForgeL1TxsNum: dbTxs[i].ToForgeL1TxsNum,
UserOrigin: dbTxs[i].UserOrigin,
FromEthAddr: ethAddrToHez(dbTxs[i].FromEthAddr),
UserOrigin: *dbTxs[i].UserOrigin,
FromEthAddr: ethAddrToHez(*dbTxs[i].FromEthAddr),
FromBJJ: bjjToString(dbTxs[i].FromBJJ),
LoadAmount: dbTxs[i].LoadAmount.String(),
HistoricLoadAmountUSD: dbTxs[i].HistoricLoadAmountUSD,

View File

@@ -149,9 +149,6 @@ func parseQueryTxType(c querier) (*common.TxType, error) {
case common.TxTypeExit:
ret := common.TxTypeExit
return &ret, nil
case common.TxTypeWithdrawn:
ret := common.TxTypeWithdrawn
return &ret, nil
case common.TxTypeTransfer:
ret := common.TxTypeTransfer
return &ret, nil

View File

@@ -239,10 +239,6 @@ func TestParseQueryTxType(t *testing.T) {
res, err = parseQueryTxType(c)
assert.NoError(t, err)
assert.Equal(t, common.TxTypeExit, *res)
c.m[name] = string(common.TxTypeWithdrawn)
res, err = parseQueryTxType(c)
assert.NoError(t, err)
assert.Equal(t, common.TxTypeWithdrawn, *res)
c.m[name] = string(common.TxTypeTransfer)
res, err = parseQueryTxType(c)
assert.NoError(t, err)

View File

@@ -1240,13 +1240,24 @@ components:
fromAccountIndex:
$ref: '#/components/schemas/AccountIndex'
toAccountIndex:
allOf:
- $ref: '#/components/schemas/AccountIndex'
- example: "hez:DAI:672"
type: string
description: >-
Identifier of the destination account. It references the position where the account is inside the state Merkle tree.
The identifier is built using: `hez:` + `token symbol:` + `index`
example: null
nullable: true
toHezEthereumAddress:
$ref: '#/components/schemas/HezEthereumAddress'
type: string
description: "Address of an Etherum account linked to the Hermez network."
pattern: "^hez:0x[a-fA-F0-9]{40}$"
example: "hez:0xaa942cfcd25ad4d90a62358b0dd84f33b398262a"
nullable: true
toBjj:
$ref: '#/components/schemas/BJJ'
type: string
description: "BabyJubJub public key, encoded as base64 URL (RFC 4648), which result in 33 bytes. The padding byte is replaced by a sum of the encoded bytes."
pattern: "^hez:[A-Za-z0-9_-]{44}$"
example: null
nullable: true
amount:
allOf:
- $ref: '#/components/schemas/BigInt'
@@ -1308,6 +1319,7 @@ components:
- type
- tokenId
- fromAccountIndex
- toAccountIndex
- toHezAccountIndex
- toHezEthereumAddress
- toBjj
@@ -1333,13 +1345,24 @@ components:
fromAccountIndex:
$ref: '#/components/schemas/AccountIndex'
toAccountIndex:
allOf:
- $ref: '#/components/schemas/AccountIndex'
- example: "hez:DAI:672"
type: string
description: >-
Identifier of the destination account. It references the position where the account is inside the state Merkle tree.
The identifier is built using: `hez:` + `token symbol:` + `index`
example: "hez:DAI:309"
nullable: true
toHezEthereumAddress:
$ref: '#/components/schemas/HezEthereumAddress'
type: string
description: "Address of an Etherum account linked to the Hermez network."
pattern: "^hez:0x[a-fA-F0-9]{40}$"
example: null
nullable: true
toBjj:
$ref: '#/components/schemas/BJJ'
type: string
description: "BabyJubJub public key, encoded as base64 URL (RFC 4648), which result in 33 bytes. The padding byte is replaced by a sum of the encoded bytes."
pattern: "^hez:[A-Za-z0-9_-]{44}$"
example: null
nullable: true
amount:
allOf:
- $ref: '#/components/schemas/BigInt'
@@ -1448,7 +1471,6 @@ components:
description: Type of transaction.
enum:
- Exit
- Withdrawn
- Transfer
- Deposit
- CreateAccountDeposit
@@ -1539,7 +1561,12 @@ components:
position:
$ref: '#/components/schemas/TransactionPosition'
fromAccountIndex:
$ref: '#/components/schemas/AccountIndex'
type: string
description: >-
Identifier of an account. It references the position where the account is inside the state Merkle tree.
The identifier is built using: `hez:` + `token symbol:` + `index`
example: "hez:DAI:4444"
nullable: true
toAccountIndex:
allOf:
- $ref: '#/components/schemas/AccountIndex'
@@ -1666,6 +1693,7 @@ components:
minimum: 0
maximum: 4294967295
example: 784
nullable: true
TransactionPosition:
type: integer
description: Position that a transaction occupies in a batch.
@@ -1689,8 +1717,8 @@ components:
items:
type: object
properties:
token:
$ref: '#/components/schemas/Token'
tokenId:
$ref: '#/components/schemas/TokenId'
amount:
allOf:
- $ref: '#/components/schemas/BigInt'
@@ -1716,6 +1744,9 @@ components:
$ref: '#/components/schemas/EthereumAddress'
collectedFees:
$ref: '#/components/schemas/CollectedFees'
totalCollectedFeesUSD:
type: number
description: Value in USD of the collected tokens by the forger in concept of fees. This is calculated at the moment the batch is forged, with the conversion rates at that time.
historicTotalCollectedFeesUSD:
type: number
description: Sum of the all the fees collected, in USD, at the moment the batch was forged.
@@ -1737,7 +1768,6 @@ components:
allOf:
- $ref: '#/components/schemas/ToForgeL1TransactionsNum'
- description: Identifier that corresponds to the group of L1 transactions forged in the current batch.
- nullable: true
- example: 5
slotNum:
$ref: '#/components/schemas/SlotNum'