mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Merge pull request #338 from hermeznetwork/feature/api-amounts
Add amount success and load amount success
This commit is contained in:
@@ -1750,6 +1750,22 @@ components:
|
|||||||
- $ref: '#/components/schemas/BigInt'
|
- $ref: '#/components/schemas/BigInt'
|
||||||
- description: Tokens transfered from L1 to L2.
|
- description: Tokens transfered from L1 to L2.
|
||||||
- example: "4900000000000000000"
|
- 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:
|
historicDepositAmountUSD:
|
||||||
type: number
|
type: number
|
||||||
description: Load amount in USD, at the moment the transaction was made.
|
description: Load amount in USD, at the moment the transaction was made.
|
||||||
@@ -1764,6 +1780,8 @@ components:
|
|||||||
- toForgeL1TransactionsNum
|
- toForgeL1TransactionsNum
|
||||||
- userOrigin
|
- userOrigin
|
||||||
- depositAmount
|
- depositAmount
|
||||||
|
- amountSuccess
|
||||||
|
- depositAmountSuccess
|
||||||
- historicDepositAmountUSD
|
- historicDepositAmountUSD
|
||||||
- ethereumBlockNum
|
- ethereumBlockNum
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ type testL1Info struct {
|
|||||||
ToForgeL1TxsNum *int64 `json:"toForgeL1TransactionsNum"`
|
ToForgeL1TxsNum *int64 `json:"toForgeL1TransactionsNum"`
|
||||||
UserOrigin bool `json:"userOrigin"`
|
UserOrigin bool `json:"userOrigin"`
|
||||||
DepositAmount string `json:"depositAmount"`
|
DepositAmount string `json:"depositAmount"`
|
||||||
|
AmountSuccess bool `json:"amountSuccess"`
|
||||||
|
DepositAmountSuccess bool `json:"depositAmountSuccess"`
|
||||||
HistoricDepositAmountUSD *float64 `json:"historicDepositAmountUSD"`
|
HistoricDepositAmountUSD *float64 `json:"historicDepositAmountUSD"`
|
||||||
EthBlockNum int64 `json:"ethereumBlockNum"`
|
EthBlockNum int64 `json:"ethereumBlockNum"`
|
||||||
}
|
}
|
||||||
@@ -126,6 +128,8 @@ func genTestTxs(
|
|||||||
ToForgeL1TxsNum: l1.ToForgeL1TxsNum,
|
ToForgeL1TxsNum: l1.ToForgeL1TxsNum,
|
||||||
UserOrigin: l1.UserOrigin,
|
UserOrigin: l1.UserOrigin,
|
||||||
DepositAmount: l1.DepositAmount.String(),
|
DepositAmount: l1.DepositAmount.String(),
|
||||||
|
AmountSuccess: true,
|
||||||
|
DepositAmountSuccess: true,
|
||||||
EthBlockNum: l1.EthBlockNum,
|
EthBlockNum: l1.EthBlockNum,
|
||||||
},
|
},
|
||||||
Token: token,
|
Token: token,
|
||||||
|
|||||||
@@ -879,15 +879,17 @@ func (hdb *HistoryDB) addTxs(d meddler.DB, txs []txWrite) error {
|
|||||||
|
|
||||||
// GetHistoryTx returns a tx from the DB given a TxID
|
// GetHistoryTx returns a tx from the DB given a TxID
|
||||||
func (hdb *HistoryDB) GetHistoryTx(txID common.TxID) (*TxAPI, error) {
|
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{}
|
tx := &TxAPI{}
|
||||||
err := meddler.QueryRow(
|
err := meddler.QueryRow(
|
||||||
hdb.db, tx, `SELECT tx.item_id, tx.is_l1, tx.id, tx.type, tx.position,
|
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.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,
|
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.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.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.eth_addr, token.name, token.symbol, token.decimals, token.usd,
|
||||||
token.usd_update, block.timestamp
|
token.usd_update, block.timestamp
|
||||||
@@ -905,7 +907,9 @@ func (hdb *HistoryDB) GetHistoryTxs(
|
|||||||
tokenID *common.TokenID, idx *common.Idx, batchNum *uint, txType *common.TxType,
|
tokenID *common.TokenID, idx *common.Idx, batchNum *uint, txType *common.TxType,
|
||||||
fromItem, limit *uint, order string,
|
fromItem, limit *uint, order string,
|
||||||
) ([]TxAPI, uint64, error) {
|
) ([]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 {
|
if ethAddr != nil && bjj != nil {
|
||||||
return nil, 0, tracerr.Wrap(errors.New("ethAddr and bjj are incompatible"))
|
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,
|
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.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,
|
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.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.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.eth_addr, token.name, token.symbol, token.decimals, token.usd,
|
||||||
token.usd_update, block.timestamp, count(*) OVER() AS total_items
|
token.usd_update, block.timestamp, count(*) OVER() AS total_items
|
||||||
|
|||||||
@@ -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
|
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"`
|
DepositAmount *apitypes.BigIntStr `meddler:"deposit_amount"`
|
||||||
HistoricDepositAmountUSD *float64 `meddler:"deposit_amount_usd"`
|
HistoricDepositAmountUSD *float64 `meddler:"deposit_amount_usd"`
|
||||||
|
AmountSuccess bool `meddler:"amount_success"`
|
||||||
|
DepositAmountSuccess bool `meddler:"deposit_amount_success"`
|
||||||
// L2
|
// L2
|
||||||
Fee *common.FeeSelector `meddler:"fee"`
|
Fee *common.FeeSelector `meddler:"fee"`
|
||||||
HistoricFeeUSD *float64 `meddler:"fee_usd"`
|
HistoricFeeUSD *float64 `meddler:"fee_usd"`
|
||||||
@@ -90,10 +92,18 @@ func (tx TxAPI) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
if tx.IsL1 {
|
if tx.IsL1 {
|
||||||
jsonTx["L1orL2"] = "L1"
|
jsonTx["L1orL2"] = "L1"
|
||||||
|
amountSuccess := tx.AmountSuccess
|
||||||
|
depositAmountSuccess := tx.DepositAmountSuccess
|
||||||
|
if tx.BatchNum == nil {
|
||||||
|
amountSuccess = false
|
||||||
|
depositAmountSuccess = false
|
||||||
|
}
|
||||||
jsonTx["L1Info"] = map[string]interface{}{
|
jsonTx["L1Info"] = map[string]interface{}{
|
||||||
"toForgeL1TransactionsNum": tx.ToForgeL1TxsNum,
|
"toForgeL1TransactionsNum": tx.ToForgeL1TxsNum,
|
||||||
"userOrigin": tx.UserOrigin,
|
"userOrigin": tx.UserOrigin,
|
||||||
"depositAmount": tx.DepositAmount,
|
"depositAmount": tx.DepositAmount,
|
||||||
|
"amountSuccess": amountSuccess,
|
||||||
|
"depositAmountSuccess": depositAmountSuccess,
|
||||||
"historicDepositAmountUSD": tx.HistoricDepositAmountUSD,
|
"historicDepositAmountUSD": tx.HistoricDepositAmountUSD,
|
||||||
"ethereumBlockNum": tx.EthBlockNum,
|
"ethereumBlockNum": tx.EthBlockNum,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user