add use.getOTABalance and use.getSupportUseCoinOTABalances

This commit is contained in:
fnaticwang 2019-09-26 10:55:11 +08:00
parent a8cd67ecd0
commit 460af1135a
4 changed files with 89 additions and 1 deletions

View file

@ -1172,3 +1172,31 @@ func FetchRingSignInfo(stateDB StateDB, hashInput []byte, ringSignedStr string)
return infoTmp, nil
}
func GetSupportUseCoinOTABalances() []*big.Int {
cval10, _ := new(big.Int).SetString(Usecoin10, 10)
cval20, _ := new(big.Int).SetString(Usecoin20, 10)
cval50, _ := new(big.Int).SetString(Usecoin50, 10)
cval100, _ := new(big.Int).SetString(Usecoin100, 10)
cval200, _ := new(big.Int).SetString(Usecoin200, 10)
cval500, _ := new(big.Int).SetString(Usecoin500, 10)
cval1000, _ := new(big.Int).SetString(Usecoin1000, 10)
cval5000, _ := new(big.Int).SetString(Usecoin5000, 10)
cval50000, _ := new(big.Int).SetString(Usecoin50000, 10)
usecoinBalances := []*big.Int{
cval10,
cval20,
cval50,
cval100,
cval200,
cval500,
cval1000,
cval5000,
cval50000,
}
return usecoinBalances
}

View file

@ -542,6 +542,21 @@ func (s *PrivateAccountAPI) Unpair(ctx context.Context, url string, pin string)
}
}
func (s *PrivateAccountAPI) GetOTABalance(ctx context.Context, blockNr rpc.BlockNumber) (*big.Int, error) {
state, _, err := s.b.StateAndHeaderByNumber(ctx, blockNr)
if state == nil || err != nil {
return nil, err
}
otaB, err := vm.GetUnspendOTATotalBalance(state)
if err != nil {
return common.Big0, err
}
return otaB, state.Error()
}
// PublicBlockChainAPI provides an API to access the Ethereum blockchain.
// It offers only methods that operate on public data that is freely available to anyone.
type PublicBlockChainAPI struct {
@ -1116,6 +1131,35 @@ func (s *PublicBlockChainAPI) rpcMarshalBlock(b *types.Block, inclTx bool, fullT
return fields, err
}
// GetOTABalance returns OTA balance
func (s *PublicBlockChainAPI) GetOTABalance(ctx context.Context, otaUAddr string, blockNr rpc.BlockNumber) (*big.Int, error) {
if !hexutil.Has0xPrefix(otaUAddr) {
return nil, ErrInvalidOTAAddr
}
state, _, err := s.b.StateAndHeaderByNumber(ctx, blockNr)
if state == nil || err != nil {
return nil, err
}
var otaAX []byte
otaUAddrByte := common.FromHex(otaUAddr)
switch len(otaUAddrByte) {
case common.HashLength:
otaAX = otaUAddrByte
case common.UAddressLength:
otaAX, _ = vm.GetAXFromUseAddr(otaUAddrByte)
default:
return nil, ErrInvalidOTAAddr
}
return vm.GetOtaBalanceFromAX(state, otaAX)
}
func (s *PublicBlockChainAPI) GetSupportUseCoinOTABalances(ctx context.Context) []*big.Int {
return vm.GetSupportUseCoinOTABalances()
}
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
type RPCTransaction struct {
BlockHash *common.Hash `json:"blockHash"`

File diff suppressed because one or more lines are too long

View file

@ -13675,12 +13675,28 @@ module.exports = XMLHttpRequest;
inputFormatter: [null, null, null]
});
var getOTABalance = new Method({
name: 'getOTABalance',
call: 'use_getOTABalance',
params: 2,
inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter],
outputFormatter: formatters.outputBigNumberFormatter
});
var getSupportUseCoinOTABalances = new Method ({
name: 'getSupportUseCoinOTABalances',
call: 'use_getSupportUseCoinOTABalances',
params: 0,
});
return [
getUseAddress,
generateOneTimeAddress,
computeOTAPPKeys,
getOTAMixSet,
genRingSignData,
getOTABalance,
getSupportUseCoinOTABalances,
];
};
var properties = function () {