github.com/aergoio/aergo@v1.3.1/cmd/aergocli/util/conv.go (about)

     1  package util
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/aergoio/aergo/consensus"
     6  	"math/big"
     7  
     8  	"github.com/aergoio/aergo/types"
     9  )
    10  
    11  type InOutChainId struct {
    12  	Magic     string
    13  	Public    bool
    14  	Mainnet   bool
    15  	Consensus string
    16  }
    17  
    18  type InOutChainInfo struct {
    19  	Chainid        InOutChainId
    20  	BpNumber       uint32
    21  	MaxBlockSize   uint64
    22  	MaxTokens      string
    23  	StakingMinimum string `json:",omitempty"`
    24  	StakingTotal   string `json:",omitempty"`
    25  }
    26  
    27  func ConvChainInfoMsg(msg *types.ChainInfo) string {
    28  	jsonout, err := json.MarshalIndent(convChainInfo(msg), "", " ")
    29  	if err != nil {
    30  		return ""
    31  	}
    32  	return string(jsonout)
    33  }
    34  
    35  func convChainInfo(msg *types.ChainInfo) *InOutChainInfo {
    36  	out := &InOutChainInfo{}
    37  	out.Chainid.Magic = msg.Id.Magic
    38  	out.Chainid.Public = msg.Id.Public
    39  	out.Chainid.Mainnet = msg.Id.Mainnet
    40  	out.Chainid.Consensus = msg.Id.Consensus
    41  	out.BpNumber = msg.BpNumber
    42  	out.MaxBlockSize = msg.Maxblocksize
    43  	out.MaxTokens = new(big.Int).SetBytes(msg.Maxtokens).String()
    44  
    45  	if consensus.IsDposName(msg.Id.Consensus) {
    46  		out.StakingMinimum = new(big.Int).SetBytes(msg.Stakingminimum).String()
    47  		out.StakingTotal = new(big.Int).SetBytes(msg.Totalstaking).String()
    48  	}
    49  	return out
    50  }