arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/common/tx.go
common/tx.goRaw
 1package common
 2
 3import (
 4	"encoding/binary"
 5	"math/big"
 6)
 7
 8// Idx represents the account Index in the MerkleTree
 9type Idx uint32
10
11// Bytes returns a byte array representing the Idx
12func (idx Idx) Bytes() []byte {
13	var b [4]byte
14	binary.LittleEndian.PutUint32(b[:], uint32(idx))
15	return b[:]
16}
17
18// BigInt returns a *big.Int representing the Idx
19func (idx Idx) BigInt() *big.Int {
20	return big.NewInt(int64(idx))
21}
22
23// IdxFromBigInt converts a *big.Int to Idx type
24func IdxFromBigInt(b *big.Int) (Idx, error) {
25	if b.Int64() > 0xffffffff { // 2**32-1
26		return 0, ErrNumOverflow
27	}
28	return Idx(uint32(b.Int64())), nil
29}
30
31// TxID is the identifier of a Hermez network transaction
32type TxID Hash // Hash is a guess
33
34// TxType is a string that represents the type of a Hermez network transaction
35type TxType string
36
37const (
38	// TxTypeExit represents L2->L1 token transfer.  A leaf for this account appears in the exit tree of the block
39	TxTypeExit TxType = "Exit"
40	// TxTypeWithdrawn represents the balance that was moved from L2->L1 has been widthrawn from the smart contract
41	TxTypeWithdrawn TxType = "Withdrawn"
42	// TxTypeTransfer represents L2->L2 token transfer
43	TxTypeTransfer TxType = "Transfer"
44	// TxTypeDeposit represents L1->L2 transfer
45	TxTypeDeposit TxType = "Deposit"
46	// TxTypeCreateAccountDeposit represents creation of a new leaf in the state tree (newAcconut) + L1->L2 transfer
47	TxTypeCreateAccountDeposit TxType = "CreateAccountDeposit"
48	// TxTypeCreateAccountDepositAndTransfer represents L1->L2 transfer + L2->L2 transfer
49	TxTypeCreateAccountDepositAndTransfer TxType = "CreateAccountDepositAndTransfer"
50	// TxTypeDepositAndTransfer TBD
51	TxTypeDepositAndTransfer TxType = "TxTypeDepositAndTransfer"
52	// TxTypeForceTransfer TBD
53	TxTypeForceTransfer TxType = "TxTypeForceTransfer"
54	// TxTypeForceExit TBD
55	TxTypeForceExit TxType = "TxTypeForceExit"
56	// TxTypeTransferToEthAddr TBD
57	TxTypeTransferToEthAddr TxType = "TxTypeTransferToEthAddr"
58	// TxTypeTransferToBJJ TBD
59	TxTypeTransferToBJJ TxType = "TxTypeTransferToBJJ"
60)