Browse Source

Made all JSON fields lower_case

pull/67/head
Jae Kwon 10 years ago
parent
commit
b92c0401e6
26 changed files with 323 additions and 265 deletions
  1. +6
    -6
      account/account.go
  2. +3
    -3
      account/priv_account.go
  3. +0
    -0
      account/priv_key.go
  4. +0
    -0
      account/pub_key.go
  5. +31
    -31
      config/config.go
  6. +7
    -7
      consensus/pol.go
  7. +9
    -9
      consensus/types/proposal.go
  8. +1
    -1
      consensus/types/proposal_test.go
  9. +39
    -39
      rpc/core/types/responses.go
  10. +58
    -0
      rpc/core_client/client_methods.go
  11. +5
    -5
      rpc/handlers.go
  12. +11
    -11
      rpc/test/.tendermint/genesis.json
  13. +4
    -5
      rpc/test/client_ws_test.go
  14. +12
    -12
      rpc/test/ws_helpers_test.go
  15. +8
    -8
      state/genesis.go
  16. +6
    -6
      state/priv_validator.go
  17. +15
    -19
      state/validator.go
  18. +16
    -16
      types/block.go
  19. +3
    -3
      types/block_meta.go
  20. +16
    -16
      types/events.go
  21. +6
    -6
      types/node.go
  22. +6
    -6
      types/part_set.go
  23. +42
    -42
      types/tx.go
  24. +5
    -5
      types/tx_test.go
  25. +9
    -9
      types/vote.go
  26. +5
    -0
      vm/types.go

+ 6
- 6
account/account.go View File

@ -36,12 +36,12 @@ func HashSignBytes(o Signable) []byte {
// on the blockchain.
// Serialized by binary.[read|write]Reflect
type Account struct {
Address []byte
PubKey PubKey
Sequence uint
Balance uint64
Code []byte // VM code
StorageRoot []byte // VM storage merkle root.
Address []byte `json:"address"`
PubKey PubKey `json:"pub_key"`
Sequence uint `json:"sequence"`
Balance uint64 `json:"balance"`
Code []byte `json:"code"` // VM code
StorageRoot []byte `json:"storage_root"` // VM storage merkle root.
}
func (acc *Account) Copy() *Account {


+ 3
- 3
account/priv_account.go View File

@ -6,9 +6,9 @@ import (
)
type PrivAccount struct {
Address []byte
PubKey PubKey
PrivKey PrivKey
Address []byte `json:"address"`
PubKey PubKey `json:"pub_key"`
PrivKey PrivKey `json:"priv_key"`
}
// Generates a new account with private key.


account/privkey.go → account/priv_key.go View File


account/pubkey.go → account/pub_key.go View File


+ 31
- 31
config/config.go View File

@ -65,64 +65,64 @@ ListenAddr = "0.0.0.0:46657"
`
var DefaultGenesis = `{
"Accounts": [
"accounts": [
{
"Address": "69988763FCF806AC35D1A2F9C4885B7DD7B0599C",
"Amount": 1049800000000000
"address": "69988763FCF806AC35D1A2F9C4885B7DD7B0599C",
"amount": 1049800000000000
},
{
"Address": "D7DFF9806078899C8DA3FE3633CC0BF3C6C2B1BB",
"Amount": 1049800000000000
"address": "D7DFF9806078899C8DA3FE3633CC0BF3C6C2B1BB",
"amount": 1049800000000000
}
],
"Validators": [
"validators": [
{
"PubKey": [1, "323A31EB01877858592AB7D593E9447110AFCD3ACF280D60C4F8E7C04FACC955"],
"Amount": 100000000000,
"UnbondTo": [
"pub_key": [1, "323A31EB01877858592AB7D593E9447110AFCD3ACF280D60C4F8E7C04FACC955"],
"amount": 100000000000,
"unbond_to": [
{
"Address": "69988763FCF806AC35D1A2F9C4885B7DD7B0599C",
"Amount": 100000000000
"address": "69988763FCF806AC35D1A2F9C4885B7DD7B0599C",
"amount": 100000000000
}
]
},
{
"PubKey": [1, "2239C21C81EA7173A6C489145490C015E05D4B97448933B708A7EC5B7B4921E3"],
"Amount": 100000000000,
"UnbondTo": [
"pub_key": [1, "2239C21C81EA7173A6C489145490C015E05D4B97448933B708A7EC5B7B4921E3"],
"amount": 100000000000,
"unbond_to": [
{
"Address": "D7DFF9806078899C8DA3FE3633CC0BF3C6C2B1BB",
"Amount": 100000000000
"address": "D7DFF9806078899C8DA3FE3633CC0BF3C6C2B1BB",
"amount": 100000000000
}
]
},
{
"PubKey": [1, "DD2206E8F889EED3ABAAECEB2D18962D062A887346241820493FFE3B1DEF255D"],
"Amount": 100000000000,
"UnbondTo": [
"pub_key": [1, "DD2206E8F889EED3ABAAECEB2D18962D062A887346241820493FFE3B1DEF255D"],
"amount": 100000000000,
"unbond_to": [
{
"Address": "69988763FCF806AC35D1A2F9C4885B7DD7B0599C",
"Amount": 100000000000
"address": "69988763FCF806AC35D1A2F9C4885B7DD7B0599C",
"amount": 100000000000
}
]
},
{
"PubKey": [1, "1B3256A3754FC6AB01110C166199A2F619E2D76DB3EE751E376FE404AC9FDCFF"],
"Amount": 100000000000,
"UnbondTo": [
"pub_key": [1, "1B3256A3754FC6AB01110C166199A2F619E2D76DB3EE751E376FE404AC9FDCFF"],
"amount": 100000000000,
"unbond_to": [
{
"Address": "69988763FCF806AC35D1A2F9C4885B7DD7B0599C",
"Amount": 50000000000
"address": "69988763FCF806AC35D1A2F9C4885B7DD7B0599C",
"amount": 50000000000
}
]
},
{
"PubKey": [1, "62CF1048BAEBB4FFFF360D5E896E3F4EC72D03D55183596931ED14995D512926"],
"Amount": 100000000000,
"UnbondTo": [
"pub_key": [1, "62CF1048BAEBB4FFFF360D5E896E3F4EC72D03D55183596931ED14995D512926"],
"amount": 100000000000,
"unbond_to": [
{
"Address": "69988763FCF806AC35D1A2F9C4885B7DD7B0599C",
"Amount": 50000000000
"address": "69988763FCF806AC35D1A2F9C4885B7DD7B0599C",
"amount": 50000000000
}
]
}


+ 7
- 7
consensus/pol.go View File

@ -15,18 +15,18 @@ import (
// Commits require an additional round which is strictly less than
// the POL round. Prevote rounds are equal to the POL round.
type POLVoteSignature struct {
Round uint
Signature account.SignatureEd25519
Round uint `json:"round"`
Signature account.SignatureEd25519 `json:"signature"`
}
// Proof of lock.
// +2/3 of validators' prevotes for a given blockhash (or nil)
type POL struct {
Height uint
Round uint
BlockHash []byte // Could be nil, which makes this a proof of unlock.
BlockParts types.PartSetHeader // When BlockHash is nil, this is zero.
Votes []POLVoteSignature // Prevote and commit signatures in ValidatorSet order.
Height uint `json:"height"`
Round uint `json:"round"`
BlockHash []byte `json:"block_hash"` // Could be nil, which makes this a proof of unlock.
BlockParts types.PartSetHeader `json:"block_parts"` // When BlockHash is nil, this is zero.
Votes []POLVoteSignature `json:"votes"` // Prevote and commit signatures in ValidatorSet order.
}
// Returns whether +2/3 have prevoted/committed for BlockHash.


+ 9
- 9
consensus/types/proposal.go View File

@ -18,11 +18,11 @@ var (
)
type Proposal struct {
Height uint
Round uint
BlockParts types.PartSetHeader
POLParts types.PartSetHeader
Signature account.SignatureEd25519
Height uint `json:"height"`
Round uint `json:"round"`
BlockParts types.PartSetHeader `json:"block_parts"`
POLParts types.PartSetHeader `json:"pol_parts"`
Signature account.SignatureEd25519 `json:"signature"`
}
func NewProposal(height uint, round uint, blockParts, polParts types.PartSetHeader) *Proposal {
@ -41,10 +41,10 @@ func (p *Proposal) String() string {
func (p *Proposal) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"Network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(`,"Proprosal":{"BlockParts":`), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(`,"proposal":{"block_parts":`), w, n, err)
p.BlockParts.WriteSignBytes(w, n, err)
binary.WriteTo([]byte(Fmt(`,"Height":%v,"POLParts":`, p.Height)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_parts":`, p.Height)), w, n, err)
p.POLParts.WriteSignBytes(w, n, err)
binary.WriteTo([]byte(Fmt(`,"Round":%v}}`, p.Round)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err)
}

+ 1
- 1
consensus/types/proposal_test.go View File

@ -19,7 +19,7 @@ func TestProposalSignable(t *testing.T) {
}
signBytes := account.SignBytes(proposal)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%X","Proprosal":{"BlockParts":{"Hash":"626C6F636B7061727473","Total":111},"Height":12345,"POLParts":{"Hash":"706F6C7061727473","Total":222},"Round":23456}}`,
expected := Fmt(`{"network":"%X","proposal":{"block_parts":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_parts":{"hash":"706F6C7061727473","total":222},"round":23456}}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)


+ 39
- 39
rpc/core/types/responses.go View File

@ -7,95 +7,95 @@ import (
)
type ResponseGenPrivAccount struct {
PrivAccount *account.PrivAccount
PrivAccount *account.PrivAccount `json:"priv_account"`
}
type ResponseGetAccount struct {
Account *account.Account
Account *account.Account `json:"account"`
}
type ResponseGetStorage struct {
Key []byte
Value []byte
Key []byte `json:"key"`
Value []byte `json:"value"`
}
type ResponseCall struct {
Return []byte
GasUsed uint64
Return []byte `json:"return"`
GasUsed uint64 `json:"gas_used"`
// TODO ...
}
type ResponseListAccounts struct {
BlockHeight uint
Accounts []*account.Account
BlockHeight uint `json:"block_height"`
Accounts []*account.Account `json:"accounts"`
}
type StorageItem struct {
Key []byte
Value []byte
Key []byte `json:"key"`
Value []byte `json:"value"`
}
type ResponseDumpStorage struct {
StorageRoot []byte
StorageItems []StorageItem
StorageRoot []byte `json:"storage_root"`
StorageItems []StorageItem `json:"storage_items"`
}
type ResponseBlockchainInfo struct {
LastHeight uint
BlockMetas []*types.BlockMeta
LastHeight uint `json:"last_height"`
BlockMetas []*types.BlockMeta `json:"block_metas"`
}
type ResponseGetBlock struct {
BlockMeta *types.BlockMeta
Block *types.Block
BlockMeta *types.BlockMeta `json:"block_meta"`
Block *types.Block `json:"block"`
}
type ResponseBroadcastTx struct {
Receipt Receipt
Receipt Receipt `json:"receipt"`
}
type ResponseListUnconfirmedTxs struct {
Txs []types.Tx
Txs []types.Tx `json:"txs"`
}
type Receipt struct {
TxHash []byte
CreatesContract uint8
ContractAddr []byte
TxHash []byte `json:"tx_hash"`
CreatesContract uint8 `json:"creates_contract"`
ContractAddr []byte `json:"contract_addr"`
}
type ResponseStatus struct {
GenesisHash []byte
Network string
LatestBlockHash []byte
LatestBlockHeight uint
LatestBlockTime int64 // nano
GenesisHash []byte `json:"genesis_hash"`
Network string `json:"network"`
LatestBlockHash []byte `json:"lastest_block_hash"`
LatestBlockHeight uint `json:"lastest_block_height"`
LatestBlockTime int64 `json:"latest_bloick_time"` // nano
}
type ResponseNetInfo struct {
Moniker string
Network string
Listening bool
Listeners []string
Peers []Peer
Moniker string `json:"moniker"`
Network string `json:"network"`
Listening bool `json:"listening"`
Listeners []string `json:"listeners"`
Peers []Peer `json:"peers"`
}
type Peer struct {
types.NodeInfo
IsOutbound bool
types.NodeInfo `json:"net_info"`
IsOutbound bool `json:"is_outbound"`
}
type ResponseSignTx struct {
Tx types.Tx
Tx types.Tx `json:"tx"`
}
type ResponseListValidators struct {
BlockHeight uint
BondedValidators []*sm.Validator
UnbondingValidators []*sm.Validator
BlockHeight uint `json:"block_height"`
BondedValidators []*sm.Validator `json:"bonded_validators"`
UnbondingValidators []*sm.Validator `json:"unbonding_validators"`
}
type ResponseDumpConsensusState struct {
RoundState string
PeerRoundStates []string
RoundState string `json:"round_state"`
PeerRoundStates []string `json:"peer_round_states"`
}

+ 58
- 0
rpc/core_client/client_methods.go View File

@ -25,6 +25,7 @@ type Client interface {
GetBlock(height uint) (*ctypes.ResponseGetBlock, error)
GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error)
ListAccounts() (*ctypes.ResponseListAccounts, error)
ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error)
ListValidators() (*ctypes.ResponseListValidators, error)
NetInfo() (*ctypes.ResponseNetInfo, error)
SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error)
@ -361,6 +362,36 @@ func (c *ClientHTTP) ListAccounts() (*ctypes.ResponseListAccounts, error) {
return response.Result, nil
}
func (c *ClientHTTP) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
values, err := argsToURLValues(nil)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["ListUnconfirmedTxs"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *ctypes.ResponseListUnconfirmedTxs `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) ListValidators() (*ctypes.ResponseListValidators, error) {
values, err := argsToURLValues(nil)
if err != nil {
@ -778,6 +809,33 @@ func (c *ClientJSON) ListAccounts() (*ctypes.ResponseListAccounts, error) {
return response.Result, nil
}
func (c *ClientJSON) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
request := rpc.RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["ListUnconfirmedTxs"],
Params: []interface{}{},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *ctypes.ResponseListUnconfirmedTxs `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) ListValidators() (*ctypes.ResponseListValidators, error) {
request := rpc.RPCRequest{
JSONRPC: "2.0",


+ 5
- 5
rpc/handlers.go View File

@ -207,15 +207,15 @@ const (
// for requests coming in
type WSRequest struct {
Type string // subscribe or unsubscribe
Event string
Type string `json:"type"` // subscribe or unsubscribe
Event string `json:"event"`
}
// for responses going out
type WSResponse struct {
Event string
Data interface{}
Error string
Event string `json:"event"`
Data interface{} `json:"data"`
Error string `json:"error"`
}
// a single websocket connection


+ 11
- 11
rpc/test/.tendermint/genesis.json View File

@ -1,22 +1,22 @@
{
"Accounts": [
"accounts": [
{
"Address": "d7dff9806078899c8da3fe3633cc0bf3c6c2b1bb",
"Amount": 200000000
"address": "d7dff9806078899c8da3fe3633cc0bf3c6c2b1bb",
"amount": 200000000
},
{
"Address": "AC89A6DDF4C309A89A2C4078CE409A5A7B282270",
"Amount": 200000000
"address": "AC89A6DDF4C309A89A2C4078CE409A5A7B282270",
"amount": 200000000
}
],
"Validators": [
"validators": [
{
"PubKey": [1, "2239c21c81ea7173a6c489145490c015e05d4b97448933b708a7ec5b7b4921e3"],
"Amount": 1000000,
"UnbondTo": [
"pub_key": [1, "2239c21c81ea7173a6c489145490c015e05d4b97448933b708a7ec5b7b4921e3"],
"amount": 1000000,
"unbond_to": [
{
"Address": "d7dff9806078899c8da3fe3633cc0bf3c6c2b1bb",
"Amount": 100000
"address": "d7dff9806078899c8da3fe3633cc0bf3c6c2b1bb",
"amount": 100000
}
]
}


+ 4
- 5
rpc/test/client_ws_test.go View File

@ -65,7 +65,7 @@ func waitForEvent(t *testing.T, con *websocket.Conn, eventid string, dieOnTimeou
// if the event id isnt what we're waiting on
// ignore it
var response struct {
Event string
Event string `json:"event"`
}
if err := json.Unmarshal(p, &response); err != nil {
ech <- err
@ -112,9 +112,9 @@ func waitForEvent(t *testing.T, con *websocket.Conn, eventid string, dieOnTimeou
func unmarshalResponseNewBlock(b []byte) (*types.Block, error) {
// unmarshall and assert somethings
var response struct {
Event string
Data *types.Block
Error string
Event string `json:"event"`
Data *types.Block `json:"data"`
Error string `json:"error"`
}
var err error
binary.ReadJSON(&response, b, &err)
@ -226,7 +226,6 @@ func TestWSCallWait(t *testing.T) {
waitForEvent(t, con, eid1, true, func() {
_, receipt := broadcastTx(t, "JSONRPC", userByteAddr, nil, code, userBytePriv, amt, 1000, 1000)
contractAddr = receipt.ContractAddr
}, unmarshalValidateCall(amt, returnCode))
// susbscribe to the new contract


+ 12
- 12
rpc/test/ws_helpers_test.go View File

@ -34,9 +34,9 @@ func unmarshalValidateSend(amt uint64, toAddr []byte) func(string, []byte) error
return func(eid string, b []byte) error {
// unmarshal and assert correctness
var response struct {
Event string
Data types.SendTx
Error string
Event string `json:"event"`
Data types.SendTx `json:"data"`
Error string `json:"error"`
}
var err error
binary.ReadJSON(&response, b, &err)
@ -67,13 +67,13 @@ func unmarshalValidateCall(amt uint64, returnCode []byte) func(string, []byte) e
return func(eid string, b []byte) error {
// unmarshall and assert somethings
var response struct {
Event string
Event string `json:"event"`
Data struct {
Tx types.CallTx
Return []byte
Exception string
}
Error string
Tx types.CallTx `json:"tx"`
Return []byte `json:"return"`
Exception string `json:"exception"`
} `json:"data"`
Error string `json:"error"`
}
var err error
binary.ReadJSON(&response, b, &err)
@ -105,9 +105,9 @@ func unmarshalValidateCallCall(origin, returnCode []byte, txid *[]byte) func(str
return func(eid string, b []byte) error {
// unmarshall and assert somethings
var response struct {
Event string
Data types.EventMsgCall
Error string
Event string `json:"event"`
Data types.EventMsgCall `json:"data"`
Error string `json:"error"`
}
var err error
binary.ReadJSON(&response, b, &err)


+ 8
- 8
state/genesis.go View File

@ -13,20 +13,20 @@ import (
)
type GenesisAccount struct {
Address []byte
Amount uint64
Address []byte `json:"address"`
Amount uint64 `json:"amount"`
}
type GenesisValidator struct {
PubKey account.PubKeyEd25519
Amount uint64
UnbondTo []GenesisAccount
PubKey account.PubKeyEd25519 `json:"pub_key"`
Amount uint64 `json:"amount"`
UnbondTo []GenesisAccount `json:"unbond_to"`
}
type GenesisDoc struct {
GenesisTime time.Time
Accounts []GenesisAccount
Validators []GenesisValidator
GenesisTime time.Time `json:"genesis_time"`
Accounts []GenesisAccount `json:"accounts"`
Validators []GenesisValidator `json:"validators"`
}
func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) {


+ 6
- 6
state/priv_validator.go View File

@ -41,12 +41,12 @@ func voteToStep(vote *types.Vote) uint8 {
}
type PrivValidator struct {
Address []byte
PubKey account.PubKeyEd25519
PrivKey account.PrivKeyEd25519
LastHeight uint
LastRound uint
LastStep uint8
Address []byte `json:"address"`
PubKey account.PubKeyEd25519 `json:"pub_key"`
PrivKey account.PrivKeyEd25519 `json:"priv_key"`
LastHeight uint `json:"last_height"`
LastRound uint `json:"last_round"`
LastStep uint8 `json:"last_step"`
// For persistence.
// Overloaded for testing.


+ 15
- 19
state/validator.go View File

@ -12,18 +12,14 @@ import (
// Persistent (mostly) static data for each Validator
type ValidatorInfo struct {
Address []byte
PubKey account.PubKeyEd25519
UnbondTo []*types.TxOutput
FirstBondHeight uint
FirstBondAmount uint64
// If destroyed:
DestroyedHeight uint
DestroyedAmount uint64
// If released:
ReleasedHeight uint
Address []byte `json:"address"`
PubKey account.PubKeyEd25519 `json:"pub_key"`
UnbondTo []*types.TxOutput `json:"unbond_to"`
FirstBondHeight uint `json:"first_bond_height"`
FirstBondAmount uint64 `json:"first_bond_amount"`
DestroyedHeight uint `json:"destroyed_height"` // If destroyed
DestroyedAmount uint64 `json:"destroyed_amount"` // If destroyed
ReleasedHeight uint `json:"released_height"` // If released
}
func (valInfo *ValidatorInfo) Copy() *ValidatorInfo {
@ -50,13 +46,13 @@ var ValidatorInfoCodec = binary.Codec{
// Also persisted with the state, but fields change
// every height|round so they don't go in merkle.Tree
type Validator struct {
Address []byte
PubKey account.PubKeyEd25519
BondHeight uint
UnbondHeight uint
LastCommitHeight uint
VotingPower uint64
Accum int64
Address []byte `json:"address"`
PubKey account.PubKeyEd25519 `json:"pub_key"`
BondHeight uint `json:"bond_height"`
UnbondHeight uint `json:"unbond_height"`
LastCommitHeight uint `json:"last_commit_height"`
VotingPower uint64 `json:"voting_power"`
Accum int64 `json:"accum"`
}
// Creates a new copy of the validator so we can mutate accum.


+ 16
- 16
types/block.go View File

@ -16,9 +16,9 @@ import (
)
type Block struct {
*Header
*Validation
*Data
*Header `json:"header"`
*Validation `json:"validation"`
*Data `json:"data"`
}
// Basic validation that doesn't involve state data.
@ -123,14 +123,14 @@ func (b *Block) StringShort() string {
//-----------------------------------------------------------------------------
type Header struct {
Network string
Height uint
Time time.Time
Fees uint64
NumTxs uint
LastBlockHash []byte
LastBlockParts PartSetHeader
StateHash []byte
Network string `json:"network"`
Height uint `json:"height"`
Time time.Time `json:"time"`
Fees uint64 `json:"fees"`
NumTxs uint `json:"num_txs"`
LastBlockHash []byte `json:"last_block_hash"`
LastBlockParts PartSetHeader `json:"last_block_parts"`
StateHash []byte `json:"state_hash"`
}
// NOTE: hash is nil if required fields are missing.
@ -178,9 +178,9 @@ func (h *Header) StringIndented(indent string) string {
//-----------------------------------------------------------------------------
type Commit struct {
Address []byte
Round uint
Signature account.SignatureEd25519
Address []byte `json:"address"`
Round uint `json:"round"`
Signature account.SignatureEd25519 `json:"signature"`
}
func (commit Commit) IsZero() bool {
@ -197,7 +197,7 @@ func (commit Commit) String() string {
// Any peer with a block can gossip commits by index with a peer without recalculating the
// active ValidatorSet.
type Validation struct {
Commits []Commit // Commits (or nil) of all active validators in address order.
Commits []Commit `json:"commits"` // Commits (or nil) of all active validators in address order.
// Volatile
hash []byte
@ -267,7 +267,7 @@ func (v *Validation) BitArray() BitArray {
//-----------------------------------------------------------------------------
type Data struct {
Txs []Tx
Txs []Tx `json:"txs"`
// Volatile
hash []byte


+ 3
- 3
types/block_meta.go View File

@ -1,9 +1,9 @@
package types
type BlockMeta struct {
Hash []byte // The block hash
Header *Header // The block's Header
Parts PartSetHeader // The PartSetHeader, for transfer
Hash []byte `json:"hash"` // The block hash
Header *Header `json:"header"` // The block's Header
Parts PartSetHeader `json:"parts"` // The PartSetHeader, for transfer
}
func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta {


+ 16
- 16
types/events.go View File

@ -7,15 +7,15 @@ import (
// Functions to generate eventId strings
func EventStringAccInput(addr []byte) string {
return fmt.Sprintf("Acc/%x/Input", addr)
return fmt.Sprintf("Acc/%X/Input", addr)
}
func EventStringAccOutput(addr []byte) string {
return fmt.Sprintf("Acc/%x/Output", addr)
return fmt.Sprintf("Acc/%X/Output", addr)
}
func EventStringAccReceive(addr []byte) string {
return fmt.Sprintf("Acc/%x/Receive", addr)
return fmt.Sprintf("Acc/%X/Receive", addr)
}
func EventStringBond() string {
@ -46,25 +46,25 @@ func EventStringFork() string {
// but some (an input to a call tx or a receive) are more exotic:
type EventMsgCallTx struct {
Tx Tx
Return []byte
Exception string
Tx Tx `json:"tx"`
Return []byte `json:"return"`
Exception string `json:"exception"`
}
type CallData struct {
Caller []byte
Callee []byte
Data []byte
Value uint64
Gas uint64
Caller []byte `json:"caller"`
Callee []byte `json:"callee"`
Data []byte `json:"data"`
Value uint64 `json:"value"`
Gas uint64 `json:"gas"`
}
type EventMsgCall struct {
CallData *CallData
Origin []byte
TxId []byte
Return []byte
Exception string
CallData *CallData `json:"call_data"`
Origin []byte `json:"origin"`
TxId []byte `json:"tx_id"`
Return []byte `json:"return"`
Exception string `json:"exception"`
}
/*


+ 6
- 6
types/node.go View File

@ -6,13 +6,13 @@ import (
)
type NodeInfo struct {
Moniker string
Network string
Version string
Moniker string `json:"moniker"`
Network string `json:"network"`
Version string `json:"version"`
Host string
P2PPort uint16
RPCPort uint16
Host string `json:"host"`
P2PPort uint16 `json:"p2p_port"`
RPCPort uint16 `json:"rpc_port"`
}
func (ni *NodeInfo) CompatibleWith(no *NodeInfo) error {


+ 6
- 6
types/part_set.go View File

@ -24,9 +24,9 @@ var (
)
type Part struct {
Index uint
Trail [][]byte
Bytes []byte
Index uint `json:"index"`
Trail [][]byte `json:"trail"`
Bytes []byte `json:"bytes"`
// Cache
hash []byte
@ -69,8 +69,8 @@ func (part *Part) StringIndented(indent string) string {
//-------------------------------------
type PartSetHeader struct {
Total uint
Hash []byte
Total uint `json:"total"`
Hash []byte `json:"hash"`
}
func (psh PartSetHeader) String() string {
@ -86,7 +86,7 @@ func (psh PartSetHeader) Equals(other PartSetHeader) bool {
}
func (psh PartSetHeader) WriteSignBytes(w io.Writer, n *int64, err *error) {
binary.WriteTo([]byte(Fmt(`{"Hash":"%X","Total":%v}`, psh.Hash, psh.Total)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"hash":"%X","total":%v}`, psh.Hash, psh.Total)), w, n, err)
}
//-------------------------------------


+ 42
- 42
types/tx.go View File

@ -73,11 +73,11 @@ var _ = binary.RegisterInterface(
//-----------------------------------------------------------------------------
type TxInput struct {
Address []byte // Hash of the PubKey
Amount uint64 // Must not exceed account balance
Sequence uint // Must be 1 greater than the last committed TxInput
Signature account.Signature // Depends on the PubKey type and the whole Tx
PubKey account.PubKey // Must not be nil, may be nil
Address []byte `json:"address"` // Hash of the PubKey
Amount uint64 `json:"amount"` // Must not exceed account balance
Sequence uint `json:"sequence"` // Must be 1 greater than the last committed TxInput
Signature account.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx
PubKey account.PubKey `json:"pub_key"` // Must not be nil, may be nil
}
func (txIn *TxInput) ValidateBasic() error {
@ -91,7 +91,7 @@ func (txIn *TxInput) ValidateBasic() error {
}
func (txIn *TxInput) WriteSignBytes(w io.Writer, n *int64, err *error) {
binary.WriteTo([]byte(Fmt(`{"Address":"%X","Amount":%v,"Sequence":%v}`, txIn.Address, txIn.Amount, txIn.Sequence)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"address":"%X","amount":%v,"sequence":%v}`, txIn.Address, txIn.Amount, txIn.Sequence)), w, n, err)
}
func (txIn *TxInput) String() string {
@ -101,8 +101,8 @@ func (txIn *TxInput) String() string {
//-----------------------------------------------------------------------------
type TxOutput struct {
Address []byte // Hash of the PubKey
Amount uint64 // The sum of all outputs must not exceed the inputs.
Address []byte `json:"address"` // Hash of the PubKey
Amount uint64 `json:"amount"` // The sum of all outputs must not exceed the inputs.
}
func (txOut *TxOutput) ValidateBasic() error {
@ -116,7 +116,7 @@ func (txOut *TxOutput) ValidateBasic() error {
}
func (txOut *TxOutput) WriteSignBytes(w io.Writer, n *int64, err *error) {
binary.WriteTo([]byte(Fmt(`{"Address":"%X","Amount":%v}`, txOut.Address, txOut.Amount)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"address":"%X","amount":%v}`, txOut.Address, txOut.Amount)), w, n, err)
}
func (txOut *TxOutput) String() string {
@ -126,21 +126,21 @@ func (txOut *TxOutput) String() string {
//-----------------------------------------------------------------------------
type SendTx struct {
Inputs []*TxInput
Outputs []*TxOutput
Inputs []*TxInput `json:"inputs"`
Outputs []*TxOutput `json:"outputs"`
}
func (tx *SendTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"Network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Tx":[%v,{"Inputs":[`, TxTypeSend)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err)
for i, in := range tx.Inputs {
in.WriteSignBytes(w, n, err)
if i != len(tx.Inputs)-1 {
binary.WriteTo([]byte(","), w, n, err)
}
}
binary.WriteTo([]byte(`],"Outputs":[`), w, n, err)
binary.WriteTo([]byte(`],"outputs":[`), w, n, err)
for i, out := range tx.Outputs {
out.WriteSignBytes(w, n, err)
if i != len(tx.Outputs)-1 {
@ -157,18 +157,18 @@ func (tx *SendTx) String() string {
//-----------------------------------------------------------------------------
type CallTx struct {
Input *TxInput
Address []byte
GasLimit uint64
Fee uint64
Data []byte
Input *TxInput `json:"input"`
Address []byte `json:"address"`
GasLimit uint64 `json:"gas_limit"`
Fee uint64 `json:"fee"`
Data []byte `json:"data"`
}
func (tx *CallTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"Network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Tx":[%v,{"Address":"%X","Data":"%X"`, TxTypeCall, tx.Address, tx.Data)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Fee":%v,"GasLimit":%v,"Input":`, tx.Fee, tx.GasLimit)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","data":"%X"`, TxTypeCall, tx.Address, tx.Data)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"fee":%v,"gas_limit":%v,"input":`, tx.Fee, tx.GasLimit)), w, n, err)
tx.Input.WriteSignBytes(w, n, err)
binary.WriteTo([]byte(`}]}`), w, n, err)
}
@ -180,24 +180,24 @@ func (tx *CallTx) String() string {
//-----------------------------------------------------------------------------
type BondTx struct {
PubKey account.PubKeyEd25519
Inputs []*TxInput
UnbondTo []*TxOutput
PubKey account.PubKeyEd25519 `json:"pub_key"`
Inputs []*TxInput `json:"inputs"`
UnbondTo []*TxOutput `json:"unbond_to"`
}
func (tx *BondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"Network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Tx":[%v,{"Inputs":[`, TxTypeBond)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err)
for i, in := range tx.Inputs {
in.WriteSignBytes(w, n, err)
if i != len(tx.Inputs)-1 {
binary.WriteTo([]byte(","), w, n, err)
}
}
binary.WriteTo([]byte(Fmt(`],"PubKey":`)), w, n, err)
binary.WriteTo([]byte(Fmt(`],"pub_key":`)), w, n, err)
binary.WriteTo(binary.JSONBytes(tx.PubKey), w, n, err)
binary.WriteTo([]byte(`,"UnbondTo":[`), w, n, err)
binary.WriteTo([]byte(`,"unbond_to":[`), w, n, err)
for i, out := range tx.UnbondTo {
out.WriteSignBytes(w, n, err)
if i != len(tx.UnbondTo)-1 {
@ -214,15 +214,15 @@ func (tx *BondTx) String() string {
//-----------------------------------------------------------------------------
type UnbondTx struct {
Address []byte
Height uint
Signature account.SignatureEd25519
Address []byte `json:"address"`
Height uint `json:"height"`
Signature account.SignatureEd25519 `json:"signature"`
}
func (tx *UnbondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"Network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Tx":[%v,{"Address":"%X","Height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err)
}
func (tx *UnbondTx) String() string {
@ -232,15 +232,15 @@ func (tx *UnbondTx) String() string {
//-----------------------------------------------------------------------------
type RebondTx struct {
Address []byte
Height uint
Signature account.SignatureEd25519
Address []byte `json:"address"`
Height uint `json:"height"`
Signature account.SignatureEd25519 `json:"signature"`
}
func (tx *RebondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"Network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Tx":[%v,{"Address":"%X","Height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err)
}
func (tx *RebondTx) String() string {
@ -250,9 +250,9 @@ func (tx *RebondTx) String() string {
//-----------------------------------------------------------------------------
type DupeoutTx struct {
Address []byte
VoteA Vote
VoteB Vote
Address []byte `json:"address"`
VoteA Vote `json:"vote_a"`
VoteB Vote `json:"vote_b"`
}
func (tx *DupeoutTx) WriteSignBytes(w io.Writer, n *int64, err *error) {


+ 5
- 5
types/tx_test.go View File

@ -35,7 +35,7 @@ func TestSendTxSignable(t *testing.T) {
}
signBytes := account.SignBytes(sendTx)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%X","Tx":[1,{"Inputs":[{"Address":"696E70757431","Amount":12345,"Sequence":67890},{"Address":"696E70757432","Amount":111,"Sequence":222}],"Outputs":[{"Address":"6F757470757431","Amount":333},{"Address":"6F757470757432","Amount":444}]}]}`,
expected := Fmt(`{"network":"%X","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)
@ -56,7 +56,7 @@ func TestCallTxSignable(t *testing.T) {
}
signBytes := account.SignBytes(callTx)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%X","Tx":[2,{"Address":"636F6E747261637431","Data":"6461746131","Fee":222,"GasLimit":111,"Input":{"Address":"696E70757431","Amount":12345,"Sequence":67890}}]}`,
expected := Fmt(`{"network":"%X","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr)
@ -92,7 +92,7 @@ func TestBondTxSignable(t *testing.T) {
}
signBytes := account.SignBytes(bondTx)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%X","Tx":[17,{"Inputs":[{"Address":"696E70757431","Amount":12345,"Sequence":67890},{"Address":"696E70757432","Amount":111,"Sequence":222}],"PubKey":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"UnbondTo":[{"Address":"6F757470757431","Amount":333},{"Address":"6F757470757432","Amount":444}]}]}`,
expected := Fmt(`{"network":"%X","tx":[17,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"pub_key":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"unbond_to":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for BondTx")
@ -106,7 +106,7 @@ func TestUnbondTxSignable(t *testing.T) {
}
signBytes := account.SignBytes(unbondTx)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%X","Tx":[18,{"Address":"6164647265737331","Height":111}]}`,
expected := Fmt(`{"network":"%X","tx":[18,{"address":"6164647265737331","height":111}]}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for UnbondTx")
@ -120,7 +120,7 @@ func TestRebondTxSignable(t *testing.T) {
}
signBytes := account.SignBytes(rebondTx)
signStr := string(signBytes)
expected := Fmt(`{"Network":"%X","Tx":[19,{"Address":"6164647265737331","Height":111}]}`,
expected := Fmt(`{"network":"%X","tx":[19,{"address":"6164647265737331","height":111}]}`,
config.App().GetString("Network"))
if signStr != expected {
t.Errorf("Got unexpected sign string for RebondTx")


+ 9
- 9
types/vote.go View File

@ -31,12 +31,12 @@ func (err *ErrVoteConflictingSignature) Error() string {
// Commit votes get aggregated into the next block's Validaiton.
// See the whitepaper for details.
type Vote struct {
Height uint
Round uint
Type byte
BlockHash []byte // empty if vote is nil.
BlockParts PartSetHeader // zero if vote is nil.
Signature account.SignatureEd25519
Height uint `json:"height"`
Round uint `json:"round"`
Type byte `json:"type"`
BlockHash []byte `json:"block_hash"` // empty if vote is nil.
BlockParts PartSetHeader `json:"block_parts"` // zero if vote is nil.
Signature account.SignatureEd25519 `json:"signature"`
}
// Types of votes
@ -48,9 +48,9 @@ const (
func (vote *Vote) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"Network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Vote":{"BlockHash":"%X","BlockParts":%v`, vote.BlockHash, vote.BlockParts)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"Height":%v,"Round":%v,"Type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err)
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"vote":{"block_hash":"%X","block_parts":%v`, vote.BlockHash, vote.BlockParts)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err)
}
func (vote *Vote) Copy() *Vote {


+ 5
- 0
vm/types.go View File

@ -17,6 +17,11 @@ type Account struct {
Other interface{} // For holding all other data.
}
func (acc *Account) String() string {
return Fmt("VMAccount{%X B:%v C:%X N:%v S:%X}",
acc.Address, acc.Balance, acc.Code, acc.Nonce, acc.StorageRoot)
}
type Log struct {
Address Word256
Topics []Word256


Loading…
Cancel
Save