-
Notifications
You must be signed in to change notification settings - Fork 119
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
- Loading branch information
Showing
28 changed files
with
230 additions
and
196 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,34 @@ | ||
package polkadot | ||
|
||
import ( | ||
"cosmossdk.io/math" | ||
gsrpc "github.com/misko9/go-substrate-rpc-client/v4" | ||
gstypes "github.com/misko9/go-substrate-rpc-client/v4/types" | ||
) | ||
|
||
// 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.