-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use cosmos sdk Int type for balances/token amounts (#679)
* refactor: use csdk Int type for balances/token amounts * chore: use ZeroInt func (cherry picked from commit 8e02aef) # Conflicts: # chain/polkadot/query.go # conformance/flush.go # conformance/test.go # examples/cosmos/light_client_test.go # examples/hyperspace/hyperspace_test.go # examples/ibc/interchain_accounts_test.go # examples/ibc/learn_ibc_test.go # examples/ibc/packet_forward_test.go # examples/ibc/wasm/wasm_ibc_test.go # examples/ibc/wasm/wasm_icq_test.go # examples/polkadot/polkadot_chain_test.go # examples/polkadot/push_wasm_client_code_test.go # go.mod # ibc/types.go # interchain_test.go # internal/blockdb/messages_view_test.go # test_user.go
- Loading branch information
1 parent
e768e7b
commit 59a2d31
Showing
28 changed files
with
1,511 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
package polkadot | ||
|
||
import ( | ||
<<<<<<< HEAD | ||
gsrpc "github.com/centrifuge/go-substrate-rpc-client/v4" | ||
gstypes "github.com/centrifuge/go-substrate-rpc-client/v4/types" | ||
======= | ||
"cosmossdk.io/math" | ||
gsrpc "github.com/misko9/go-substrate-rpc-client/v4" | ||
gstypes "github.com/misko9/go-substrate-rpc-client/v4/types" | ||
>>>>>>> 8e02aef (refactor: use cosmos sdk Int type for balances/token amounts (#679)) | ||
) | ||
|
||
// GetBalance fetches the current balance for a specific account address using the SubstrateAPI | ||
func GetBalance(api *gsrpc.SubstrateAPI, address string) (int64, error) { | ||
func GetBalance(api *gsrpc.SubstrateAPI, address string) (math.Int, error) { | ||
meta, err := api.RPC.State.GetMetadataLatest() | ||
if err != nil { | ||
return -1, err | ||
return math.Int{}, err | ||
} | ||
pubKey, err := DecodeAddressSS58(address) | ||
if err != nil { | ||
return -2, err | ||
return math.Int{}, err | ||
} | ||
key, err := gstypes.CreateStorageKey(meta, "System", "Account", pubKey, nil) | ||
if err != nil { | ||
return -3, err | ||
return math.Int{}, err | ||
} | ||
|
||
var accountInfo AccountInfo | ||
ok, err := api.RPC.State.GetStorageLatest(key, &accountInfo) | ||
if err != nil { | ||
return -4, err | ||
return math.Int{}, err | ||
} | ||
if !ok { | ||
return -5, nil | ||
return math.Int{}, nil | ||
} | ||
|
||
return accountInfo.Data.Free.Int64(), nil | ||
return math.NewIntFromBigInt(accountInfo.Data.Free.Int), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.