tx_utils library

Enums

TxType

Constants

bitsShiftPrecision → const int
hermezPrefix → const String
txState → const Map<String, String>
txType → const Map<String, String>

Properties

nativeExampleLib DynamicLibrary
final

Functions

buildElement1(Map<String, dynamic> tx) BigInt
Build element_1 for L2HashSignature @param {Object} tx - Transaction object returned by encodeTransaction @returns {BigInt} element_1 L2 signature
buildTransactionHashMessage(Map<String, dynamic> encodedTransaction) BigInt
Builds the message to hash
buildTxCompressedData(Map<String, dynamic> tx) BigInt
Encode tx compressed data @param {Object} tx - Transaction object @returns {BigInt} Encoded tx compressed data
encodeTransaction(Map<String, dynamic> transaction, {String? providerUrl}) Map<String, dynamic>
Encodes the transaction object to be in a format supported by the Smart Contracts and Circuits. Used, for example, to sign the transaction
generateL2Transaction(Map tx, String? bjj, Token token) Future<Set<Map<String, dynamic>>>
Prepares a transaction to be ready to be sent to a Coordinator.
getFeeIndex(num fee, num amount) int
Calculates the appropriate fee factor depending on what's the fee as a percentage of the amount
getFeeValue(num feeIndex, num amount) BigInt
Compute fee in token value with an amount and a fee index @param {Number} feeIndex - Fee selected among 0 - 255 @param {Number} amount - The amount of the transaction as a Scalar @returns {BigInt} Resulting fee in token value
getL1UserTxId(BigInt toForgeL1TxsNum, BigInt currentPosition) String
Generates the L1 Transaction Id based on the spec TxID (32 bytes) for L1Tx is the Keccak256 (ethereum) hash of: bytes: | 1 byte | 32 bytes | SHA256( 8 bytes | 2 bytes ) content: | type | SHA256(ToForgeL1TxsNum | Position ) where type for L1UserTx is 0 @param {Number} toForgeL1TxsNum @param {Number} currentPosition
getL2TxId(int fromIdx, int tokenId, double amount, int nonce, int fee) String
Generates the Transaction Id based on the spec TxID (33 bytes) for L2Tx is: bytes: | 1 byte | 32 bytes | SHA256( 6 bytes | 4 bytes | 2 bytes| 5 bytes | 1 byte ) content: | type | SHA256(FromIdx | TokenID | Amount | Nonce | Fee ) where type for L2Tx is '2' @param {Number} fromIdx - The account index that sends the transaction @param {Number} tokenId - The tokenId being transacted @param {Number} amount - The amount being transacted @param {Number} nonce - Nonce of the transaction @param {Number} fee - The fee of the transaction @returns {String} Transaction Id
getNonce(num? currentNonce, String? accountIndex, String? bjj, num? tokenId) Future<num?>
Calculates the appropriate nonce based on the current token account nonce and existing transactions in the Pool. It needs to find the lowest nonce available as transactions in the pool may fail and the Coordinator only forges transactions in the order set by nonces.
getTransactionType(Map transaction) String
Gets the transaction type depending on the information in the transaction object If an account index is used, it will be 'Transfer' If a Hermez address is used, it will be 'TransferToEthAddr' If a BabyJubJub is used, it will be 'TransferToBjj'