diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index ee728310a..159a5153f 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -551,9 +551,9 @@ func (bc *Blockchain) processHeader(h *block.Header, batch storage.Batch, header return nil } -// bc.GetHeaderHash(int(endHeight)) returns sum of all system fees for blocks up to h. +// GetSystemFeeAmount returns sum of all system fees for blocks up to h. // and 0 if no such block exists. -func (bc *Blockchain) getSystemFeeAmount(h util.Uint256) uint32 { +func (bc *Blockchain) GetSystemFeeAmount(h util.Uint256) uint32 { _, sf, _ := bc.dao.GetBlock(h) return sf } @@ -582,7 +582,7 @@ func (bc *Blockchain) GetStateRoot(height uint32) (*state.MPTRootState, error) { func (bc *Blockchain) storeBlock(block *block.Block) error { cache := dao.NewCached(bc.dao) appExecResults := make([]*state.AppExecResult, 0, len(block.Transactions)) - fee := bc.getSystemFeeAmount(block.PrevHash) + fee := bc.GetSystemFeeAmount(block.PrevHash) for _, tx := range block.Transactions { fee += uint32(bc.SystemFee(tx).IntegralValue()) } @@ -1503,9 +1503,9 @@ func (bc *Blockchain) CalculateClaimable(value util.Fixed8, startHeight, endHeig startHeight++ } h := bc.GetHeaderHash(int(startHeight - 1)) - feeStart := bc.getSystemFeeAmount(h) + feeStart := bc.GetSystemFeeAmount(h) h = bc.GetHeaderHash(int(endHeight - 1)) - feeEnd := bc.getSystemFeeAmount(h) + feeEnd := bc.GetSystemFeeAmount(h) sysFeeTotal := util.Fixed8(feeEnd - feeStart) ratio := value / 100000000 diff --git a/pkg/core/blockchainer.go b/pkg/core/blockchainer.go index 76c032c61..5d72d8543 100644 --- a/pkg/core/blockchainer.go +++ b/pkg/core/blockchainer.go @@ -44,6 +44,7 @@ type Blockchainer interface { GetStateRoot(height uint32) (*state.MPTRootState, error) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error) + GetSystemFeeAmount(h util.Uint256) uint32 GetTestVM(tx *transaction.Transaction) *vm.VM GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) GetUnspentCoinState(util.Uint256) *state.UnspentCoin diff --git a/pkg/network/helper_test.go b/pkg/network/helper_test.go index 5f078fddc..8922733aa 100644 --- a/pkg/network/helper_test.go +++ b/pkg/network/helper_test.go @@ -123,6 +123,9 @@ func (chain testChain) GetStateRoot(height uint32) (*state.MPTRootState, error) func (chain testChain) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem { panic("TODO") } +func (chain testChain) GetSystemFeeAmount(h util.Uint256) uint32 { + panic("TODO") +} func (chain testChain) GetTestVM(tx *transaction.Transaction) *vm.VM { panic("TODO") } diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 98739d4b7..623a49e4d 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -1356,17 +1356,8 @@ func (s *Server) getBlockSysFee(reqParams request.Params) (interface{}, *respons } headerHash := s.chain.GetHeaderHash(num) - block, errBlock := s.chain.GetBlock(headerHash) - if errBlock != nil { - return 0, response.NewRPCError(errBlock.Error(), "", nil) - } - var blockSysFee util.Fixed8 - for _, tx := range block.Transactions { - blockSysFee += s.chain.SystemFee(tx) - } - - return blockSysFee, nil + return util.Fixed8FromInt64(int64(s.chain.GetSystemFeeAmount(headerHash))), nil } // getBlockHeader returns the corresponding block header information according to the specified script hash. diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 4b544610c..35b5407d9 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -548,13 +548,9 @@ var rpcTestCases = map[string][]rpcTestCase{ name: "positive", params: "[1]", result: func(e *executor) interface{} { - block, _ := e.chain.GetBlock(e.chain.GetHeaderHash(1)) - - var expectedBlockSysFee util.Fixed8 - for _, tx := range block.Transactions { - expectedBlockSysFee += e.chain.SystemFee(tx) - } - return &expectedBlockSysFee + sf := e.chain.GetSystemFeeAmount(e.chain.GetHeaderHash(1)) + r := util.Fixed8FromInt64(int64(sf)) + return &r }, }, {