diff options
author | Bojie Wu <bojie@dexon.org> | 2018-10-31 12:16:50 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:52 +0800 |
commit | ccc622d2078f34d5c805719e14897c4c9e84e3ca (patch) | |
tree | e76663be57d3f4690741b35b948345abd6d0304e /dex | |
parent | 3d5d607ecde57c6fb0ad550d1c97d8ae80039c56 (diff) | |
download | dexon-ccc622d2078f34d5c805719e14897c4c9e84e3ca.tar dexon-ccc622d2078f34d5c805719e14897c4c9e84e3ca.tar.gz dexon-ccc622d2078f34d5c805719e14897c4c9e84e3ca.tar.bz2 dexon-ccc622d2078f34d5c805719e14897c4c9e84e3ca.tar.lz dexon-ccc622d2078f34d5c805719e14897c4c9e84e3ca.tar.xz dexon-ccc622d2078f34d5c805719e14897c4c9e84e3ca.tar.zst dexon-ccc622d2078f34d5c805719e14897c4c9e84e3ca.zip |
app: refactor prepare logic
Diffstat (limited to 'dex')
-rw-r--r-- | dex/app.go | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/dex/app.go b/dex/app.go index 6c6d8da53..a226aaa0c 100644 --- a/dex/app.go +++ b/dex/app.go @@ -156,6 +156,12 @@ addressMap: continue } + balance := latestState.GetBalance(address) + cost, exist := d.blockchain.GetCostInConfirmedBlocks(address) + if exist { + balance = new(big.Int).Sub(balance, cost) + } + var expectNonce uint64 // get last nonce from confirmed blocks lastConfirmedNonce, exist := d.blockchain.GetLastNonceInConfirmedBlocks(address) @@ -166,18 +172,18 @@ addressMap: expectNonce = lastConfirmedNonce + 1 } - if expectNonce != txs[0].Nonce() { - log.Debug("Nonce check error", "expect", expectNonce, "nonce", txs[0].Nonce()) - continue - } - - balance := latestState.GetBalance(address) - cost, exist := d.blockchain.GetCostInConfirmedBlocks(address) - if exist { - balance = new(big.Int).Sub(balance, cost) - } - for _, tx := range txs { + if expectNonce == tx.Nonce() { + expectNonce++ + } else if expectNonce < tx.Nonce() { + // break to do next address + break + } else if expectNonce > tx.Nonce() { + // continue to find next available + log.Debug("Nonce check error and continue next tx", "expect", expectNonce, "nonce", tx.Nonce()) + continue + } + maxGasUsed := new(big.Int).Mul(new(big.Int).SetUint64(tx.Gas()), tx.GasPrice()) intrinsicGas, err := core.IntrinsicGas(tx.Data(), tx.To() == nil, true) if err != nil { |