From 0aaaf7f7879dd20100d081ed48318a0c6ffb024f Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 29 Jun 2020 16:09:23 +0300 Subject: [PATCH] *: switch from fixed8 to int64 in (Blockchain).CalculateClaimable --- pkg/core/blockchain.go | 10 +++++----- pkg/core/blockchainer/blockchainer.go | 2 +- pkg/core/native/native_neo.go | 4 ++-- pkg/network/helper_test.go | 2 +- pkg/rpc/server/server.go | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 96e5f1b73..9a8c6942b 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1062,8 +1062,8 @@ func (bc *Blockchain) UnsubscribeFromExecutions(ch chan<- *state.AppExecResult) // amount of NEO between specified blocks. The amount of NEO being passed is in // its natural non-divisible form (1 NEO as 1, 2 NEO as 2, no multiplication by // 10⁸ is neeeded as for Fixed8). -func (bc *Blockchain) CalculateClaimable(value int64, startHeight, endHeight uint32) util.Fixed8 { - var amount util.Fixed8 +func (bc *Blockchain) CalculateClaimable(value int64, startHeight, endHeight uint32) int64 { + var amount int64 di := uint32(bc.decrementInterval) ustart := startHeight / di @@ -1080,15 +1080,15 @@ func (bc *Blockchain) CalculateClaimable(value int64, startHeight, endHeight uin istart := startHeight % di for ustart < uend { - amount += util.Fixed8(di-istart) * util.Fixed8(bc.generationAmount[ustart]) + amount += int64(di-istart) * int64(bc.generationAmount[ustart]) ustart++ istart = 0 } - amount += util.Fixed8(iend-istart) * util.Fixed8(bc.generationAmount[ustart]) + amount += int64(iend-istart) * int64(bc.generationAmount[ustart]) } - return amount * util.Fixed8(value) + return amount * value } // FeePerByte returns transaction network fee per byte. diff --git a/pkg/core/blockchainer/blockchainer.go b/pkg/core/blockchainer/blockchainer.go index 6c5fcad2f..dae93659d 100644 --- a/pkg/core/blockchainer/blockchainer.go +++ b/pkg/core/blockchainer/blockchainer.go @@ -19,7 +19,7 @@ type Blockchainer interface { AddHeaders(...*block.Header) error AddBlock(*block.Block) error BlockHeight() uint32 - CalculateClaimable(value int64, startHeight, endHeight uint32) util.Fixed8 + CalculateClaimable(value int64, startHeight, endHeight uint32) int64 Close() HeaderHeight() uint32 GetBlock(hash util.Uint256) (*block.Block, error) diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index 73388bbdd..0d3addd68 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -199,7 +199,7 @@ func (n *NEO) distributeGas(ic *interop.Context, h util.Uint160, acc *state.NEOB } gen := ic.Chain.CalculateClaimable(acc.Balance.Int64(), acc.BalanceHeight, ic.Block.Index) acc.BalanceHeight = ic.Block.Index - n.GAS.mint(ic, h, big.NewInt(int64(gen))) + n.GAS.mint(ic, h, big.NewInt(gen)) return nil } @@ -213,7 +213,7 @@ func (n *NEO) unclaimedGas(ic *interop.Context, args []stackitem.Item) stackitem tr := bs.Trackers[n.Hash] gen := ic.Chain.CalculateClaimable(tr.Balance, tr.LastUpdatedBlock, end) - return stackitem.NewBigInteger(big.NewInt(int64(gen))) + return stackitem.NewBigInteger(big.NewInt(gen)) } func (n *NEO) registerValidator(ic *interop.Context, args []stackitem.Item) stackitem.Item { diff --git a/pkg/network/helper_test.go b/pkg/network/helper_test.go index e63664b51..f6f66dcdb 100644 --- a/pkg/network/helper_test.go +++ b/pkg/network/helper_test.go @@ -31,7 +31,7 @@ func (chain testChain) ApplyPolicyToTxSet([]*transaction.Transaction) []*transac func (chain testChain) GetConfig() config.ProtocolConfiguration { panic("TODO") } -func (chain testChain) CalculateClaimable(int64, uint32, uint32) util.Fixed8 { +func (chain testChain) CalculateClaimable(int64, uint32, uint32) int64 { panic("TODO") } diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 8cb69d7b7..03399574c 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -787,7 +787,7 @@ func (s *Server) getUnclaimedGas(ps request.Params) (interface{}, *response.Erro return "0", nil } gas := s.chain.CalculateClaimable(neo, neoHeight, s.chain.BlockHeight()+1) // +1 as in C#, for the next block. - return strconv.FormatInt(int64(gas), 10), nil // It's not represented as Fixed8 in C#. + return strconv.FormatInt(gas, 10), nil } // getValidators returns the current NEO consensus nodes information and voting status.