aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2020-09-19 14:33:17 -0400
committerDeterminant <tederminant@gmail.com>2020-09-19 14:33:17 -0400
commiteda06da4c762be9944fdc1dbb3c7786fc4719960 (patch)
tree751095c84c9a878647c96dc5a3c7f752a34c3332
parentbf037f27122dcc96849b4dd3d9f9f76c9bb26292 (diff)
...
-rw-r--r--internal/ethapi/api.go11
-rw-r--r--plugin/evm/import_tx.go3
-rw-r--r--plugin/evm/vm.go2
3 files changed, 12 insertions, 4 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index 9915ad4..9e50f64 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -555,6 +555,17 @@ func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Add
return (*hexutil.Big)(state.GetBalance(address)), state.Error()
}
+// GetBalanceMultiCoin returns the amount of wei for the given address in the state of the
+// given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta
+// block numbers are also allowed.
+func (s *PublicBlockChainAPI) GetBalanceMultiCoin(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash, coinID common.Hash) (*hexutil.Big, error) {
+ state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
+ if state == nil || err != nil {
+ return nil, err
+ }
+ return (*hexutil.Big)(state.GetBalanceMultiCoin(address, coinID)), state.Error()
+}
+
// Result structs for GetProof
type AccountResult struct {
Address common.Address `json:"address"`
diff --git a/plugin/evm/import_tx.go b/plugin/evm/import_tx.go
index 1297f7c..261e68f 100644
--- a/plugin/evm/import_tx.go
+++ b/plugin/evm/import_tx.go
@@ -179,7 +179,6 @@ func (vm *VM) newImportTx(
to common.Address, // Address of recipient
keys []*crypto.PrivateKeySECP256K1R, // Keys to import the funds
) (*Tx, error) {
- log.Info("here0")
if !vm.ctx.XChainID.Equals(chainID) {
return nil, errWrongChainID
}
@@ -225,7 +224,6 @@ func (vm *VM) newImportTx(
importedAVAXAmount := importedAmount[vm.ctx.AVAXAssetID.Key()]
if importedAVAXAmount == 0 {
- log.Info("here1")
return nil, errNoFunds // No imported UTXOs were spendable
}
@@ -233,7 +231,6 @@ func (vm *VM) newImportTx(
// AVAX output
if importedAVAXAmount < vm.txFee { // imported amount goes toward paying tx fee
- log.Info("here2")
// TODO: spend EVM balance to compensate vm.txFee-importedAmount
return nil, errNoFunds
} else if importedAVAXAmount > vm.txFee {
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go
index 2ce72be..52e4acf 100644
--- a/plugin/evm/vm.go
+++ b/plugin/evm/vm.go
@@ -898,7 +898,7 @@ func (vm *VM) GetSpendableCanonical(keys []*crypto.PrivateKeySECP256K1R, assetID
}
addr := GetEthAddress(key)
var balance uint64
- if assetID == vm.ctx.AVAXAssetID {
+ if assetID.Equals(vm.ctx.AVAXAssetID) {
balance = new(big.Int).Div(state.GetBalance(addr), x2cRate).Uint64()
} else {
balance = new(big.Int).Div(state.GetBalanceMultiCoin(addr, assetID.Key()), x2cRate).Uint64()