mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Til use bigint for amount & loadamount values
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -61,8 +62,8 @@ type instruction struct {
|
|||||||
literal string
|
literal string
|
||||||
from string
|
from string
|
||||||
to string
|
to string
|
||||||
amount uint64
|
amount *big.Int
|
||||||
loadAmount uint64
|
loadAmount *big.Int
|
||||||
fee uint8
|
fee uint8
|
||||||
tokenID common.TokenID
|
tokenID common.TokenID
|
||||||
typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
|
typ common.TxType // D: Deposit, T: Transfer, E: ForceExit
|
||||||
@@ -433,30 +434,30 @@ func (p *parser) parseLine(setType setType) (*instruction, error) {
|
|||||||
// deposit case
|
// deposit case
|
||||||
_, lit = p.scanIgnoreWhitespace()
|
_, lit = p.scanIgnoreWhitespace()
|
||||||
c.literal += lit
|
c.literal += lit
|
||||||
loadAmount, err := strconv.Atoi(lit)
|
loadAmount, ok := new(big.Int).SetString(lit, 10)
|
||||||
if err != nil {
|
if !ok {
|
||||||
line, _ := p.s.r.ReadString('\n')
|
line, _ := p.s.r.ReadString('\n')
|
||||||
c.literal += line
|
c.literal += line
|
||||||
return c, err
|
return c, fmt.Errorf("Can not parse number for LoadAmount")
|
||||||
}
|
}
|
||||||
c.loadAmount = uint64(loadAmount)
|
c.loadAmount = loadAmount
|
||||||
if err := p.expectChar(c, ","); err != nil {
|
if err := p.expectChar(c, ","); err != nil {
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, lit = p.scanIgnoreWhitespace()
|
_, lit = p.scanIgnoreWhitespace()
|
||||||
c.literal += lit
|
c.literal += lit
|
||||||
amount, err := strconv.Atoi(lit)
|
amount, ok := new(big.Int).SetString(lit, 10)
|
||||||
if err != nil {
|
if !ok {
|
||||||
line, _ := p.s.r.ReadString('\n')
|
line, _ := p.s.r.ReadString('\n')
|
||||||
c.literal += line
|
c.literal += line
|
||||||
return c, err
|
return c, fmt.Errorf("Can not parse number for Amount: %s", lit)
|
||||||
}
|
}
|
||||||
if c.typ == common.TxTypeDeposit ||
|
if c.typ == common.TxTypeDeposit ||
|
||||||
c.typ == common.TxTypeCreateAccountDeposit {
|
c.typ == common.TxTypeCreateAccountDeposit {
|
||||||
c.loadAmount = uint64(amount)
|
c.loadAmount = amount
|
||||||
} else {
|
} else {
|
||||||
c.amount = uint64(amount)
|
c.amount = amount
|
||||||
}
|
}
|
||||||
if fee {
|
if fee {
|
||||||
if err := p.expectChar(c, "("); err != nil {
|
if err := p.expectChar(c, "("); err != nil {
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ func TestParseErrors(t *testing.T) {
|
|||||||
`
|
`
|
||||||
parser := newParser(strings.NewReader(s))
|
parser := newParser(strings.NewReader(s))
|
||||||
_, err := parser.parse()
|
_, err := parser.parse()
|
||||||
assert.Equal(t, "Line 2: Deposit(1)A:: 10\n, err: strconv.Atoi: parsing \":\": invalid syntax", err.Error())
|
assert.Equal(t, "Line 2: Deposit(1)A:: 10\n, err: Can not parse number for Amount: :", err.Error())
|
||||||
|
|
||||||
s = `
|
s = `
|
||||||
Type: Blockchain
|
Type: Blockchain
|
||||||
|
|||||||
@@ -195,11 +195,11 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) {
|
|||||||
FromBJJ: tc.Users[inst.from].BJJ.Public(),
|
FromBJJ: tc.Users[inst.from].BJJ.Public(),
|
||||||
TokenID: inst.tokenID,
|
TokenID: inst.tokenID,
|
||||||
Amount: big.NewInt(0),
|
Amount: big.NewInt(0),
|
||||||
LoadAmount: big.NewInt(int64(inst.loadAmount)),
|
LoadAmount: inst.loadAmount,
|
||||||
Type: inst.typ,
|
Type: inst.typ,
|
||||||
}
|
}
|
||||||
if inst.typ == common.TxTypeCreateAccountDepositTransfer {
|
if inst.typ == common.TxTypeCreateAccountDepositTransfer {
|
||||||
tx.Amount = big.NewInt(int64(inst.amount))
|
tx.Amount = inst.amount
|
||||||
}
|
}
|
||||||
testTx := L1Tx{
|
testTx := L1Tx{
|
||||||
lineNum: inst.lineNum,
|
lineNum: inst.lineNum,
|
||||||
@@ -222,11 +222,11 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) {
|
|||||||
tx := common.L1Tx{
|
tx := common.L1Tx{
|
||||||
TokenID: inst.tokenID,
|
TokenID: inst.tokenID,
|
||||||
Amount: big.NewInt(0),
|
Amount: big.NewInt(0),
|
||||||
LoadAmount: big.NewInt(int64(inst.loadAmount)),
|
LoadAmount: inst.loadAmount,
|
||||||
Type: inst.typ,
|
Type: inst.typ,
|
||||||
}
|
}
|
||||||
if inst.typ == common.TxTypeDepositTransfer {
|
if inst.typ == common.TxTypeDepositTransfer {
|
||||||
tx.Amount = big.NewInt(int64(inst.amount))
|
tx.Amount = inst.amount
|
||||||
}
|
}
|
||||||
testTx := L1Tx{
|
testTx := L1Tx{
|
||||||
lineNum: inst.lineNum,
|
lineNum: inst.lineNum,
|
||||||
@@ -243,7 +243,7 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) {
|
|||||||
return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())
|
return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())
|
||||||
}
|
}
|
||||||
tx := common.L2Tx{
|
tx := common.L2Tx{
|
||||||
Amount: big.NewInt(int64(inst.amount)),
|
Amount: inst.amount,
|
||||||
Fee: common.FeeSelector(inst.fee),
|
Fee: common.FeeSelector(inst.fee),
|
||||||
Type: common.TxTypeTransfer,
|
Type: common.TxTypeTransfer,
|
||||||
EthBlockNum: tc.blockNum,
|
EthBlockNum: tc.blockNum,
|
||||||
@@ -264,7 +264,7 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) {
|
|||||||
}
|
}
|
||||||
tx := common.L1Tx{
|
tx := common.L1Tx{
|
||||||
TokenID: inst.tokenID,
|
TokenID: inst.tokenID,
|
||||||
Amount: big.NewInt(int64(inst.amount)),
|
Amount: inst.amount,
|
||||||
LoadAmount: big.NewInt(0),
|
LoadAmount: big.NewInt(0),
|
||||||
Type: common.TxTypeForceTransfer,
|
Type: common.TxTypeForceTransfer,
|
||||||
}
|
}
|
||||||
@@ -285,7 +285,7 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) {
|
|||||||
tx := common.L2Tx{
|
tx := common.L2Tx{
|
||||||
ToIdx: common.Idx(1), // as is an Exit
|
ToIdx: common.Idx(1), // as is an Exit
|
||||||
Fee: common.FeeSelector(inst.fee),
|
Fee: common.FeeSelector(inst.fee),
|
||||||
Amount: big.NewInt(int64(inst.amount)),
|
Amount: inst.amount,
|
||||||
Type: common.TxTypeExit,
|
Type: common.TxTypeExit,
|
||||||
EthBlockNum: tc.blockNum,
|
EthBlockNum: tc.blockNum,
|
||||||
}
|
}
|
||||||
@@ -306,7 +306,7 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) {
|
|||||||
tx := common.L1Tx{
|
tx := common.L1Tx{
|
||||||
ToIdx: common.Idx(1), // as is an Exit
|
ToIdx: common.Idx(1), // as is an Exit
|
||||||
TokenID: inst.tokenID,
|
TokenID: inst.tokenID,
|
||||||
Amount: big.NewInt(int64(inst.amount)),
|
Amount: inst.amount,
|
||||||
LoadAmount: big.NewInt(0),
|
LoadAmount: big.NewInt(0),
|
||||||
Type: common.TxTypeForceExit,
|
Type: common.TxTypeForceExit,
|
||||||
}
|
}
|
||||||
@@ -547,7 +547,7 @@ func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) {
|
|||||||
tx := common.PoolL2Tx{
|
tx := common.PoolL2Tx{
|
||||||
FromIdx: tc.Users[inst.from].Accounts[inst.tokenID].Idx,
|
FromIdx: tc.Users[inst.from].Accounts[inst.tokenID].Idx,
|
||||||
TokenID: inst.tokenID,
|
TokenID: inst.tokenID,
|
||||||
Amount: big.NewInt(int64(inst.amount)),
|
Amount: inst.amount,
|
||||||
Fee: common.FeeSelector(inst.fee),
|
Fee: common.FeeSelector(inst.fee),
|
||||||
Nonce: tc.Users[inst.from].Accounts[inst.tokenID].Nonce,
|
Nonce: tc.Users[inst.from].Accounts[inst.tokenID].Nonce,
|
||||||
State: common.PoolL2TxStatePending,
|
State: common.PoolL2TxStatePending,
|
||||||
@@ -589,7 +589,7 @@ func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) {
|
|||||||
ToIdx: common.Idx(1), // as is an Exit
|
ToIdx: common.Idx(1), // as is an Exit
|
||||||
Fee: common.FeeSelector(inst.fee),
|
Fee: common.FeeSelector(inst.fee),
|
||||||
TokenID: inst.tokenID,
|
TokenID: inst.tokenID,
|
||||||
Amount: big.NewInt(int64(inst.amount)),
|
Amount: inst.amount,
|
||||||
Nonce: tc.Users[inst.from].Accounts[inst.tokenID].Nonce,
|
Nonce: tc.Users[inst.from].Accounts[inst.tokenID].Nonce,
|
||||||
State: common.PoolL2TxStatePending,
|
State: common.PoolL2TxStatePending,
|
||||||
Type: common.TxTypeExit,
|
Type: common.TxTypeExit,
|
||||||
|
|||||||
Reference in New Issue
Block a user