Browse Source

Add amount success and load amount success

feature/sql-semaphore1
Arnau B 4 years ago
parent
commit
e1d34e3796
4 changed files with 46 additions and 10 deletions
  1. +18
    -0
      api/swagger.yml
  2. +8
    -4
      api/txshistory_test.go
  3. +10
    -6
      db/historydb/historydb.go
  4. +10
    -0
      db/historydb/views.go

+ 18
- 0
api/swagger.yml

@ -1750,6 +1750,22 @@ components:
- $ref: '#/components/schemas/BigInt'
- description: Tokens transfered from L1 to L2.
- example: "4900000000000000000"
amountSuccess:
type: boolean
description: >-
Indicates if the amount specified by the user has been sent propperly. If false, the amount that actualy has been sent is 0.
If the transaction hasn't been forged yet (`batchNum == null`), this value will be false, as it's unknown if it has succeed or not.
An example were this value could be false: a user send a `DepositTransfer` transaction, but when the tx is forged there are not
enougth founds in the account. In this case the transfer part of the transaction won't be effective making the amount have a real value of 0.
example: true
depositAmountSuccess:
type: boolean
description: >-
Indicates if the deposit amount specified by the user has been sent propperly. If false, the deposit amount that actualy has been sent is 0.
If the transaction hasn't been forged yet (`batchNum == null`), this value will be false, as it's unknown if it has succeed or not.
An example were this value could be false: a user send a `Deposit` transaction, but when the tx is forged the token id is not registered on the network.
In this case transaction won't be effective making the deposit amount have a real value of 0.
example: true
historicDepositAmountUSD:
type: number
description: Load amount in USD, at the moment the transaction was made.
@ -1764,6 +1780,8 @@ components:
- toForgeL1TransactionsNum
- userOrigin
- depositAmount
- amountSuccess
- depositAmountSuccess
- historicDepositAmountUSD
- ethereumBlockNum
additionalProperties: false

+ 8
- 4
api/txshistory_test.go

@ -21,6 +21,8 @@ type testL1Info struct {
ToForgeL1TxsNum *int64 `json:"toForgeL1TransactionsNum"`
UserOrigin bool `json:"userOrigin"`
DepositAmount string `json:"depositAmount"`
AmountSuccess bool `json:"amountSuccess"`
DepositAmountSuccess bool `json:"depositAmountSuccess"`
HistoricDepositAmountUSD *float64 `json:"historicDepositAmountUSD"`
EthBlockNum int64 `json:"ethereumBlockNum"`
}
@ -123,10 +125,12 @@ func genTestTxs(
BatchNum: l1.BatchNum,
Timestamp: getTimestamp(l1.EthBlockNum, blocks),
L1Info: &testL1Info{
ToForgeL1TxsNum: l1.ToForgeL1TxsNum,
UserOrigin: l1.UserOrigin,
DepositAmount: l1.DepositAmount.String(),
EthBlockNum: l1.EthBlockNum,
ToForgeL1TxsNum: l1.ToForgeL1TxsNum,
UserOrigin: l1.UserOrigin,
DepositAmount: l1.DepositAmount.String(),
AmountSuccess: true,
DepositAmountSuccess: true,
EthBlockNum: l1.EthBlockNum,
},
Token: token,
}

+ 10
- 6
db/historydb/historydb.go

@ -879,15 +879,17 @@ func (hdb *HistoryDB) addTxs(d meddler.DB, txs []txWrite) error {
// GetHistoryTx returns a tx from the DB given a TxID
func (hdb *HistoryDB) GetHistoryTx(txID common.TxID) (*TxAPI, error) {
// TODO: add success flags for L1s
// Warning: amount_success and deposit_amount_success have true as default for
// performance reasons. The expected default value is false (when txs are unforged)
// this case is handled at the function func (tx TxAPI) MarshalJSON() ([]byte, error)
tx := &TxAPI{}
err := meddler.QueryRow(
hdb.db, tx, `SELECT tx.item_id, tx.is_l1, tx.id, tx.type, tx.position,
hez_idx(tx.from_idx, token.symbol) AS from_idx, tx.from_eth_addr, tx.from_bjj,
hez_idx(tx.to_idx, token.symbol) AS to_idx, tx.to_eth_addr, tx.to_bjj,
tx.amount, tx.token_id, tx.amount_usd,
tx.amount, tx.amount_success, tx.token_id, tx.amount_usd,
tx.batch_num, tx.eth_block_num, tx.to_forge_l1_txs_num, tx.user_origin,
tx.deposit_amount, tx.deposit_amount_usd, tx.fee, tx.fee_usd, tx.nonce,
tx.deposit_amount, tx.deposit_amount_usd, tx.deposit_amount_success, tx.fee, tx.fee_usd, tx.nonce,
token.token_id, token.item_id AS token_item_id, token.eth_block_num AS token_block,
token.eth_addr, token.name, token.symbol, token.decimals, token.usd,
token.usd_update, block.timestamp
@ -905,7 +907,9 @@ func (hdb *HistoryDB) GetHistoryTxs(
tokenID *common.TokenID, idx *common.Idx, batchNum *uint, txType *common.TxType,
fromItem, limit *uint, order string,
) ([]TxAPI, uint64, error) {
// TODO: add success flags for L1s
// Warning: amount_success and deposit_amount_success have true as default for
// performance reasons. The expected default value is false (when txs are unforged)
// this case is handled at the function func (tx TxAPI) MarshalJSON() ([]byte, error)
if ethAddr != nil && bjj != nil {
return nil, 0, tracerr.Wrap(errors.New("ethAddr and bjj are incompatible"))
}
@ -914,9 +918,9 @@ func (hdb *HistoryDB) GetHistoryTxs(
queryStr := `SELECT tx.item_id, tx.is_l1, tx.id, tx.type, tx.position,
hez_idx(tx.from_idx, token.symbol) AS from_idx, tx.from_eth_addr, tx.from_bjj,
hez_idx(tx.to_idx, token.symbol) AS to_idx, tx.to_eth_addr, tx.to_bjj,
tx.amount, tx.token_id, tx.amount_usd,
tx.amount, tx.amount_success, tx.token_id, tx.amount_usd,
tx.batch_num, tx.eth_block_num, tx.to_forge_l1_txs_num, tx.user_origin,
tx.deposit_amount, tx.deposit_amount_usd, tx.fee, tx.fee_usd, tx.nonce,
tx.deposit_amount, tx.deposit_amount_usd, tx.deposit_amount_success, tx.fee, tx.fee_usd, tx.nonce,
token.token_id, token.item_id AS token_item_id, token.eth_block_num AS token_block,
token.eth_addr, token.name, token.symbol, token.decimals, token.usd,
token.usd_update, block.timestamp, count(*) OVER() AS total_items

+ 10
- 0
db/historydb/views.go

@ -36,6 +36,8 @@ type TxAPI struct {
UserOrigin *bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
DepositAmount *apitypes.BigIntStr `meddler:"deposit_amount"`
HistoricDepositAmountUSD *float64 `meddler:"deposit_amount_usd"`
AmountSuccess bool `meddler:"amount_success"`
DepositAmountSuccess bool `meddler:"deposit_amount_success"`
// L2
Fee *common.FeeSelector `meddler:"fee"`
HistoricFeeUSD *float64 `meddler:"fee_usd"`
@ -90,10 +92,18 @@ func (tx TxAPI) MarshalJSON() ([]byte, error) {
}
if tx.IsL1 {
jsonTx["L1orL2"] = "L1"
amountSuccess := tx.AmountSuccess
depositAmountSuccess := tx.DepositAmountSuccess
if tx.BatchNum == nil {
amountSuccess = false
depositAmountSuccess = false
}
jsonTx["L1Info"] = map[string]interface{}{
"toForgeL1TransactionsNum": tx.ToForgeL1TxsNum,
"userOrigin": tx.UserOrigin,
"depositAmount": tx.DepositAmount,
"amountSuccess": amountSuccess,
"depositAmountSuccess": depositAmountSuccess,
"historicDepositAmountUSD": tx.HistoricDepositAmountUSD,
"ethereumBlockNum": tx.EthBlockNum,
}

Loading…
Cancel
Save