mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Rename load amount to deposit amount
This commit is contained in:
@@ -716,7 +716,7 @@ var errTODO = fmt.Errorf("TODO: Not implemented yet")
|
||||
// }
|
||||
|
||||
// RollupL1UserTxERC20Permit is the interface to call the smart contract function
|
||||
func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
|
||||
func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
|
||||
log.Error("TODO")
|
||||
return nil, tracerr.Wrap(errTODO)
|
||||
}
|
||||
@@ -725,7 +725,7 @@ func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx i
|
||||
func (c *Client) RollupL1UserTxERC20ETH(
|
||||
fromBJJ *babyjub.PublicKey,
|
||||
fromIdx int64,
|
||||
loadAmount *big.Int,
|
||||
depositAmount *big.Int,
|
||||
amount *big.Int,
|
||||
tokenID uint32,
|
||||
toIdx int64,
|
||||
@@ -739,7 +739,7 @@ func (c *Client) RollupL1UserTxERC20ETH(
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
_, err = common.NewFloat16(loadAmount)
|
||||
_, err = common.NewFloat16(depositAmount)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
@@ -764,7 +764,7 @@ func (c *Client) RollupL1UserTxERC20ETH(
|
||||
FromEthAddr: *c.addr,
|
||||
FromBJJ: fromBJJ,
|
||||
Amount: amount,
|
||||
LoadAmount: loadAmount,
|
||||
DepositAmount: depositAmount,
|
||||
TokenID: common.TokenID(tokenID),
|
||||
ToIdx: common.Idx(toIdx),
|
||||
ToForgeL1TxsNum: &toForgeL1TxsNum,
|
||||
@@ -783,7 +783,7 @@ func (c *Client) RollupL1UserTxERC20ETH(
|
||||
}
|
||||
|
||||
// RollupL1UserTxERC777 is the interface to call the smart contract function
|
||||
// func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||
// func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||
// log.Error("TODO")
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
@@ -156,14 +156,14 @@ func TestClientRollup(t *testing.T) {
|
||||
for i := 0; i < N; i++ {
|
||||
keys[i] = genKeys(int64(i))
|
||||
tx := common.L1Tx{
|
||||
FromIdx: 0,
|
||||
FromEthAddr: keys[i].Addr,
|
||||
FromBJJ: keys[i].BJJPublicKey,
|
||||
TokenID: common.TokenID(0),
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: big.NewInt(10 + int64(i)),
|
||||
FromIdx: 0,
|
||||
FromEthAddr: keys[i].Addr,
|
||||
FromBJJ: keys[i].BJJPublicKey,
|
||||
TokenID: common.TokenID(0),
|
||||
Amount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(10 + int64(i)),
|
||||
}
|
||||
_, err := c.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.LoadAmount,
|
||||
_, err := c.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.DepositAmount,
|
||||
tx.Amount, uint32(tx.TokenID), int64(tx.ToIdx))
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -157,12 +157,12 @@ func GenL1Txs(
|
||||
token := tokens[i%len(tokens)]
|
||||
amount := big.NewInt(int64(i + 1))
|
||||
tx := common.L1Tx{
|
||||
Position: i - fromIdx,
|
||||
UserOrigin: i%2 == 0,
|
||||
TokenID: token.TokenID,
|
||||
Amount: amount,
|
||||
LoadAmount: amount,
|
||||
EthBlockNum: blocks[i%len(blocks)].Num,
|
||||
Position: i - fromIdx,
|
||||
UserOrigin: i%2 == 0,
|
||||
TokenID: token.TokenID,
|
||||
Amount: amount,
|
||||
DepositAmount: amount,
|
||||
EthBlockNum: blocks[i%len(blocks)].Num,
|
||||
}
|
||||
if tx.UserOrigin {
|
||||
n := nextTxsNum
|
||||
|
||||
@@ -63,15 +63,15 @@ const (
|
||||
|
||||
// Instruction is the data structure that represents one line of code
|
||||
type Instruction struct {
|
||||
LineNum int
|
||||
Literal string
|
||||
From string
|
||||
To string
|
||||
Amount *big.Int
|
||||
LoadAmount *big.Int
|
||||
Fee uint8
|
||||
TokenID common.TokenID
|
||||
Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
|
||||
LineNum int
|
||||
Literal string
|
||||
From string
|
||||
To string
|
||||
Amount *big.Int
|
||||
DepositAmount *big.Int
|
||||
Fee uint8
|
||||
TokenID common.TokenID
|
||||
Typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
|
||||
}
|
||||
|
||||
// parsedSet contains the full Set of Instructions representing a full code
|
||||
@@ -94,7 +94,7 @@ func (i Instruction) String() string {
|
||||
if i.Typ == common.TxTypeDeposit ||
|
||||
i.Typ == common.TxTypeDepositTransfer ||
|
||||
i.Typ == common.TxTypeCreateAccountDepositTransfer {
|
||||
fmt.Fprintf(buf, "LoadAmount: %d, ", i.LoadAmount)
|
||||
fmt.Fprintf(buf, "DepositAmount: %d, ", i.DepositAmount)
|
||||
}
|
||||
if i.Typ != common.TxTypeDeposit {
|
||||
fmt.Fprintf(buf, "Amount: %d, ", i.Amount)
|
||||
@@ -123,7 +123,7 @@ func (i Instruction) raw() string {
|
||||
if i.Typ == common.TxTypeDeposit ||
|
||||
i.Typ == common.TxTypeDepositTransfer ||
|
||||
i.Typ == common.TxTypeCreateAccountDepositTransfer {
|
||||
fmt.Fprintf(buf, "%d", i.LoadAmount)
|
||||
fmt.Fprintf(buf, "%d", i.DepositAmount)
|
||||
}
|
||||
if i.Typ != common.TxTypeDeposit {
|
||||
fmt.Fprintf(buf, "%d", i.Amount)
|
||||
@@ -439,13 +439,13 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
|
||||
// deposit case
|
||||
_, lit = p.scanIgnoreWhitespace()
|
||||
c.Literal += lit
|
||||
loadAmount, ok := new(big.Int).SetString(lit, 10)
|
||||
depositAmount, ok := new(big.Int).SetString(lit, 10)
|
||||
if !ok {
|
||||
line, _ := p.s.r.ReadString('\n')
|
||||
c.Literal += line
|
||||
return c, tracerr.Wrap(fmt.Errorf("Can not parse number for LoadAmount"))
|
||||
return c, tracerr.Wrap(fmt.Errorf("Can not parse number for DepositAmount"))
|
||||
}
|
||||
c.LoadAmount = loadAmount
|
||||
c.DepositAmount = depositAmount
|
||||
if err := p.expectChar(c, ","); err != nil {
|
||||
return c, tracerr.Wrap(err)
|
||||
}
|
||||
@@ -460,7 +460,7 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
|
||||
}
|
||||
if c.Typ == common.TxTypeDeposit ||
|
||||
c.Typ == common.TxTypeCreateAccountDeposit {
|
||||
c.LoadAmount = amount
|
||||
c.DepositAmount = amount
|
||||
} else {
|
||||
c.Amount = amount
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestParseBlockchainTxs(t *testing.T) {
|
||||
assert.Equal(t, TxTypeCreateAccountDepositCoordinator, instructions.instructions[7].Typ)
|
||||
assert.Equal(t, TypeNewBatch, instructions.instructions[11].Typ)
|
||||
assert.Equal(t, "Deposit(1)User0:20", instructions.instructions[16].raw())
|
||||
assert.Equal(t, "Type: DepositTransfer, From: A, To: B, LoadAmount: 15, Amount: 10, Fee: 0, TokenID: 1\n", instructions.instructions[13].String())
|
||||
assert.Equal(t, "Type: DepositTransfer, From: A, To: B, DepositAmount: 15, Amount: 10, Fee: 0, TokenID: 1\n", instructions.instructions[13].String())
|
||||
assert.Equal(t, "Type: Transfer, From: User1, To: User0, Amount: 15, Fee: 1, TokenID: 3\n", instructions.instructions[19].String())
|
||||
assert.Equal(t, "Transfer(2)A-B:15(1)", instructions.instructions[15].raw())
|
||||
assert.Equal(t, "Type: Transfer, From: A, To: B, Amount: 15, Fee: 1, TokenID: 2\n", instructions.instructions[15].String())
|
||||
|
||||
@@ -199,12 +199,12 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
|
||||
}
|
||||
tx := common.L1Tx{
|
||||
FromEthAddr: tc.Users[inst.From].Addr,
|
||||
FromBJJ: tc.Users[inst.From].BJJ.Public(),
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: big.NewInt(0),
|
||||
Type: common.TxTypeCreateAccountDeposit, // as TxTypeCreateAccountDepositCoordinator is not valid oustide Til package
|
||||
FromEthAddr: tc.Users[inst.From].Addr,
|
||||
FromBJJ: tc.Users[inst.From].BJJ.Public(),
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
Type: common.TxTypeCreateAccountDeposit, // as TxTypeCreateAccountDepositCoordinator is not valid oustide Til package
|
||||
}
|
||||
testTx := L1Tx{
|
||||
lineNum: inst.LineNum,
|
||||
@@ -219,12 +219,12 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
|
||||
}
|
||||
tx := common.L1Tx{
|
||||
FromEthAddr: tc.Users[inst.From].Addr,
|
||||
FromBJJ: tc.Users[inst.From].BJJ.Public(),
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: inst.LoadAmount,
|
||||
Type: inst.Typ,
|
||||
FromEthAddr: tc.Users[inst.From].Addr,
|
||||
FromBJJ: tc.Users[inst.From].BJJ.Public(),
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
DepositAmount: inst.DepositAmount,
|
||||
Type: inst.Typ,
|
||||
}
|
||||
if inst.Typ == common.TxTypeCreateAccountDepositTransfer {
|
||||
tx.Amount = inst.Amount
|
||||
@@ -248,10 +248,10 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
|
||||
}
|
||||
tx := common.L1Tx{
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: inst.LoadAmount,
|
||||
Type: inst.Typ,
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
DepositAmount: inst.DepositAmount,
|
||||
Type: inst.Typ,
|
||||
}
|
||||
if inst.Typ == common.TxTypeDepositTransfer {
|
||||
tx.Amount = inst.Amount
|
||||
@@ -291,10 +291,10 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
|
||||
}
|
||||
tx := common.L1Tx{
|
||||
TokenID: inst.TokenID,
|
||||
Amount: inst.Amount,
|
||||
LoadAmount: big.NewInt(0),
|
||||
Type: common.TxTypeForceTransfer,
|
||||
TokenID: inst.TokenID,
|
||||
Amount: inst.Amount,
|
||||
DepositAmount: big.NewInt(0),
|
||||
Type: common.TxTypeForceTransfer,
|
||||
}
|
||||
testTx := L1Tx{
|
||||
lineNum: inst.LineNum,
|
||||
@@ -332,11 +332,11 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
|
||||
}
|
||||
tx := common.L1Tx{
|
||||
ToIdx: common.Idx(1), // as is an Exit
|
||||
TokenID: inst.TokenID,
|
||||
Amount: inst.Amount,
|
||||
LoadAmount: big.NewInt(0),
|
||||
Type: common.TxTypeForceExit,
|
||||
ToIdx: common.Idx(1), // as is an Exit
|
||||
TokenID: inst.TokenID,
|
||||
Amount: inst.Amount,
|
||||
DepositAmount: big.NewInt(0),
|
||||
Type: common.TxTypeForceExit,
|
||||
}
|
||||
testTx := L1Tx{
|
||||
lineNum: inst.LineNum,
|
||||
@@ -747,7 +747,7 @@ func (tc *Context) FillBlocksL1UserTxsBatchNum(blocks []common.BlockData) {
|
||||
|
||||
// FillBlocksForgedL1UserTxs fills the L1UserTxs of a batch with the L1UserTxs
|
||||
// that are forged in that batch. It always sets `EffectiveAmount` = `Amount`
|
||||
// and `EffectiveLoadAmount` = `LoadAmount`.
|
||||
// and `EffectiveDepositAmount` = `DepositAmount`.
|
||||
func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
|
||||
for i := range blocks {
|
||||
block := &blocks[i]
|
||||
@@ -761,7 +761,7 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
|
||||
tx := &batch.L1UserTxs[k]
|
||||
*tx = queue[k].L1Tx
|
||||
tx.EffectiveAmount = tx.Amount
|
||||
tx.EffectiveLoadAmount = tx.LoadAmount
|
||||
tx.EffectiveDepositAmount = tx.DepositAmount
|
||||
tx.BatchNum = &batchNum
|
||||
_tx, err := common.NewL1Tx(tx)
|
||||
if err != nil {
|
||||
@@ -786,7 +786,7 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
|
||||
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EthBlockNum
|
||||
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].Position
|
||||
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveAmount
|
||||
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveLoadAmount
|
||||
// - blocks[].Rollup.Batch.L1CoordinatorTxs[].EffectiveDepositAmount
|
||||
// - blocks[].Rollup.Batch.L2Txs[].TxID
|
||||
// - blocks[].Rollup.Batch.L2Txs[].Position
|
||||
// - blocks[].Rollup.Batch.L2Txs[].Nonce
|
||||
@@ -869,7 +869,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra)
|
||||
tx.Position = position
|
||||
position++
|
||||
tx.EffectiveAmount = big.NewInt(0)
|
||||
tx.EffectiveLoadAmount = big.NewInt(0)
|
||||
tx.EffectiveDepositAmount = big.NewInt(0)
|
||||
nTx, err := common.NewL1Tx(tx)
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
|
||||
@@ -141,7 +141,7 @@ func TestGenerateBlocks(t *testing.T) {
|
||||
tc.checkL2TxParams(t, blocks[1].Rollup.Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6))
|
||||
}
|
||||
|
||||
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, loadAmount, amount *big.Int) {
|
||||
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, depositAmount, amount *big.Int) {
|
||||
assert.Equal(t, typ, tx.Type)
|
||||
if tx.FromIdx != common.Idx(0) {
|
||||
assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
|
||||
@@ -151,8 +151,8 @@ func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxTy
|
||||
if tx.ToIdx != common.Idx(0) {
|
||||
assert.Equal(t, tc.Users[to].Accounts[tokenID].Idx, tx.ToIdx)
|
||||
}
|
||||
if loadAmount != nil {
|
||||
assert.Equal(t, loadAmount, tx.LoadAmount)
|
||||
if depositAmount != nil {
|
||||
assert.Equal(t, depositAmount, tx.DepositAmount)
|
||||
}
|
||||
if amount != nil {
|
||||
assert.Equal(t, amount, tx.Amount)
|
||||
@@ -432,14 +432,14 @@ func TestGenerateFromInstructions(t *testing.T) {
|
||||
TokenID: 1,
|
||||
})
|
||||
i++
|
||||
la := big.NewInt(10)
|
||||
da := big.NewInt(10)
|
||||
setInst = append(setInst, Instruction{
|
||||
LineNum: i,
|
||||
// Literal: "CreateAccountDeposit(1) A: 10",
|
||||
Typ: common.TxTypeCreateAccountDeposit,
|
||||
From: "A",
|
||||
TokenID: 1,
|
||||
LoadAmount: la,
|
||||
Typ: common.TxTypeCreateAccountDeposit,
|
||||
From: "A",
|
||||
TokenID: 1,
|
||||
DepositAmount: da,
|
||||
})
|
||||
i++
|
||||
setInst = append(setInst, Instruction{
|
||||
|
||||
Reference in New Issue
Block a user