mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 12:05:18 +00:00
495898170c
* draft auth migration from kava-3 to kava-4 * add harvest module accounts to auth state * check account state equality * add supply reconciliation to auth migration * add gov migration * add exact json test (#674) Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com> * fix: check err variable * correct import path * feat: add hard accounts Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com>
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package v38_5
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
// BaseAccount - a base account structure.
|
|
// This can be extended by embedding within in your AppAccount.
|
|
// However one doesn't have to use BaseAccount as long as your struct
|
|
// implements Account.
|
|
type BaseAccount struct {
|
|
Address sdk.AccAddress `json:"address" yaml:"address"`
|
|
Coins sdk.Coins `json:"coins" yaml:"coins"`
|
|
PubKey crypto.PubKey `json:"public_key" yaml:"public_key"`
|
|
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
|
|
Sequence uint64 `json:"sequence" yaml:"sequence"`
|
|
}
|
|
|
|
// NewBaseAccount creates a new BaseAccount object
|
|
func NewBaseAccount(address sdk.AccAddress, coins sdk.Coins,
|
|
pubKey crypto.PubKey, accountNumber uint64, sequence uint64) *BaseAccount {
|
|
|
|
return &BaseAccount{
|
|
Address: address,
|
|
Coins: coins,
|
|
PubKey: pubKey,
|
|
AccountNumber: accountNumber,
|
|
Sequence: sequence,
|
|
}
|
|
}
|
|
|
|
type baseAccountPretty struct {
|
|
Address sdk.AccAddress `json:"address" yaml:"address"`
|
|
Coins sdk.Coins `json:"coins" yaml:"coins"`
|
|
PubKey string `json:"public_key" yaml:"public_key"`
|
|
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
|
|
Sequence uint64 `json:"sequence" yaml:"sequence"`
|
|
}
|
|
|
|
// UnmarshalJSON unmarshals raw JSON bytes into a BaseAccount.
|
|
func (acc *BaseAccount) UnmarshalJSON(bz []byte) error {
|
|
var alias baseAccountPretty
|
|
if err := json.Unmarshal(bz, &alias); err != nil {
|
|
return err
|
|
}
|
|
|
|
if alias.PubKey != "" {
|
|
pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
acc.PubKey = pk
|
|
}
|
|
|
|
acc.Address = alias.Address
|
|
acc.Coins = alias.Coins
|
|
acc.AccountNumber = alias.AccountNumber
|
|
acc.Sequence = alias.Sequence
|
|
|
|
return nil
|
|
}
|