mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Helper methods for Synchronizer and TX refactor
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
const batchNumBytesLen = 4
|
||||
const batchNumBytesLen = 8
|
||||
|
||||
// Batch is a struct that represents Hermez network batch
|
||||
type Batch struct {
|
||||
@@ -24,20 +24,20 @@ type Batch struct {
|
||||
}
|
||||
|
||||
// BatchNum identifies a batch
|
||||
type BatchNum uint32
|
||||
type BatchNum int64
|
||||
|
||||
// Bytes returns a byte array of length 4 representing the BatchNum
|
||||
func (bn BatchNum) Bytes() []byte {
|
||||
var batchNumBytes [4]byte
|
||||
binary.LittleEndian.PutUint32(batchNumBytes[:], uint32(bn))
|
||||
var batchNumBytes [batchNumBytesLen]byte
|
||||
binary.BigEndian.PutUint64(batchNumBytes[:], uint64(bn))
|
||||
return batchNumBytes[:]
|
||||
}
|
||||
|
||||
// BatchNumFromBytes returns BatchNum from a []byte
|
||||
func BatchNumFromBytes(b []byte) (BatchNum, error) {
|
||||
if len(b) != batchNumBytesLen {
|
||||
return 0, fmt.Errorf("can not parse BatchNumFromBytes, bytes len %d, expected 4", len(b))
|
||||
return 0, fmt.Errorf("can not parse BatchNumFromBytes, bytes len %d, expected %d", len(b), batchNumBytesLen)
|
||||
}
|
||||
batchNum := binary.LittleEndian.Uint32(b[:4])
|
||||
batchNum := binary.BigEndian.Uint64(b[:batchNumBytesLen])
|
||||
return BatchNum(batchNum), nil
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
// Coordinator represents a Hermez network coordinator who wins an auction for an specific slot
|
||||
// WARNING: this is strongly based on the previous implementation, once the new spec is done, this may change a lot.
|
||||
type Coordinator struct {
|
||||
EthBlockNum int64 // block in which the coordinator was registered
|
||||
Forger ethCommon.Address // address of the forger
|
||||
Withdraw ethCommon.Address // address of the withdraw
|
||||
URL string // URL of the coordinators API
|
||||
Forger ethCommon.Address `meddler:"forger_addr"` // address of the forger
|
||||
EthBlockNum int64 `meddler:"eth_block_num"` // block in which the coordinator was registered
|
||||
WithdrawAddr ethCommon.Address `meddler:"withdraw_addr"` // address of the withdraw
|
||||
URL string `meddler:"url"` // URL of the coordinators API
|
||||
}
|
||||
|
||||
@@ -8,8 +8,19 @@ import (
|
||||
|
||||
// ExitInfo represents the ExitTree Leaf data
|
||||
type ExitInfo struct {
|
||||
AccountIdx Idx
|
||||
MerkleProof *merkletree.CircomVerifierProof
|
||||
Balance *big.Int
|
||||
Nullifier *big.Int
|
||||
BatchNum BatchNum `meddler:"batch_num"`
|
||||
AccountIdx Idx `meddler:"account_idx"`
|
||||
MerkleProof *merkletree.CircomVerifierProof `meddler:"merkle_proof,json"`
|
||||
Balance *big.Int `meddler:"balance,bigint"`
|
||||
// InstantWithdrawn is the ethBlockNum in which the exit is withdrawn
|
||||
// instantly. nil means this hasn't happened.
|
||||
InstantWithdrawn *int64 `meddler:"instant_withdrawn"`
|
||||
// DelayedWithdrawRequest is the ethBlockNum in which the exit is
|
||||
// requested to be withdrawn from the delayedWithdrawn smart contract.
|
||||
// nil means this hasn't happened.
|
||||
DelayedWithdrawRequest *int64 `meddler:"delayed_withdraw_request"`
|
||||
// DelayedWithdrawn is the ethBlockNum in which the exit is withdrawn
|
||||
// from the delayedWithdrawn smart contract. nil means this hasn't
|
||||
// happened.
|
||||
DelayedWithdrawn *int64 `meddler:"delayed_withdrawn"`
|
||||
}
|
||||
|
||||
21
common/tx.go
21
common/tx.go
@@ -66,3 +66,24 @@ type Tx struct {
|
||||
FeeUSD float64 `meddler:"fee_usd,zeroisnull"`
|
||||
Nonce Nonce `meddler:"nonce,zeroisnull"`
|
||||
}
|
||||
|
||||
// L1Tx returns a *L1Tx from the Tx
|
||||
func (tx *Tx) L1Tx() *L1Tx {
|
||||
l1Tx := &L1Tx{
|
||||
TxID: tx.TxID,
|
||||
ToForgeL1TxsNum: tx.ToForgeL1TxsNum,
|
||||
Position: tx.Position,
|
||||
UserOrigin: tx.UserOrigin,
|
||||
FromIdx: tx.FromIdx,
|
||||
FromEthAddr: tx.FromEthAddr,
|
||||
FromBJJ: tx.FromBJJ,
|
||||
ToIdx: tx.ToIdx,
|
||||
TokenID: tx.TokenID,
|
||||
Amount: tx.Amount,
|
||||
LoadAmount: tx.LoadAmount,
|
||||
EthBlockNum: tx.EthBlockNum,
|
||||
Type: tx.Type,
|
||||
BatchNum: tx.BatchNum,
|
||||
}
|
||||
return l1Tx
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user