mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Import & adapt iden/go-iden3-core/eth/client
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/iden3/go-iden3-crypto/poseidon"
|
||||
cryptoUtils "github.com/iden3/go-iden3-crypto/utils"
|
||||
@@ -20,7 +20,7 @@ type Account struct {
|
||||
Nonce uint64 // max of 40 bits used
|
||||
Balance *big.Int // max of 192 bits used
|
||||
PublicKey *babyjub.PublicKey
|
||||
EthAddr eth.Address
|
||||
EthAddr ethCommon.Address
|
||||
}
|
||||
|
||||
func (a *Account) String() string {
|
||||
@@ -121,7 +121,7 @@ func AccountFromBytes(b [32 * NLEAFELEMS]byte) (*Account, error) {
|
||||
return nil, err
|
||||
}
|
||||
publicKey := babyjub.PublicKey(*pkPoint)
|
||||
ethAddr := eth.BytesToAddress(b[96:116])
|
||||
ethAddr := ethCommon.BytesToAddress(b[96:116])
|
||||
|
||||
if !cryptoUtils.CheckBigIntInField(balance) {
|
||||
return nil, ErrNotInFF
|
||||
|
||||
@@ -3,14 +3,14 @@ package common
|
||||
import (
|
||||
"time"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
)
|
||||
|
||||
// AccountCreationAuth authorizations sent by users to the L2DB, to be used for account creations when necessary
|
||||
type AccountCreationAuth struct {
|
||||
Timestamp time.Time
|
||||
EthAddr eth.Address
|
||||
EthAddr ethCommon.Address
|
||||
BJJ babyjub.PublicKey
|
||||
Signature babyjub.Signature
|
||||
}
|
||||
|
||||
@@ -3,25 +3,25 @@ package common
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// Batch is a struct that represents Hermez network batch
|
||||
type Batch struct {
|
||||
BatchNum BatchNum
|
||||
SlotNum SlotNum // Slot in which the batch is forged
|
||||
EthTxHash eth.Hash
|
||||
EthTxHash ethCommon.Hash
|
||||
EthBlockNum uint64 // Ethereum block in which the batch is forged
|
||||
ExitRoot Hash
|
||||
OldStateRoot Hash
|
||||
NewStateRoot Hash
|
||||
OldNumAccounts int
|
||||
NewNumAccounts int
|
||||
ToForgeL1TxsNum uint32 // optional, Only when the batch forges L1 txs. Identifier that corresponds to the group of L1 txs forged in the current batch.
|
||||
ToForgeL1TxsHash eth.Hash // optional, Only when the batch forges L1 txs. Frozen from pendingL1TxsHash (which are the group of L1UserTxs), to be forged in ToForgeL1TxsNum + 1.
|
||||
ForgedL1TxsHash eth.Hash // optional, Only when the batch forges L1 txs. This will be the Hash of the group of L1 txs (L1UserTxs + L1CoordinatorTx) forged in the current batch.
|
||||
ToForgeL1TxsNum uint32 // optional, Only when the batch forges L1 txs. Identifier that corresponds to the group of L1 txs forged in the current batch.
|
||||
ToForgeL1TxsHash ethCommon.Hash // optional, Only when the batch forges L1 txs. Frozen from pendingL1TxsHash (which are the group of L1UserTxs), to be forged in ToForgeL1TxsNum + 1.
|
||||
ForgedL1TxsHash ethCommon.Hash // optional, Only when the batch forges L1 txs. This will be the Hash of the group of L1 txs (L1UserTxs + L1CoordinatorTx) forged in the current batch.
|
||||
CollectedFees map[TokenID]*big.Int
|
||||
ForgerAddr eth.Address // TODO: Should this be retrieved via slot reference?
|
||||
ForgerAddr ethCommon.Address // TODO: Should this be retrieved via slot reference?
|
||||
}
|
||||
|
||||
// BatchNum identifies a batch
|
||||
|
||||
@@ -3,13 +3,13 @@ package common
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// Bid is a struct that represents one bid in the PoH
|
||||
type Bid struct {
|
||||
SlotNum SlotNum `meddler:"slot_num"`
|
||||
ForgerAddr eth.Address `meddler:"forger_addr"` // Coordinator reference
|
||||
BidValue *big.Int `meddler:"bid_value,bigint"`
|
||||
EthBlockNum uint64 `meddler:"eth_block_num"`
|
||||
SlotNum SlotNum `meddler:"slot_num"`
|
||||
ForgerAddr ethCommon.Address `meddler:"forger_addr"` // Coordinator reference
|
||||
BidValue *big.Int `meddler:"bid_value,bigint"`
|
||||
EthBlockNum uint64 `meddler:"eth_block_num"`
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package common
|
||||
import (
|
||||
"time"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// Block represents of an Ethereum block
|
||||
type Block struct {
|
||||
EthBlockNum uint64 `meddler:"eth_block_num"`
|
||||
Timestamp time.Time `meddler:"timestamp"`
|
||||
Hash eth.Hash `meddler:"hash"`
|
||||
EthBlockNum uint64 `meddler:"eth_block_num"`
|
||||
Timestamp time.Time `meddler:"timestamp"`
|
||||
Hash ethCommon.Hash `meddler:"hash"`
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
Forger eth.Address // address of the forger
|
||||
Beneficiary eth.Address // address of the beneficiary
|
||||
Withdraw eth.Address // address of the withdraw
|
||||
URL string // URL of the coordinators API
|
||||
Forger ethCommon.Address // address of the forger
|
||||
Beneficiary ethCommon.Address // address of the beneficiary
|
||||
Withdraw ethCommon.Address // address of the withdraw
|
||||
URL string // URL of the coordinators API
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package common
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ type L1Tx struct {
|
||||
Position int `meddler:"position"`
|
||||
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
|
||||
FromIdx Idx `meddler:"from_idx"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
FromEthAddr eth.Address `meddler:"from_eth_addr"`
|
||||
FromEthAddr ethCommon.Address `meddler:"from_eth_addr"`
|
||||
FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
|
||||
ToIdx Idx `meddler:"to_idx"` // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer
|
||||
TokenID TokenID `meddler:"token_id"`
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/hermeznetwork/hermez-node/utils"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/iden3/go-iden3-crypto/poseidon"
|
||||
@@ -40,7 +40,7 @@ type PoolL2Tx struct {
|
||||
TxID TxID `meddler:"tx_id"`
|
||||
FromIdx Idx `meddler:"from_idx"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
ToIdx Idx `meddler:"to_idx"` // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer
|
||||
ToEthAddr eth.Address `meddler:"to_eth_addr"`
|
||||
ToEthAddr ethCommon.Address `meddler:"to_eth_addr"`
|
||||
ToBJJ *babyjub.PublicKey `meddler:"to_bjj"` // TODO: stop using json, use scanner/valuer
|
||||
TokenID TokenID `meddler:"token_id"`
|
||||
Amount *big.Int `meddler:"amount,bigint"` // TODO: change to float16
|
||||
@@ -53,7 +53,7 @@ type PoolL2Tx struct {
|
||||
BatchNum BatchNum `meddler:"batch_num,zeroisnull"` // batchNum in which this tx was forged. Presence indicates "forged" state.
|
||||
RqFromIdx Idx `meddler:"rq_from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
RqToIdx Idx `meddler:"rq_to_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
RqToEthAddr eth.Address `meddler:"rq_to_eth_addr"`
|
||||
RqToEthAddr ethCommon.Address `meddler:"rq_to_eth_addr"`
|
||||
RqToBJJ *babyjub.PublicKey `meddler:"rq_to_bjj"` // TODO: stop using json, use scanner/valuer
|
||||
RqTokenID TokenID `meddler:"rq_token_id,zeroisnull"`
|
||||
RqAmount *big.Int `meddler:"rq_amount,bigintnull"` // TODO: change to float16
|
||||
|
||||
@@ -3,19 +3,19 @@ package common
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// SmartContractParameters describes the constant values of the parameters of the Hermez smart contracts
|
||||
// WARNING: not stable at all
|
||||
type SmartContractParameters struct {
|
||||
SlotDuration uint64 // number of ethereum blocks in a slot
|
||||
Slot0BlockNum uint64 // ethereum block number of the first slot (slot 0)
|
||||
MaxL1UserTxs uint64 // maximum number of L1UserTxs that can be queued for a single batch
|
||||
FreeCoordinatorWait uint64 // if the winning coordinator doesn't forge during this number of blocks, anyone can forge
|
||||
ContractAddr eth.Address // Ethereum address of the rollup smart contract
|
||||
NLevels uint16 // Heigth of the SMT. This will determine the maximum number of accounts that can coexist in the Hermez network by 2^nLevels
|
||||
MaxTxs uint16 // Max amount of txs that can be added in a batch, either L1 or L2
|
||||
FeeL1Tx *big.Int // amount of eth (in wei) that has to be payed to do a L1 tx
|
||||
FeeDeposit *big.Int // amount of eth (in wei) that has to be payed to do a deposit
|
||||
SlotDuration uint64 // number of ethereum blocks in a slot
|
||||
Slot0BlockNum uint64 // ethereum block number of the first slot (slot 0)
|
||||
MaxL1UserTxs uint64 // maximum number of L1UserTxs that can be queued for a single batch
|
||||
FreeCoordinatorWait uint64 // if the winning coordinator doesn't forge during this number of blocks, anyone can forge
|
||||
ContractAddr ethCommon.Address // Ethereum address of the rollup smart contract
|
||||
NLevels uint16 // Heigth of the SMT. This will determine the maximum number of accounts that can coexist in the Hermez network by 2^nLevels
|
||||
MaxTxs uint16 // Max amount of txs that can be added in a batch, either L1 or L2
|
||||
FeeL1Tx *big.Int // amount of eth (in wei) that has to be payed to do a L1 tx
|
||||
FeeDeposit *big.Int // amount of eth (in wei) that has to be payed to do a deposit
|
||||
}
|
||||
|
||||
@@ -4,18 +4,18 @@ import (
|
||||
"encoding/binary"
|
||||
"time"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// Token is a struct that represents an Ethereum token that is supported in Hermez network
|
||||
type Token struct {
|
||||
TokenID TokenID
|
||||
EthAddr eth.Address
|
||||
EthAddr ethCommon.Address
|
||||
Name string
|
||||
Symbol string
|
||||
Decimals uint64
|
||||
EthTxHash eth.Hash // Ethereum TxHash in which this token was registered
|
||||
EthBlockNum uint64 // Ethereum block number in which this token was registered
|
||||
EthTxHash ethCommon.Hash // Ethereum TxHash in which this token was registered
|
||||
EthBlockNum uint64 // Ethereum block number in which this token was registered
|
||||
}
|
||||
|
||||
// TokenInfo provides the price of the token in USD
|
||||
|
||||
Reference in New Issue
Block a user