Commit 18d934a3 authored by vicotor's avatar vicotor

update genesis sorted alloc asserts

parent b799c26c
......@@ -9,25 +9,27 @@ import (
// MarshalJSON marshals as JSON.
func (g GenesisAccount) MarshalJSON() ([]byte, error) {
type InnerWalletInfo struct {
Coin string `json:"coin"`
Balance *hexutil.Big `json:"balance"`
}
type GenesisAccount struct {
SignerProxy *hexutil.Bytes `json:"signerProxy,omitempty"`
Assets map[string]InnerWalletInfo `json:"assets"`
SignerProxy *hexutil.Bytes `json:"signerProxy,omitempty"`
Assets []InnerWalletInfo `json:"assets"`
}
var enc GenesisAccount
if len(g.SingerProxy) > 0 {
enc.SignerProxy = (*hexutil.Bytes)(&g.SingerProxy)
}
enc.Assets = make(map[string]InnerWalletInfo, len(g.Assets))
for k, v := range g.Assets {
wallet := InnerWalletInfo{}
enc.Assets = make([]InnerWalletInfo, 0, len(g.Assets))
for _, v := range g.Assets {
wallet := InnerWalletInfo{
Coin: v.Coin,
}
if v.Balance != nil {
balance := hexutil.Big(*v.Balance)
wallet.Balance = &balance
}
enc.Assets[k] = wallet
enc.Assets = append(enc.Assets, wallet)
}
return json.Marshal(&enc)
}
......@@ -35,11 +37,12 @@ func (g GenesisAccount) MarshalJSON() ([]byte, error) {
// UnmarshalJSON unmarshals from JSON.
func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
type InnerWalletInfo struct {
Coin string `json:"coin"`
Balance *hexutil.Big `json:"balance"`
}
type GenesisAccount struct {
SignerProxy *hexutil.Bytes `json:"signerProxy,omitempty"`
Assets map[string]InnerWalletInfo `json:"assets"`
SignerProxy *hexutil.Bytes `json:"signerProxy,omitempty"`
Assets []InnerWalletInfo `json:"assets"`
}
var dec GenesisAccount
if err := json.Unmarshal(input, &dec); err != nil {
......@@ -50,13 +53,15 @@ func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
}
if dec.Assets != nil {
g.Assets = make(map[string]WalletInfo, len(dec.Assets))
for coin, v := range dec.Assets {
wallet := WalletInfo{}
g.Assets = make([]WalletInfo, 0, len(dec.Assets))
for _, v := range dec.Assets {
wallet := WalletInfo{
Coin: v.Coin,
}
if v.Balance != nil {
wallet.Balance = new(big.Int).Set(v.Balance.ToInt())
}
g.Assets[coin] = wallet
g.Assets = append(g.Assets, wallet)
}
}
return nil
......
......@@ -22,10 +22,11 @@ var (
)
type WalletInfo struct {
Coin string `json:"coin"`
Balance *big.Int `json:"balance"`
}
type AssetsInfo map[string]WalletInfo
type AssetsInfo []WalletInfo
type GenesisAccount struct {
SingerProxy []byte `json:"signerProxy"`
......@@ -118,7 +119,7 @@ func (g *GenesisBlock) ToBlock() *nebulav1.Block {
}
blk.Transactions.Txs = append(blk.Transactions.Txs, tx)
}
for asset, wallet := range info.Assets {
for _, wallet := range info.Assets {
if wallet.Balance.Cmp(big.NewInt(0)) > 0 {
tx := &nebulav1.Transaction{
TxType: nebulav1.TxType_DepositTx,
......@@ -129,7 +130,7 @@ func (g *GenesisBlock) ToBlock() *nebulav1.Block {
DepositTx: &nebulav1.DepositTransaction{
SourceHash: common.Hash{}.Bytes(),
User: account.Bytes(),
Coin: []byte(asset),
Coin: []byte(wallet.Coin),
Amount: wallet.Balance.Bytes(),
},
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment