mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-05 03:58:23 +00:00
rpc: fix getblocksystemfee call
It should return cumulative fee and it should be wrapped into a string.
This commit is contained in:
parent
fda8b784c8
commit
a46c93f6bb
5 changed files with 13 additions and 22 deletions
|
@ -551,9 +551,9 @@ func (bc *Blockchain) processHeader(h *block.Header, batch storage.Batch, header
|
||||||
return nil
|
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.
|
// 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)
|
_, sf, _ := bc.dao.GetBlock(h)
|
||||||
return sf
|
return sf
|
||||||
}
|
}
|
||||||
|
@ -582,7 +582,7 @@ func (bc *Blockchain) GetStateRoot(height uint32) (*state.MPTRootState, error) {
|
||||||
func (bc *Blockchain) storeBlock(block *block.Block) error {
|
func (bc *Blockchain) storeBlock(block *block.Block) error {
|
||||||
cache := dao.NewCached(bc.dao)
|
cache := dao.NewCached(bc.dao)
|
||||||
appExecResults := make([]*state.AppExecResult, 0, len(block.Transactions))
|
appExecResults := make([]*state.AppExecResult, 0, len(block.Transactions))
|
||||||
fee := bc.getSystemFeeAmount(block.PrevHash)
|
fee := bc.GetSystemFeeAmount(block.PrevHash)
|
||||||
for _, tx := range block.Transactions {
|
for _, tx := range block.Transactions {
|
||||||
fee += uint32(bc.SystemFee(tx).IntegralValue())
|
fee += uint32(bc.SystemFee(tx).IntegralValue())
|
||||||
}
|
}
|
||||||
|
@ -1503,9 +1503,9 @@ func (bc *Blockchain) CalculateClaimable(value util.Fixed8, startHeight, endHeig
|
||||||
startHeight++
|
startHeight++
|
||||||
}
|
}
|
||||||
h := bc.GetHeaderHash(int(startHeight - 1))
|
h := bc.GetHeaderHash(int(startHeight - 1))
|
||||||
feeStart := bc.getSystemFeeAmount(h)
|
feeStart := bc.GetSystemFeeAmount(h)
|
||||||
h = bc.GetHeaderHash(int(endHeight - 1))
|
h = bc.GetHeaderHash(int(endHeight - 1))
|
||||||
feeEnd := bc.getSystemFeeAmount(h)
|
feeEnd := bc.GetSystemFeeAmount(h)
|
||||||
|
|
||||||
sysFeeTotal := util.Fixed8(feeEnd - feeStart)
|
sysFeeTotal := util.Fixed8(feeEnd - feeStart)
|
||||||
ratio := value / 100000000
|
ratio := value / 100000000
|
||||||
|
|
|
@ -44,6 +44,7 @@ type Blockchainer interface {
|
||||||
GetStateRoot(height uint32) (*state.MPTRootState, error)
|
GetStateRoot(height uint32) (*state.MPTRootState, error)
|
||||||
GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem
|
GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem
|
||||||
GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error)
|
GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error)
|
||||||
|
GetSystemFeeAmount(h util.Uint256) uint32
|
||||||
GetTestVM(tx *transaction.Transaction) *vm.VM
|
GetTestVM(tx *transaction.Transaction) *vm.VM
|
||||||
GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error)
|
GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error)
|
||||||
GetUnspentCoinState(util.Uint256) *state.UnspentCoin
|
GetUnspentCoinState(util.Uint256) *state.UnspentCoin
|
||||||
|
|
|
@ -123,6 +123,9 @@ func (chain testChain) GetStateRoot(height uint32) (*state.MPTRootState, error)
|
||||||
func (chain testChain) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem {
|
func (chain testChain) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
func (chain testChain) GetSystemFeeAmount(h util.Uint256) uint32 {
|
||||||
|
panic("TODO")
|
||||||
|
}
|
||||||
func (chain testChain) GetTestVM(tx *transaction.Transaction) *vm.VM {
|
func (chain testChain) GetTestVM(tx *transaction.Transaction) *vm.VM {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1356,17 +1356,8 @@ func (s *Server) getBlockSysFee(reqParams request.Params) (interface{}, *respons
|
||||||
}
|
}
|
||||||
|
|
||||||
headerHash := s.chain.GetHeaderHash(num)
|
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
|
return util.Fixed8FromInt64(int64(s.chain.GetSystemFeeAmount(headerHash))), nil
|
||||||
for _, tx := range block.Transactions {
|
|
||||||
blockSysFee += s.chain.SystemFee(tx)
|
|
||||||
}
|
|
||||||
|
|
||||||
return blockSysFee, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getBlockHeader returns the corresponding block header information according to the specified script hash.
|
// getBlockHeader returns the corresponding block header information according to the specified script hash.
|
||||||
|
|
|
@ -548,13 +548,9 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
params: "[1]",
|
params: "[1]",
|
||||||
result: func(e *executor) interface{} {
|
result: func(e *executor) interface{} {
|
||||||
block, _ := e.chain.GetBlock(e.chain.GetHeaderHash(1))
|
sf := e.chain.GetSystemFeeAmount(e.chain.GetHeaderHash(1))
|
||||||
|
r := util.Fixed8FromInt64(int64(sf))
|
||||||
var expectedBlockSysFee util.Fixed8
|
return &r
|
||||||
for _, tx := range block.Transactions {
|
|
||||||
expectedBlockSysFee += e.chain.SystemFee(tx)
|
|
||||||
}
|
|
||||||
return &expectedBlockSysFee
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue