commit
5230440141
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/merkle"
|
"github.com/tendermint/tendermint/merkle"
|
||||||
ptypes "github.com/tendermint/tendermint/permission/types"
|
ptypes "github.com/tendermint/tendermint/permission/types"
|
||||||
|
@ -36,7 +36,7 @@ func HashSignBytes(chainID string, o Signable) []byte {
|
||||||
|
|
||||||
// Account resides in the application state, and is mutated by transactions
|
// Account resides in the application state, and is mutated by transactions
|
||||||
// on the blockchain.
|
// on the blockchain.
|
||||||
// Serialized by binary.[read|write]Reflect
|
// Serialized by wire.[read|write]Reflect
|
||||||
type Account struct {
|
type Account struct {
|
||||||
Address []byte `json:"address"`
|
Address []byte `json:"address"`
|
||||||
PubKey PubKey `json:"pub_key"`
|
PubKey PubKey `json:"pub_key"`
|
||||||
|
@ -61,14 +61,14 @@ func (acc *Account) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func AccountEncoder(o interface{}, w io.Writer, n *int64, err *error) {
|
func AccountEncoder(o interface{}, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteBinary(o.(*Account), w, n, err)
|
wire.WriteBinary(o.(*Account), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AccountDecoder(r io.Reader, n *int64, err *error) interface{} {
|
func AccountDecoder(r io.Reader, n *int64, err *error) interface{} {
|
||||||
return binary.ReadBinary(&Account{}, r, n, err)
|
return wire.ReadBinary(&Account{}, r, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var AccountCodec = binary.Codec{
|
var AccountCodec = wire.Codec{
|
||||||
Encode: AccountEncoder,
|
Encode: AccountEncoder,
|
||||||
Decode: AccountDecoder,
|
Decode: AccountDecoder,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func GenPrivAccount() *PrivAccount {
|
||||||
|
|
||||||
// Generates a new account with private key from SHA256 hash of a secret
|
// Generates a new account with private key from SHA256 hash of a secret
|
||||||
func GenPrivAccountFromSecret(secret []byte) *PrivAccount {
|
func GenPrivAccountFromSecret(secret []byte) *PrivAccount {
|
||||||
privKey32 := binary.BinarySha256(secret) // Not Ripemd160 because we want 32 bytes.
|
privKey32 := wire.BinarySha256(secret) // Not Ripemd160 because we want 32 bytes.
|
||||||
privKeyBytes := new([64]byte)
|
privKeyBytes := new([64]byte)
|
||||||
copy(privKeyBytes[:32], privKey32)
|
copy(privKeyBytes[:32], privKey32)
|
||||||
pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
|
pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package account
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@ const (
|
||||||
PrivKeyTypeEd25519 = byte(0x01)
|
PrivKeyTypeEd25519 = byte(0x01)
|
||||||
)
|
)
|
||||||
|
|
||||||
// for binary.readReflect
|
// for wire.readReflect
|
||||||
var _ = binary.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ PrivKey }{},
|
struct{ PrivKey }{},
|
||||||
binary.ConcreteType{PrivKeyEd25519{}, PrivKeyTypeEd25519},
|
wire.ConcreteType{PrivKeyEd25519{}, PrivKeyTypeEd25519},
|
||||||
)
|
)
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
@ -53,7 +53,7 @@ func (privKey PrivKeyEd25519) String() string {
|
||||||
|
|
||||||
// Deterministically generates new priv-key bytes from key.
|
// Deterministically generates new priv-key bytes from key.
|
||||||
func (key PrivKeyEd25519) Generate(index int) PrivKeyEd25519 {
|
func (key PrivKeyEd25519) Generate(index int) PrivKeyEd25519 {
|
||||||
newBytes := binary.BinarySha256(struct {
|
newBytes := wire.BinarySha256(struct {
|
||||||
PrivKey [64]byte
|
PrivKey [64]byte
|
||||||
Index int
|
Index int
|
||||||
}{key, index})
|
}{key, index})
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519"
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/golang.org/x/crypto/ripemd160"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/golang.org/x/crypto/ripemd160"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,10 +21,10 @@ const (
|
||||||
PubKeyTypeEd25519 = byte(0x01)
|
PubKeyTypeEd25519 = byte(0x01)
|
||||||
)
|
)
|
||||||
|
|
||||||
// for binary.readReflect
|
// for wire.readReflect
|
||||||
var _ = binary.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ PubKey }{},
|
struct{ PubKey }{},
|
||||||
binary.ConcreteType{PubKeyEd25519{}, PubKeyTypeEd25519},
|
wire.ConcreteType{PubKeyEd25519{}, PubKeyTypeEd25519},
|
||||||
)
|
)
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
@ -38,7 +38,7 @@ type PubKeyEd25519 [32]byte
|
||||||
// compatibility for when the pubkey wasn't fixed length array
|
// compatibility for when the pubkey wasn't fixed length array
|
||||||
func (pubKey PubKeyEd25519) Address() []byte {
|
func (pubKey PubKeyEd25519) Address() []byte {
|
||||||
w, n, err := new(bytes.Buffer), new(int64), new(error)
|
w, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
binary.WriteBinary(pubKey[:], w, n, err)
|
wire.WriteBinary(pubKey[:], w, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
PanicCrisis(*err)
|
PanicCrisis(*err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package account
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@ const (
|
||||||
SignatureTypeEd25519 = byte(0x01)
|
SignatureTypeEd25519 = byte(0x01)
|
||||||
)
|
)
|
||||||
|
|
||||||
// for binary.readReflect
|
// for wire.readReflect
|
||||||
var _ = binary.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ Signature }{},
|
struct{ Signature }{},
|
||||||
binary.ConcreteType{SignatureEd25519{}, SignatureTypeEd25519},
|
wire.ConcreteType{SignatureEd25519{}, SignatureTypeEd25519},
|
||||||
)
|
)
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ func TestBinaryDecode(t *testing.T) {
|
||||||
t.Logf("msg: %X, sig: %X", msg, sig)
|
t.Logf("msg: %X, sig: %X", msg, sig)
|
||||||
|
|
||||||
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
binary.WriteBinary(sig, buf, n, err)
|
wire.WriteBinary(sig, buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
t.Fatalf("Failed to write Signature: %v", err)
|
t.Fatalf("Failed to write Signature: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func TestBinaryDecode(t *testing.T) {
|
||||||
t.Fatalf("Unexpected signature type byte")
|
t.Fatalf("Unexpected signature type byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
sig2, ok := binary.ReadBinary(SignatureEd25519{}, buf, n, err).(SignatureEd25519)
|
sig2, ok := wire.ReadBinary(SignatureEd25519{}, buf, n, err).(SignatureEd25519)
|
||||||
if !ok || *err != nil {
|
if !ok || *err != nil {
|
||||||
t.Fatalf("Failed to read Signature: %v", err)
|
t.Fatalf("Failed to read Signature: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/events"
|
"github.com/tendermint/tendermint/events"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
|
@ -271,19 +271,19 @@ const (
|
||||||
|
|
||||||
type BlockchainMessage interface{}
|
type BlockchainMessage interface{}
|
||||||
|
|
||||||
var _ = binary.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ BlockchainMessage }{},
|
struct{ BlockchainMessage }{},
|
||||||
binary.ConcreteType{&bcBlockRequestMessage{}, msgTypeBlockRequest},
|
wire.ConcreteType{&bcBlockRequestMessage{}, msgTypeBlockRequest},
|
||||||
binary.ConcreteType{&bcBlockResponseMessage{}, msgTypeBlockResponse},
|
wire.ConcreteType{&bcBlockResponseMessage{}, msgTypeBlockResponse},
|
||||||
binary.ConcreteType{&bcStatusResponseMessage{}, msgTypeStatusResponse},
|
wire.ConcreteType{&bcStatusResponseMessage{}, msgTypeStatusResponse},
|
||||||
binary.ConcreteType{&bcStatusRequestMessage{}, msgTypeStatusRequest},
|
wire.ConcreteType{&bcStatusRequestMessage{}, msgTypeStatusRequest},
|
||||||
)
|
)
|
||||||
|
|
||||||
func DecodeMessage(bz []byte) (msgType byte, msg BlockchainMessage, err error) {
|
func DecodeMessage(bz []byte) (msgType byte, msg BlockchainMessage, err error) {
|
||||||
msgType = bz[0]
|
msgType = bz[0]
|
||||||
n := new(int64)
|
n := new(int64)
|
||||||
r := bytes.NewReader(bz)
|
r := bytes.NewReader(bz)
|
||||||
msg = binary.ReadBinary(struct{ BlockchainMessage }{}, r, n, &err).(struct{ BlockchainMessage }).BlockchainMessage
|
msg = wire.ReadBinary(struct{ BlockchainMessage }{}, r, n, &err).(struct{ BlockchainMessage }).BlockchainMessage
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
dbm "github.com/tendermint/tendermint/db"
|
dbm "github.com/tendermint/tendermint/db"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
@ -59,7 +59,7 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
meta := binary.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta)
|
meta := wire.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Error reading block meta: %v", err))
|
PanicCrisis(Fmt("Error reading block meta: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block {
|
||||||
part := bs.LoadBlockPart(height, i)
|
part := bs.LoadBlockPart(height, i)
|
||||||
bytez = append(bytez, part.Bytes...)
|
bytez = append(bytez, part.Bytes...)
|
||||||
}
|
}
|
||||||
block := binary.ReadBinary(&types.Block{}, bytes.NewReader(bytez), &n, &err).(*types.Block)
|
block := wire.ReadBinary(&types.Block{}, bytes.NewReader(bytez), &n, &err).(*types.Block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Error reading block: %v", err))
|
PanicCrisis(Fmt("Error reading block: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func (bs *BlockStore) LoadBlockPart(height int, index int) *types.Part {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
part := binary.ReadBinary(&types.Part{}, r, &n, &err).(*types.Part)
|
part := wire.ReadBinary(&types.Part{}, r, &n, &err).(*types.Part)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Error reading block part: %v", err))
|
PanicCrisis(Fmt("Error reading block part: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ func (bs *BlockStore) LoadBlockMeta(height int) *types.BlockMeta {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
meta := binary.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta)
|
meta := wire.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Error reading block meta: %v", err))
|
PanicCrisis(Fmt("Error reading block meta: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func (bs *BlockStore) LoadBlockValidation(height int) *types.Validation {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
validation := binary.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation)
|
validation := wire.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Error reading validation: %v", err))
|
PanicCrisis(Fmt("Error reading validation: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ func (bs *BlockStore) LoadSeenValidation(height int) *types.Validation {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
validation := binary.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation)
|
validation := wire.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Error reading validation: %v", err))
|
PanicCrisis(Fmt("Error reading validation: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
|
||||||
|
|
||||||
// Save block meta
|
// Save block meta
|
||||||
meta := types.NewBlockMeta(block, blockParts)
|
meta := types.NewBlockMeta(block, blockParts)
|
||||||
metaBytes := binary.BinaryBytes(meta)
|
metaBytes := wire.BinaryBytes(meta)
|
||||||
bs.db.Set(calcBlockMetaKey(height), metaBytes)
|
bs.db.Set(calcBlockMetaKey(height), metaBytes)
|
||||||
|
|
||||||
// Save block parts
|
// Save block parts
|
||||||
|
@ -159,11 +159,11 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save block validation (duplicate and separate from the Block)
|
// Save block validation (duplicate and separate from the Block)
|
||||||
blockValidationBytes := binary.BinaryBytes(block.LastValidation)
|
blockValidationBytes := wire.BinaryBytes(block.LastValidation)
|
||||||
bs.db.Set(calcBlockValidationKey(height-1), blockValidationBytes)
|
bs.db.Set(calcBlockValidationKey(height-1), blockValidationBytes)
|
||||||
|
|
||||||
// Save seen validation (seen +2/3 precommits for block)
|
// Save seen validation (seen +2/3 precommits for block)
|
||||||
seenValidationBytes := binary.BinaryBytes(seenValidation)
|
seenValidationBytes := wire.BinaryBytes(seenValidation)
|
||||||
bs.db.Set(calcSeenValidationKey(height), seenValidationBytes)
|
bs.db.Set(calcSeenValidationKey(height), seenValidationBytes)
|
||||||
|
|
||||||
// Save new BlockStoreStateJSON descriptor
|
// Save new BlockStoreStateJSON descriptor
|
||||||
|
@ -177,7 +177,7 @@ func (bs *BlockStore) saveBlockPart(height int, index int, part *types.Part) {
|
||||||
if height != bs.height+1 {
|
if height != bs.height+1 {
|
||||||
PanicSanity(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height))
|
PanicSanity(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height))
|
||||||
}
|
}
|
||||||
partBytes := binary.BinaryBytes(part)
|
partBytes := wire.BinaryBytes(part)
|
||||||
bs.db.Set(calcBlockPartKey(height, index), partBytes)
|
bs.db.Set(calcBlockPartKey(height, index), partBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/cmd/barak/types"
|
. "github.com/tendermint/tendermint/cmd/barak/types"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
pcm "github.com/tendermint/tendermint/process"
|
pcm "github.com/tendermint/tendermint/process"
|
||||||
|
@ -36,7 +36,7 @@ func ReadBarakOptions(optFile string) *BarakOptions {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Error reading input: %v", err))
|
panic(Fmt("Error reading input: %v", err))
|
||||||
}
|
}
|
||||||
opt := binary.ReadJSON(&BarakOptions{}, optBytes, &err).(*BarakOptions)
|
opt := wire.ReadJSON(&BarakOptions{}, optBytes, &err).(*BarakOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Error parsing input: %v", err))
|
panic(Fmt("Error parsing input: %v", err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/cmd/barak/types"
|
. "github.com/tendermint/tendermint/cmd/barak/types"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
|
@ -108,7 +108,7 @@ func Run(authCommand AuthCommand) (interface{}, error) {
|
||||||
|
|
||||||
func parseValidateCommandStr(authCommandStr string) (Command, error) {
|
func parseValidateCommandStr(authCommandStr string) (Command, error) {
|
||||||
var err error
|
var err error
|
||||||
authCommand := binary.ReadJSON(AuthCommand{}, []byte(authCommandStr), &err).(AuthCommand)
|
authCommand := wire.ReadJSON(AuthCommand{}, []byte(authCommandStr), &err).(AuthCommand)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to parse auth_command")
|
fmt.Printf("Failed to parse auth_command")
|
||||||
return nil, errors.New("AuthCommand parse error")
|
return nil, errors.New("AuthCommand parse error")
|
||||||
|
@ -126,7 +126,7 @@ func parseValidateCommand(authCommand AuthCommand) (Command, error) {
|
||||||
}
|
}
|
||||||
// Parse command
|
// Parse command
|
||||||
var err error
|
var err error
|
||||||
command := binary.ReadJSON(NoncedCommand{}, []byte(commandJSONStr), &err).(NoncedCommand)
|
command := wire.ReadJSON(NoncedCommand{}, []byte(commandJSONStr), &err).(NoncedCommand)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to parse command")
|
fmt.Printf("Failed to parse command")
|
||||||
return nil, errors.New("Command parse error")
|
return nil, errors.New("Command parse error")
|
||||||
|
|
|
@ -2,7 +2,7 @@ package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuthCommand struct {
|
type AuthCommand struct {
|
||||||
|
@ -27,16 +27,16 @@ const (
|
||||||
commandTypeQuit = 0x07
|
commandTypeQuit = 0x07
|
||||||
)
|
)
|
||||||
|
|
||||||
// for binary.readReflect
|
// for wire.readReflect
|
||||||
var _ = binary.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ Command }{},
|
struct{ Command }{},
|
||||||
binary.ConcreteType{CommandStartProcess{}, commandTypeStartProcess},
|
wire.ConcreteType{CommandStartProcess{}, commandTypeStartProcess},
|
||||||
binary.ConcreteType{CommandStopProcess{}, commandTypeStopProcess},
|
wire.ConcreteType{CommandStopProcess{}, commandTypeStopProcess},
|
||||||
binary.ConcreteType{CommandListProcesses{}, commandTypeListProcesses},
|
wire.ConcreteType{CommandListProcesses{}, commandTypeListProcesses},
|
||||||
binary.ConcreteType{CommandServeFile{}, commandTypeServeFile},
|
wire.ConcreteType{CommandServeFile{}, commandTypeServeFile},
|
||||||
binary.ConcreteType{CommandOpenListener{}, commandTypeOpenListener},
|
wire.ConcreteType{CommandOpenListener{}, commandTypeOpenListener},
|
||||||
binary.ConcreteType{CommandCloseListener{}, commandTypeCloseListener},
|
wire.ConcreteType{CommandCloseListener{}, commandTypeCloseListener},
|
||||||
binary.ConcreteType{CommandQuit{}, commandTypeQuit},
|
wire.ConcreteType{CommandQuit{}, commandTypeQuit},
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommandStartProcess struct {
|
type CommandStartProcess struct {
|
||||||
|
|
|
@ -43,7 +43,7 @@ func ValidateHandler(handler http.Handler, validators []Validator) http.Handler
|
||||||
Path string
|
Path string
|
||||||
}{bodyString, pathQuery}
|
}{bodyString, pathQuery}
|
||||||
// Get sign bytes
|
// Get sign bytes
|
||||||
signBytes := binary.BinaryBytes(tuple)
|
signBytes := wire.BinaryBytes(tuple)
|
||||||
// Validate the sign bytes.
|
// Validate the sign bytes.
|
||||||
//if validate(signBytes, validators,
|
//if validate(signBytes, validators,
|
||||||
log.Info("Should sign", "bytes", signBytes)
|
log.Info("Should sign", "bytes", signBytes)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/rpc/client"
|
"github.com/tendermint/tendermint/rpc/client"
|
||||||
|
@ -81,7 +81,7 @@ func DownloadFile(privKey acm.PrivKey, remote string, command btypes.CommandServ
|
||||||
CommandJSONStr: string(commandBytes),
|
CommandJSONStr: string(commandBytes),
|
||||||
Signatures: []acm.Signature{signature},
|
Signatures: []acm.Signature{signature},
|
||||||
}
|
}
|
||||||
authCommandJSONBytes := binary.JSONBytes(authCommand)
|
authCommandJSONBytes := wire.JSONBytes(authCommand)
|
||||||
// Make request and write to outPath.
|
// Make request and write to outPath.
|
||||||
httpResponse, err := http.PostForm(remote+"/download", url.Values{"auth_command": {string(authCommandJSONBytes)}})
|
httpResponse, err := http.PostForm(remote+"/download", url.Values{"auth_command": {string(authCommandJSONBytes)}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -133,7 +133,7 @@ func SignCommand(privKey acm.PrivKey, nonce int64, command btypes.Command) ([]by
|
||||||
Nonce: nonce,
|
Nonce: nonce,
|
||||||
Command: command,
|
Command: command,
|
||||||
}
|
}
|
||||||
commandJSONBytes := binary.JSONBytes(noncedCommand)
|
commandJSONBytes := wire.JSONBytes(noncedCommand)
|
||||||
signature := privKey.Sign(commandJSONBytes)
|
signature := privKey.Sign(commandJSONBytes)
|
||||||
return commandJSONBytes, signature
|
return commandJSONBytes, signature
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
|
@ -133,7 +133,7 @@ func ReadConfig(configFilePath string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Failed to read config file %v. %v\n", configFilePath, err))
|
Exit(Fmt("Failed to read config file %v. %v\n", configFilePath, err))
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&Config, configJSONBytes, &err)
|
wire.ReadJSON(&Config, configJSONBytes, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Failed to parse config. %v", err))
|
Exit(Fmt("Failed to parse config. %v", err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func gen_account() {
|
func gen_account() {
|
||||||
privAccount := acm.GenPrivAccount()
|
privAccount := acm.GenPrivAccount()
|
||||||
privAccountJSONBytes := binary.JSONBytes(privAccount)
|
privAccountJSONBytes := wire.JSONBytes(privAccount)
|
||||||
fmt.Printf(`Generated a new account!
|
fmt.Printf(`Generated a new account!
|
||||||
|
|
||||||
%v
|
%v
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
dbm "github.com/tendermint/tendermint/db"
|
dbm "github.com/tendermint/tendermint/db"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
|
@ -54,7 +54,7 @@ func gen_tx() {
|
||||||
// Get source pubkey
|
// Get source pubkey
|
||||||
srcPubKeyBytes := getByteSliceFromHex("Enter source pubkey: ")
|
srcPubKeyBytes := getByteSliceFromHex("Enter source pubkey: ")
|
||||||
r, n, err := bytes.NewReader(srcPubKeyBytes), new(int64), new(error)
|
r, n, err := bytes.NewReader(srcPubKeyBytes), new(int64), new(error)
|
||||||
srcPubKey := binary.ReadBinary(struct{ acm.PubKey }{}, r, n, err).(struct{ acm.PubKey }).PubKey
|
srcPubKey := wire.ReadBinary(struct{ acm.PubKey }{}, r, n, err).(struct{ acm.PubKey }).PubKey
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
Exit(Fmt("Invalid PubKey. Error: %v", err))
|
Exit(Fmt("Invalid PubKey. Error: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -103,17 +103,17 @@ func gen_tx() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the intermediate form.
|
// Show the intermediate form.
|
||||||
fmt.Printf("Generated tx: %X\n", binary.BinaryBytes(tx))
|
fmt.Printf("Generated tx: %X\n", wire.BinaryBytes(tx))
|
||||||
|
|
||||||
// Get source privkey (for signing)
|
// Get source privkey (for signing)
|
||||||
srcPrivKeyBytes := getByteSliceFromHex("Enter source privkey (for signing): ")
|
srcPrivKeyBytes := getByteSliceFromHex("Enter source privkey (for signing): ")
|
||||||
r, n, err = bytes.NewReader(srcPrivKeyBytes), new(int64), new(error)
|
r, n, err = bytes.NewReader(srcPrivKeyBytes), new(int64), new(error)
|
||||||
srcPrivKey := binary.ReadBinary(struct{ acm.PrivKey }{}, r, n, err).(struct{ acm.PrivKey }).PrivKey
|
srcPrivKey := wire.ReadBinary(struct{ acm.PrivKey }{}, r, n, err).(struct{ acm.PrivKey }).PrivKey
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
Exit(Fmt("Invalid PrivKey. Error: %v", err))
|
Exit(Fmt("Invalid PrivKey. Error: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sign
|
// Sign
|
||||||
tx.Inputs[0].Signature = srcPrivKey.Sign(acm.SignBytes(config.GetString("chain_id"), tx))
|
tx.Inputs[0].Signature = srcPrivKey.Sign(acm.SignBytes(config.GetString("chain_id"), tx))
|
||||||
fmt.Printf("Signed tx: %X\n", binary.BinaryBytes(tx))
|
fmt.Printf("Signed tx: %X\n", wire.BinaryBytes(tx))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,14 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
func gen_validator() {
|
func gen_validator() {
|
||||||
|
|
||||||
privValidator := sm.GenPrivValidator()
|
privValidator := sm.GenPrivValidator()
|
||||||
privValidatorJSONBytes := binary.JSONBytes(privValidator)
|
privValidatorJSONBytes := wire.JSONBytes(privValidator)
|
||||||
fmt.Printf(`Generated a new validator!
|
fmt.Printf(`Generated a new validator!
|
||||||
Paste the following JSON into your %v file
|
Paste the following JSON into your %v file
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
bc "github.com/tendermint/tendermint/blockchain"
|
bc "github.com/tendermint/tendermint/blockchain"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
. "github.com/tendermint/tendermint/consensus/types"
|
. "github.com/tendermint/tendermint/consensus/types"
|
||||||
|
@ -909,15 +909,15 @@ const (
|
||||||
|
|
||||||
type ConsensusMessage interface{}
|
type ConsensusMessage interface{}
|
||||||
|
|
||||||
var _ = binary.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ ConsensusMessage }{},
|
struct{ ConsensusMessage }{},
|
||||||
binary.ConcreteType{&NewRoundStepMessage{}, msgTypeNewRoundStep},
|
wire.ConcreteType{&NewRoundStepMessage{}, msgTypeNewRoundStep},
|
||||||
binary.ConcreteType{&CommitStepMessage{}, msgTypeCommitStep},
|
wire.ConcreteType{&CommitStepMessage{}, msgTypeCommitStep},
|
||||||
binary.ConcreteType{&ProposalMessage{}, msgTypeProposal},
|
wire.ConcreteType{&ProposalMessage{}, msgTypeProposal},
|
||||||
binary.ConcreteType{&ProposalPOLMessage{}, msgTypeProposalPOL},
|
wire.ConcreteType{&ProposalPOLMessage{}, msgTypeProposalPOL},
|
||||||
binary.ConcreteType{&BlockPartMessage{}, msgTypeBlockPart},
|
wire.ConcreteType{&BlockPartMessage{}, msgTypeBlockPart},
|
||||||
binary.ConcreteType{&VoteMessage{}, msgTypeVote},
|
wire.ConcreteType{&VoteMessage{}, msgTypeVote},
|
||||||
binary.ConcreteType{&HasVoteMessage{}, msgTypeHasVote},
|
wire.ConcreteType{&HasVoteMessage{}, msgTypeHasVote},
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: check for unnecessary extra bytes at the end.
|
// TODO: check for unnecessary extra bytes at the end.
|
||||||
|
@ -925,7 +925,7 @@ func DecodeMessage(bz []byte) (msgType byte, msg ConsensusMessage, err error) {
|
||||||
msgType = bz[0]
|
msgType = bz[0]
|
||||||
n := new(int64)
|
n := new(int64)
|
||||||
r := bytes.NewReader(bz)
|
r := bytes.NewReader(bz)
|
||||||
msg = binary.ReadBinary(struct{ ConsensusMessage }{}, r, n, &err).(struct{ ConsensusMessage }).ConsensusMessage
|
msg = wire.ReadBinary(struct{ ConsensusMessage }{}, r, n, &err).(struct{ ConsensusMessage }).ConsensusMessage
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
bc "github.com/tendermint/tendermint/blockchain"
|
bc "github.com/tendermint/tendermint/blockchain"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
. "github.com/tendermint/tendermint/consensus/types"
|
. "github.com/tendermint/tendermint/consensus/types"
|
||||||
|
@ -1028,7 +1028,7 @@ func (cs *ConsensusState) AddProposalBlockPart(height int, part *types.Part) (ad
|
||||||
// Added and completed!
|
// Added and completed!
|
||||||
var n int64
|
var n int64
|
||||||
var err error
|
var err error
|
||||||
cs.ProposalBlock = binary.ReadBinary(&types.Block{}, cs.ProposalBlockParts.GetReader(), &n, &err).(*types.Block)
|
cs.ProposalBlock = wire.ReadBinary(&types.Block{}, cs.ProposalBlockParts.GetReader(), &n, &err).(*types.Block)
|
||||||
log.Info("Received complete proposal", "hash", cs.ProposalBlock.Hash())
|
log.Info("Received complete proposal", "hash", cs.ProposalBlock.Hash())
|
||||||
if cs.Step == RoundStepPropose && cs.isProposalComplete() {
|
if cs.Step == RoundStepPropose && cs.isProposalComplete() {
|
||||||
// Move onto the next step
|
// Move onto the next step
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
@ -39,9 +39,9 @@ func (p *Proposal) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
|
||||||
binary.WriteTo([]byte(`,"proposal":{"block_parts_header":`), w, n, err)
|
wire.WriteTo([]byte(`,"proposal":{"block_parts_header":`), w, n, err)
|
||||||
p.BlockPartsHeader.WriteSignBytes(w, n, err)
|
p.BlockPartsHeader.WriteSignBytes(w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_round":%v`, p.Height, p.POLRound)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"height":%v,"pol_round":%v`, p.Height, p.POLRound)), w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
@ -151,7 +151,7 @@ func (voteSet *VoteSet) addVote(val *sm.Validator, valIndex int, vote *types.Vot
|
||||||
// Add vote.
|
// Add vote.
|
||||||
voteSet.votes[valIndex] = vote
|
voteSet.votes[valIndex] = vote
|
||||||
voteSet.votesBitArray.SetIndex(valIndex, true)
|
voteSet.votesBitArray.SetIndex(valIndex, true)
|
||||||
blockKey := string(vote.BlockHash) + string(binary.BinaryBytes(vote.BlockParts))
|
blockKey := string(vote.BlockHash) + string(wire.BinaryBytes(vote.BlockParts))
|
||||||
totalBlockHashVotes := voteSet.votesByBlock[blockKey] + val.VotingPower
|
totalBlockHashVotes := voteSet.votesByBlock[blockKey] + val.VotingPower
|
||||||
voteSet.votesByBlock[blockKey] = totalBlockHashVotes
|
voteSet.votesByBlock[blockKey] = totalBlockHashVotes
|
||||||
voteSet.totalVotes += val.VotingPower
|
voteSet.totalVotes += val.VotingPower
|
||||||
|
|
|
@ -2,7 +2,7 @@ package crawler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
rpcclient "github.com/tendermint/tendermint/rpc/core_client"
|
rpcclient "github.com/tendermint/tendermint/rpc/core_client"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
@ -196,7 +196,7 @@ func (c *Crawler) consumeMessage(wsMsg *rpcclient.WSMsg, node *Node) error {
|
||||||
Error string
|
Error string
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
binary.ReadJSON(&response, wsMsg.Data, &err)
|
wire.ReadJSON(&response, wsMsg.Data, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/events"
|
"github.com/tendermint/tendermint/events"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
|
@ -114,16 +114,16 @@ const (
|
||||||
|
|
||||||
type MempoolMessage interface{}
|
type MempoolMessage interface{}
|
||||||
|
|
||||||
var _ = binary.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ MempoolMessage }{},
|
struct{ MempoolMessage }{},
|
||||||
binary.ConcreteType{&TxMessage{}, msgTypeTx},
|
wire.ConcreteType{&TxMessage{}, msgTypeTx},
|
||||||
)
|
)
|
||||||
|
|
||||||
func DecodeMessage(bz []byte) (msgType byte, msg MempoolMessage, err error) {
|
func DecodeMessage(bz []byte) (msgType byte, msg MempoolMessage, err error) {
|
||||||
msgType = bz[0]
|
msgType = bz[0]
|
||||||
n := new(int64)
|
n := new(int64)
|
||||||
r := bytes.NewReader(bz)
|
r := bytes.NewReader(bz)
|
||||||
msg = binary.ReadBinary(struct{ MempoolMessage }{}, r, n, &err).(struct{ MempoolMessage }).MempoolMessage
|
msg = wire.ReadBinary(struct{ MempoolMessage }{}, r, n, &err).(struct{ MempoolMessage }).MempoolMessage
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ func ReadIAVLNode(t *IAVLTree, r io.Reader, n *int64, err *error) *IAVLNode {
|
||||||
node := &IAVLNode{}
|
node := &IAVLNode{}
|
||||||
|
|
||||||
// node header
|
// node header
|
||||||
node.height = binary.ReadInt8(r, n, err)
|
node.height = wire.ReadInt8(r, n, err)
|
||||||
node.size = binary.ReadVarint(r, n, err)
|
node.size = wire.ReadVarint(r, n, err)
|
||||||
node.key = decodeByteSlice(t.keyCodec, r, n, err)
|
node.key = decodeByteSlice(t.keyCodec, r, n, err)
|
||||||
|
|
||||||
if node.height == 0 {
|
if node.height == 0 {
|
||||||
|
@ -48,8 +48,8 @@ func ReadIAVLNode(t *IAVLTree, r io.Reader, n *int64, err *error) *IAVLNode {
|
||||||
node.value = decodeByteSlice(t.valueCodec, r, n, err)
|
node.value = decodeByteSlice(t.valueCodec, r, n, err)
|
||||||
} else {
|
} else {
|
||||||
// children
|
// children
|
||||||
node.leftHash = binary.ReadByteSlice(r, n, err)
|
node.leftHash = wire.ReadByteSlice(r, n, err)
|
||||||
node.rightHash = binary.ReadByteSlice(r, n, err)
|
node.rightHash = wire.ReadByteSlice(r, n, err)
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
@ -148,8 +148,8 @@ func (node *IAVLNode) hashWithCount(t *IAVLTree) ([]byte, int) {
|
||||||
// NOTE: sets hashes recursively
|
// NOTE: sets hashes recursively
|
||||||
func (node *IAVLNode) writeHashBytes(t *IAVLTree, w io.Writer) (n int64, hashCount int, err error) {
|
func (node *IAVLNode) writeHashBytes(t *IAVLTree, w io.Writer) (n int64, hashCount int, err error) {
|
||||||
// height & size
|
// height & size
|
||||||
binary.WriteInt8(node.height, w, &n, &err)
|
wire.WriteInt8(node.height, w, &n, &err)
|
||||||
binary.WriteVarint(node.size, w, &n, &err)
|
wire.WriteVarint(node.size, w, &n, &err)
|
||||||
// key is not written for inner nodes, unlike writePersistBytes
|
// key is not written for inner nodes, unlike writePersistBytes
|
||||||
|
|
||||||
if node.height == 0 {
|
if node.height == 0 {
|
||||||
|
@ -166,7 +166,7 @@ func (node *IAVLNode) writeHashBytes(t *IAVLTree, w io.Writer) (n int64, hashCou
|
||||||
if node.leftHash == nil {
|
if node.leftHash == nil {
|
||||||
PanicSanity("node.leftHash was nil in writeHashBytes")
|
PanicSanity("node.leftHash was nil in writeHashBytes")
|
||||||
}
|
}
|
||||||
binary.WriteByteSlice(node.leftHash, w, &n, &err)
|
wire.WriteByteSlice(node.leftHash, w, &n, &err)
|
||||||
// right
|
// right
|
||||||
if node.rightNode != nil {
|
if node.rightNode != nil {
|
||||||
rightHash, rightCount := node.rightNode.hashWithCount(t)
|
rightHash, rightCount := node.rightNode.hashWithCount(t)
|
||||||
|
@ -176,7 +176,7 @@ func (node *IAVLNode) writeHashBytes(t *IAVLTree, w io.Writer) (n int64, hashCou
|
||||||
if node.rightHash == nil {
|
if node.rightHash == nil {
|
||||||
PanicSanity("node.rightHash was nil in writeHashBytes")
|
PanicSanity("node.rightHash was nil in writeHashBytes")
|
||||||
}
|
}
|
||||||
binary.WriteByteSlice(node.rightHash, w, &n, &err)
|
wire.WriteByteSlice(node.rightHash, w, &n, &err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -209,8 +209,8 @@ func (node *IAVLNode) save(t *IAVLTree) []byte {
|
||||||
// NOTE: sets hashes recursively
|
// NOTE: sets hashes recursively
|
||||||
func (node *IAVLNode) writePersistBytes(t *IAVLTree, w io.Writer) (n int64, err error) {
|
func (node *IAVLNode) writePersistBytes(t *IAVLTree, w io.Writer) (n int64, err error) {
|
||||||
// node header
|
// node header
|
||||||
binary.WriteInt8(node.height, w, &n, &err)
|
wire.WriteInt8(node.height, w, &n, &err)
|
||||||
binary.WriteVarint(node.size, w, &n, &err)
|
wire.WriteVarint(node.size, w, &n, &err)
|
||||||
// key (unlike writeHashBytes, key is written for inner nodes)
|
// key (unlike writeHashBytes, key is written for inner nodes)
|
||||||
encodeByteSlice(node.key, t.keyCodec, w, &n, &err)
|
encodeByteSlice(node.key, t.keyCodec, w, &n, &err)
|
||||||
|
|
||||||
|
@ -222,12 +222,12 @@ func (node *IAVLNode) writePersistBytes(t *IAVLTree, w io.Writer) (n int64, err
|
||||||
if node.leftHash == nil {
|
if node.leftHash == nil {
|
||||||
PanicSanity("node.leftHash was nil in writePersistBytes")
|
PanicSanity("node.leftHash was nil in writePersistBytes")
|
||||||
}
|
}
|
||||||
binary.WriteByteSlice(node.leftHash, w, &n, &err)
|
wire.WriteByteSlice(node.leftHash, w, &n, &err)
|
||||||
// right
|
// right
|
||||||
if node.rightHash == nil {
|
if node.rightHash == nil {
|
||||||
PanicSanity("node.rightHash was nil in writePersistBytes")
|
PanicSanity("node.rightHash was nil in writePersistBytes")
|
||||||
}
|
}
|
||||||
binary.WriteByteSlice(node.rightHash, w, &n, &err)
|
wire.WriteByteSlice(node.rightHash, w, &n, &err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -439,8 +439,8 @@ func (node *IAVLNode) rmd(t *IAVLTree) *IAVLNode {
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Read a (length prefixed) byteslice then decode the object using the codec
|
// Read a (length prefixed) byteslice then decode the object using the codec
|
||||||
func decodeByteSlice(codec binary.Codec, r io.Reader, n *int64, err *error) interface{} {
|
func decodeByteSlice(codec wire.Codec, r io.Reader, n *int64, err *error) interface{} {
|
||||||
bytez := binary.ReadByteSlice(r, n, err)
|
bytez := wire.ReadByteSlice(r, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -449,11 +449,11 @@ func decodeByteSlice(codec binary.Codec, r io.Reader, n *int64, err *error) inte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode object using codec, then write a (length prefixed) byteslice.
|
// Encode object using codec, then write a (length prefixed) byteslice.
|
||||||
func encodeByteSlice(o interface{}, codec binary.Codec, w io.Writer, n *int64, err *error) {
|
func encodeByteSlice(o interface{}, codec wire.Codec, w io.Writer, n *int64, err *error) {
|
||||||
buf, n_ := new(bytes.Buffer), new(int64)
|
buf, n_ := new(bytes.Buffer), new(int64)
|
||||||
codec.Encode(o, buf, n_, err)
|
codec.Encode(o, buf, n_, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
binary.WriteByteSlice(buf.Bytes(), w, n, err)
|
wire.WriteByteSlice(buf.Bytes(), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,14 +46,14 @@ func (branch IAVLProofInnerNode) Hash(childHash []byte) []byte {
|
||||||
hasher := ripemd160.New()
|
hasher := ripemd160.New()
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
n, err := int64(0), error(nil)
|
n, err := int64(0), error(nil)
|
||||||
binary.WriteInt8(branch.Height, buf, &n, &err)
|
wire.WriteInt8(branch.Height, buf, &n, &err)
|
||||||
binary.WriteVarint(branch.Size, buf, &n, &err)
|
wire.WriteVarint(branch.Size, buf, &n, &err)
|
||||||
if len(branch.Left) == 0 {
|
if len(branch.Left) == 0 {
|
||||||
binary.WriteByteSlice(childHash, buf, &n, &err)
|
wire.WriteByteSlice(childHash, buf, &n, &err)
|
||||||
binary.WriteByteSlice(branch.Right, buf, &n, &err)
|
wire.WriteByteSlice(branch.Right, buf, &n, &err)
|
||||||
} else {
|
} else {
|
||||||
binary.WriteByteSlice(branch.Left, buf, &n, &err)
|
wire.WriteByteSlice(branch.Left, buf, &n, &err)
|
||||||
binary.WriteByteSlice(childHash, buf, &n, &err)
|
wire.WriteByteSlice(childHash, buf, &n, &err)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Failed to hash IAVLProofInnerNode: %v", err))
|
PanicCrisis(Fmt("Failed to hash IAVLProofInnerNode: %v", err))
|
||||||
|
@ -72,10 +72,10 @@ func (leaf IAVLProofLeafNode) Hash() []byte {
|
||||||
hasher := ripemd160.New()
|
hasher := ripemd160.New()
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
n, err := int64(0), error(nil)
|
n, err := int64(0), error(nil)
|
||||||
binary.WriteInt8(0, buf, &n, &err)
|
wire.WriteInt8(0, buf, &n, &err)
|
||||||
binary.WriteVarint(1, buf, &n, &err)
|
wire.WriteVarint(1, buf, &n, &err)
|
||||||
binary.WriteByteSlice(leaf.KeyBytes, buf, &n, &err)
|
wire.WriteByteSlice(leaf.KeyBytes, buf, &n, &err)
|
||||||
binary.WriteByteSlice(leaf.ValueBytes, buf, &n, &err)
|
wire.WriteByteSlice(leaf.ValueBytes, buf, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Failed to hash IAVLProofLeafNode: %v", err))
|
PanicCrisis(Fmt("Failed to hash IAVLProofLeafNode: %v", err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
. "github.com/tendermint/tendermint/common/test"
|
. "github.com/tendermint/tendermint/common/test"
|
||||||
"github.com/tendermint/tendermint/db"
|
"github.com/tendermint/tendermint/db"
|
||||||
|
@ -43,7 +43,7 @@ func N(l, r interface{}) *IAVLNode {
|
||||||
|
|
||||||
// Setup a deep node
|
// Setup a deep node
|
||||||
func T(n *IAVLNode) *IAVLTree {
|
func T(n *IAVLNode) *IAVLTree {
|
||||||
t := NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 0, nil)
|
t := NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 0, nil)
|
||||||
n.hashWithCount(t)
|
n.hashWithCount(t)
|
||||||
t.root = n
|
t.root = n
|
||||||
return t
|
return t
|
||||||
|
@ -149,7 +149,7 @@ func TestIntegration(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
records := make([]*record, 400)
|
records := make([]*record, 400)
|
||||||
var tree *IAVLTree = NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 0, nil)
|
var tree *IAVLTree = NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 0, nil)
|
||||||
|
|
||||||
randomRecord := func() *record {
|
randomRecord := func() *record {
|
||||||
return &record{randstr(20), randstr(20)}
|
return &record{randstr(20), randstr(20)}
|
||||||
|
@ -219,7 +219,7 @@ func TestPersistence(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct some tree and save it
|
// Construct some tree and save it
|
||||||
t1 := NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 0, db)
|
t1 := NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 0, db)
|
||||||
for key, value := range records {
|
for key, value := range records {
|
||||||
t1.Set(key, value)
|
t1.Set(key, value)
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ func TestPersistence(t *testing.T) {
|
||||||
hash, _ := t1.HashWithCount()
|
hash, _ := t1.HashWithCount()
|
||||||
|
|
||||||
// Load a tree
|
// Load a tree
|
||||||
t2 := NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 0, db)
|
t2 := NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 0, db)
|
||||||
t2.Load(hash)
|
t2.Load(hash)
|
||||||
for key, value := range records {
|
for key, value := range records {
|
||||||
_, t2value := t2.Get(key)
|
_, t2value := t2.Get(key)
|
||||||
|
@ -245,15 +245,15 @@ func testProof(t *testing.T, proof *IAVLProof, keyBytes, valueBytes, rootHash []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Write/Read then verify.
|
// Write/Read then verify.
|
||||||
proofBytes := binary.BinaryBytes(proof)
|
proofBytes := wire.BinaryBytes(proof)
|
||||||
n, err := int64(0), error(nil)
|
n, err := int64(0), error(nil)
|
||||||
proof2 := binary.ReadBinary(&IAVLProof{}, bytes.NewBuffer(proofBytes), &n, &err).(*IAVLProof)
|
proof2 := wire.ReadBinary(&IAVLProof{}, bytes.NewBuffer(proofBytes), &n, &err).(*IAVLProof)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to read IAVLProof from bytes: %v", err)
|
t.Errorf("Failed to read IAVLProof from bytes: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !proof2.Verify(keyBytes, valueBytes, rootHash) {
|
if !proof2.Verify(keyBytes, valueBytes, rootHash) {
|
||||||
// t.Log(Fmt("%X\n%X\n", proofBytes, binary.BinaryBytes(proof2)))
|
// t.Log(Fmt("%X\n%X\n", proofBytes, wire.BinaryBytes(proof2)))
|
||||||
t.Errorf("Invalid proof after write/read. Verification failed.")
|
t.Errorf("Invalid proof after write/read. Verification failed.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ func testProof(t *testing.T, proof *IAVLProof, keyBytes, valueBytes, rootHash []
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
badProofBytes := MutateByteSlice(proofBytes)
|
badProofBytes := MutateByteSlice(proofBytes)
|
||||||
n, err := int64(0), error(nil)
|
n, err := int64(0), error(nil)
|
||||||
badProof := binary.ReadBinary(&IAVLProof{}, bytes.NewBuffer(badProofBytes), &n, &err).(*IAVLProof)
|
badProof := wire.ReadBinary(&IAVLProof{}, bytes.NewBuffer(badProofBytes), &n, &err).(*IAVLProof)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue // This is fine.
|
continue // This is fine.
|
||||||
}
|
}
|
||||||
|
@ -273,10 +273,10 @@ func testProof(t *testing.T, proof *IAVLProof, keyBytes, valueBytes, rootHash []
|
||||||
|
|
||||||
func TestIAVLProof(t *testing.T) {
|
func TestIAVLProof(t *testing.T) {
|
||||||
|
|
||||||
// Convenient wrapper around binary.BasicCodec.
|
// Convenient wrapper around wire.BasicCodec.
|
||||||
toBytes := func(o interface{}) []byte {
|
toBytes := func(o interface{}) []byte {
|
||||||
buf, n, err := new(bytes.Buffer), int64(0), error(nil)
|
buf, n, err := new(bytes.Buffer), int64(0), error(nil)
|
||||||
binary.BasicCodec.Encode(o, buf, &n, &err)
|
wire.BasicCodec.Encode(o, buf, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(Fmt("Failed to encode thing: %v", err))
|
panic(Fmt("Failed to encode thing: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ func TestIAVLProof(t *testing.T) {
|
||||||
|
|
||||||
// Construct some random tree
|
// Construct some random tree
|
||||||
db := db.NewMemDB()
|
db := db.NewMemDB()
|
||||||
var tree *IAVLTree = NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 100, db)
|
var tree *IAVLTree = NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 100, db)
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
key, value := randstr(20), randstr(20)
|
key, value := randstr(20), randstr(20)
|
||||||
tree.Set(key, value)
|
tree.Set(key, value)
|
||||||
|
@ -315,7 +315,7 @@ func TestIAVLProof(t *testing.T) {
|
||||||
func BenchmarkImmutableAvlTree(b *testing.B) {
|
func BenchmarkImmutableAvlTree(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
|
|
||||||
t := NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 0, nil)
|
t := NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 0, nil)
|
||||||
// 23000ns/op, 43000ops/s
|
// 23000ns/op, 43000ops/s
|
||||||
// for i := 0; i < 10000000; i++ {
|
// for i := 0; i < 10000000; i++ {
|
||||||
for i := 0; i < 1000000; i++ {
|
for i := 0; i < 1000000; i++ {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
dbm "github.com/tendermint/tendermint/db"
|
dbm "github.com/tendermint/tendermint/db"
|
||||||
)
|
)
|
||||||
|
@ -15,13 +15,13 @@ Immutable AVL Tree (wraps the Node root)
|
||||||
This tree is not goroutine safe.
|
This tree is not goroutine safe.
|
||||||
*/
|
*/
|
||||||
type IAVLTree struct {
|
type IAVLTree struct {
|
||||||
keyCodec binary.Codec
|
keyCodec wire.Codec
|
||||||
valueCodec binary.Codec
|
valueCodec wire.Codec
|
||||||
root *IAVLNode
|
root *IAVLNode
|
||||||
ndb *nodeDB
|
ndb *nodeDB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIAVLTree(keyCodec, valueCodec binary.Codec, cacheSize int, db dbm.DB) *IAVLTree {
|
func NewIAVLTree(keyCodec, valueCodec wire.Codec, cacheSize int, db dbm.DB) *IAVLTree {
|
||||||
if db == nil {
|
if db == nil {
|
||||||
// In-memory IAVLTree
|
// In-memory IAVLTree
|
||||||
return &IAVLTree{
|
return &IAVLTree{
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ func SimpleHashFromTwoHashes(left []byte, right []byte) []byte {
|
||||||
var n int64
|
var n int64
|
||||||
var err error
|
var err error
|
||||||
var hasher = ripemd160.New()
|
var hasher = ripemd160.New()
|
||||||
binary.WriteByteSlice(left, hasher, &n, &err)
|
wire.WriteByteSlice(left, hasher, &n, &err)
|
||||||
binary.WriteByteSlice(right, hasher, &n, &err)
|
wire.WriteByteSlice(right, hasher, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func SimpleHashFromBinaries(items []interface{}) []byte {
|
||||||
// General Convenience
|
// General Convenience
|
||||||
func SimpleHashFromBinary(item interface{}) []byte {
|
func SimpleHashFromBinary(item interface{}) []byte {
|
||||||
hasher, n, err := ripemd160.New(), new(int64), new(error)
|
hasher, n, err := ripemd160.New(), new(int64), new(error)
|
||||||
binary.WriteBinary(item, hasher, n, err)
|
wire.WriteBinary(item, hasher, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
PanicCrisis(err)
|
PanicCrisis(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
bc "github.com/tendermint/tendermint/blockchain"
|
bc "github.com/tendermint/tendermint/blockchain"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/consensus"
|
"github.com/tendermint/tendermint/consensus"
|
||||||
|
@ -56,7 +56,7 @@ func NewNode() *Node {
|
||||||
state.Save()
|
state.Save()
|
||||||
// write the gendoc to db
|
// write the gendoc to db
|
||||||
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
binary.WriteJSON(genDoc, buf, n, err)
|
wire.WriteJSON(genDoc, buf, n, err)
|
||||||
stateDB.Set(sm.GenDocKey, buf.Bytes())
|
stateDB.Set(sm.GenDocKey, buf.Bytes())
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
log.Error("Unable to write gendoc to db", "error", err)
|
log.Error("Unable to write gendoc to db", "error", err)
|
||||||
|
@ -65,7 +65,7 @@ func NewNode() *Node {
|
||||||
} else {
|
} else {
|
||||||
genDocBytes := stateDB.Get(sm.GenDocKey)
|
genDocBytes := stateDB.Get(sm.GenDocKey)
|
||||||
err := new(error)
|
err := new(error)
|
||||||
binary.ReadJSONPtr(&genDoc, genDocBytes, err)
|
wire.ReadJSONPtr(&genDoc, genDocBytes, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
log.Error("Unable to read gendoc from db", "error", err)
|
log.Error("Unable to read gendoc from db", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -22,7 +22,7 @@ func (m MConnection) TrySend(chId byte, msg interface{}) bool {}
|
||||||
|
|
||||||
`Send(chId, msg)` is a blocking call that waits until `msg` is successfully queued
|
`Send(chId, msg)` is a blocking call that waits until `msg` is successfully queued
|
||||||
for the channel with the given id byte `chId`. The message `msg` is serialized
|
for the channel with the given id byte `chId`. The message `msg` is serialized
|
||||||
using the `tendermint/binary` submodule's `WriteBinary()` reflection routine.
|
using the `tendermint/wire` submodule's `WriteBinary()` reflection routine.
|
||||||
|
|
||||||
`TrySend(chId, msg)` is a nonblocking call that returns false if the channel's
|
`TrySend(chId, msg)` is a nonblocking call that returns false if the channel's
|
||||||
queue is full.
|
queue is full.
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
flow "github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/mxk/go1/flowcontrol"
|
flow "github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/mxk/go1/flowcontrol"
|
||||||
"github.com/tendermint/tendermint/binary" //"github.com/tendermint/log15"
|
"github.com/tendermint/tendermint/wire" //"github.com/tendermint/log15"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ There are two methods for sending messages:
|
||||||
|
|
||||||
`Send(chId, msg)` is a blocking call that waits until `msg` is successfully queued
|
`Send(chId, msg)` is a blocking call that waits until `msg` is successfully queued
|
||||||
for the channel with the given id byte `chId`, or until the request times out.
|
for the channel with the given id byte `chId`, or until the request times out.
|
||||||
The message `msg` is serialized using the `tendermint/binary` submodule's
|
The message `msg` is serialized using the `tendermint/wire` submodule's
|
||||||
`WriteBinary()` reflection routine.
|
`WriteBinary()` reflection routine.
|
||||||
|
|
||||||
`TrySend(chId, msg)` is a nonblocking call that returns false if the channel's
|
`TrySend(chId, msg)` is a nonblocking call that returns false if the channel's
|
||||||
|
@ -189,7 +189,7 @@ func (c *MConnection) Send(chId byte, msg interface{}) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Send", "channel", chId, "conn", c, "msg", msg) //, "bytes", binary.BinaryBytes(msg))
|
log.Info("Send", "channel", chId, "conn", c, "msg", msg) //, "bytes", wire.BinaryBytes(msg))
|
||||||
|
|
||||||
// Send message to channel.
|
// Send message to channel.
|
||||||
channel, ok := c.channelsIdx[chId]
|
channel, ok := c.channelsIdx[chId]
|
||||||
|
@ -198,7 +198,7 @@ func (c *MConnection) Send(chId byte, msg interface{}) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
success := channel.sendBytes(binary.BinaryBytes(msg))
|
success := channel.sendBytes(wire.BinaryBytes(msg))
|
||||||
if success {
|
if success {
|
||||||
// Wake up sendRoutine if necessary
|
// Wake up sendRoutine if necessary
|
||||||
select {
|
select {
|
||||||
|
@ -227,7 +227,7 @@ func (c *MConnection) TrySend(chId byte, msg interface{}) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = channel.trySendBytes(binary.BinaryBytes(msg))
|
ok = channel.trySendBytes(wire.BinaryBytes(msg))
|
||||||
if ok {
|
if ok {
|
||||||
// Wake up sendRoutine if necessary
|
// Wake up sendRoutine if necessary
|
||||||
select {
|
select {
|
||||||
|
@ -271,12 +271,12 @@ FOR_LOOP:
|
||||||
}
|
}
|
||||||
case <-c.pingTimer.Ch:
|
case <-c.pingTimer.Ch:
|
||||||
log.Info("Send Ping")
|
log.Info("Send Ping")
|
||||||
binary.WriteByte(packetTypePing, c.bufWriter, &n, &err)
|
wire.WriteByte(packetTypePing, c.bufWriter, &n, &err)
|
||||||
c.sendMonitor.Update(int(n))
|
c.sendMonitor.Update(int(n))
|
||||||
c.flush()
|
c.flush()
|
||||||
case <-c.pong:
|
case <-c.pong:
|
||||||
log.Info("Send Pong")
|
log.Info("Send Pong")
|
||||||
binary.WriteByte(packetTypePong, c.bufWriter, &n, &err)
|
wire.WriteByte(packetTypePong, c.bufWriter, &n, &err)
|
||||||
c.sendMonitor.Update(int(n))
|
c.sendMonitor.Update(int(n))
|
||||||
c.flush()
|
c.flush()
|
||||||
case <-c.quit:
|
case <-c.quit:
|
||||||
|
@ -390,7 +390,7 @@ FOR_LOOP:
|
||||||
// Read packet type
|
// Read packet type
|
||||||
var n int64
|
var n int64
|
||||||
var err error
|
var err error
|
||||||
pktType := binary.ReadByte(c.bufReader, &n, &err)
|
pktType := wire.ReadByte(c.bufReader, &n, &err)
|
||||||
c.recvMonitor.Update(int(n))
|
c.recvMonitor.Update(int(n))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if c.IsRunning() {
|
if c.IsRunning() {
|
||||||
|
@ -411,7 +411,7 @@ FOR_LOOP:
|
||||||
log.Info("Receive Pong")
|
log.Info("Receive Pong")
|
||||||
case packetTypeMsg:
|
case packetTypeMsg:
|
||||||
pkt, n, err := msgPacket{}, int64(0), error(nil)
|
pkt, n, err := msgPacket{}, int64(0), error(nil)
|
||||||
binary.ReadBinaryPtr(&pkt, c.bufReader, &n, &err)
|
wire.ReadBinaryPtr(&pkt, c.bufReader, &n, &err)
|
||||||
c.recvMonitor.Update(int(n))
|
c.recvMonitor.Update(int(n))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if c.IsRunning() {
|
if c.IsRunning() {
|
||||||
|
@ -573,8 +573,8 @@ func (ch *Channel) nextMsgPacket() msgPacket {
|
||||||
func (ch *Channel) writeMsgPacketTo(w io.Writer) (n int64, err error) {
|
func (ch *Channel) writeMsgPacketTo(w io.Writer) (n int64, err error) {
|
||||||
packet := ch.nextMsgPacket()
|
packet := ch.nextMsgPacket()
|
||||||
log.Debug("Write Msg Packet", "conn", ch.conn, "packet", packet)
|
log.Debug("Write Msg Packet", "conn", ch.conn, "packet", packet)
|
||||||
binary.WriteByte(packetTypeMsg, w, &n, &err)
|
wire.WriteByte(packetTypeMsg, w, &n, &err)
|
||||||
binary.WriteBinary(packet, w, &n, &err)
|
wire.WriteBinary(packet, w, &n, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ch.recentlySent += n
|
ch.recentlySent += n
|
||||||
}
|
}
|
||||||
|
@ -585,8 +585,8 @@ func (ch *Channel) writeMsgPacketTo(w io.Writer) (n int64, err error) {
|
||||||
// Not goroutine-safe
|
// Not goroutine-safe
|
||||||
func (ch *Channel) recvMsgPacket(packet msgPacket) ([]byte, error) {
|
func (ch *Channel) recvMsgPacket(packet msgPacket) ([]byte, error) {
|
||||||
log.Debug("Read Msg Packet", "conn", ch.conn, "packet", packet)
|
log.Debug("Read Msg Packet", "conn", ch.conn, "packet", packet)
|
||||||
if binary.MaxBinaryReadSize < len(ch.recving)+len(packet.Bytes) {
|
if wire.MaxBinaryReadSize < len(ch.recving)+len(packet.Bytes) {
|
||||||
return nil, binary.ErrBinaryReadSizeOverflow
|
return nil, wire.ErrBinaryReadSizeOverflow
|
||||||
}
|
}
|
||||||
ch.recving = append(ch.recving, packet.Bytes...)
|
ch.recving = append(ch.recving, packet.Bytes...)
|
||||||
if packet.EOF == byte(0x01) {
|
if packet.EOF == byte(0x01) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
@ -30,11 +30,11 @@ func peerHandshake(conn net.Conn, ourNodeInfo *types.NodeInfo) (*types.NodeInfo,
|
||||||
Parallel(
|
Parallel(
|
||||||
func() {
|
func() {
|
||||||
var n int64
|
var n int64
|
||||||
binary.WriteBinary(ourNodeInfo, conn, &n, &err1)
|
wire.WriteBinary(ourNodeInfo, conn, &n, &err1)
|
||||||
},
|
},
|
||||||
func() {
|
func() {
|
||||||
var n int64
|
var n int64
|
||||||
binary.ReadBinary(peerNodeInfo, conn, &n, &err2)
|
wire.ReadBinary(peerNodeInfo, conn, &n, &err2)
|
||||||
log.Notice("Peer handshake", "peerNodeInfo", peerNodeInfo)
|
log.Notice("Peer handshake", "peerNodeInfo", peerNodeInfo)
|
||||||
})
|
})
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
|
@ -112,7 +112,7 @@ func (p *Peer) CanSend(chId byte) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Peer) WriteTo(w io.Writer) (n int64, err error) {
|
func (p *Peer) WriteTo(w io.Writer) (n int64, err error) {
|
||||||
binary.WriteString(p.Key, w, &n, &err)
|
wire.WriteString(p.Key, w, &n, &err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/events"
|
"github.com/tendermint/tendermint/events"
|
||||||
)
|
)
|
||||||
|
@ -225,17 +225,17 @@ const (
|
||||||
|
|
||||||
type PexMessage interface{}
|
type PexMessage interface{}
|
||||||
|
|
||||||
var _ = binary.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ PexMessage }{},
|
struct{ PexMessage }{},
|
||||||
binary.ConcreteType{&pexRequestMessage{}, msgTypeRequest},
|
wire.ConcreteType{&pexRequestMessage{}, msgTypeRequest},
|
||||||
binary.ConcreteType{&pexAddrsMessage{}, msgTypeAddrs},
|
wire.ConcreteType{&pexAddrsMessage{}, msgTypeAddrs},
|
||||||
)
|
)
|
||||||
|
|
||||||
func DecodeMessage(bz []byte) (msgType byte, msg PexMessage, err error) {
|
func DecodeMessage(bz []byte) (msgType byte, msg PexMessage, err error) {
|
||||||
msgType = bz[0]
|
msgType = bz[0]
|
||||||
n := new(int64)
|
n := new(int64)
|
||||||
r := bytes.NewReader(bz)
|
r := bytes.NewReader(bz)
|
||||||
msg = binary.ReadBinary(struct{ PexMessage }{}, r, n, &err).(struct{ PexMessage }).PexMessage
|
msg = wire.ReadBinary(struct{ PexMessage }{}, r, n, &err).(struct{ PexMessage }).PexMessage
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ import (
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/golang.org/x/crypto/ripemd160"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/golang.org/x/crypto/ripemd160"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
bm "github.com/tendermint/tendermint/binary"
|
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
"github.com/tendermint/tendermint/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 2 + 1024 == 1026 total frame size
|
// 2 + 1024 == 1026 total frame size
|
||||||
|
@ -270,7 +270,7 @@ func shareAuthSignature(sc *SecretConnection, pubKey acm.PubKeyEd25519, signatur
|
||||||
|
|
||||||
Parallel(
|
Parallel(
|
||||||
func() {
|
func() {
|
||||||
msgBytes := bm.BinaryBytes(authSigMessage{pubKey, signature})
|
msgBytes := wire.BinaryBytes(authSigMessage{pubKey, signature})
|
||||||
_, err1 = sc.Write(msgBytes)
|
_, err1 = sc.Write(msgBytes)
|
||||||
},
|
},
|
||||||
func() {
|
func() {
|
||||||
|
@ -280,7 +280,7 @@ func shareAuthSignature(sc *SecretConnection, pubKey acm.PubKeyEd25519, signatur
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n := int64(0) // not used.
|
n := int64(0) // not used.
|
||||||
recvMsg = bm.ReadBinary(authSigMessage{}, bytes.NewBuffer(readBuffer), &n, &err2).(authSigMessage)
|
recvMsg = wire.ReadBinary(authSigMessage{}, bytes.NewBuffer(readBuffer), &n, &err2).(authSigMessage)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
@ -164,8 +164,8 @@ func TestSwitches(t *testing.T) {
|
||||||
if len(ch0Msgs) != 1 {
|
if len(ch0Msgs) != 1 {
|
||||||
t.Errorf("Expected to have received 1 message in ch0")
|
t.Errorf("Expected to have received 1 message in ch0")
|
||||||
}
|
}
|
||||||
if !bytes.Equal(ch0Msgs[0].Bytes, binary.BinaryBytes(ch0Msg)) {
|
if !bytes.Equal(ch0Msgs[0].Bytes, wire.BinaryBytes(ch0Msg)) {
|
||||||
t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", binary.BinaryBytes(ch0Msg), ch0Msgs[0].Bytes)
|
t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", wire.BinaryBytes(ch0Msg), ch0Msgs[0].Bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check message on ch1
|
// Check message on ch1
|
||||||
|
@ -173,8 +173,8 @@ func TestSwitches(t *testing.T) {
|
||||||
if len(ch1Msgs) != 1 {
|
if len(ch1Msgs) != 1 {
|
||||||
t.Errorf("Expected to have received 1 message in ch1")
|
t.Errorf("Expected to have received 1 message in ch1")
|
||||||
}
|
}
|
||||||
if !bytes.Equal(ch1Msgs[0].Bytes, binary.BinaryBytes(ch1Msg)) {
|
if !bytes.Equal(ch1Msgs[0].Bytes, wire.BinaryBytes(ch1Msg)) {
|
||||||
t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", binary.BinaryBytes(ch1Msg), ch1Msgs[0].Bytes)
|
t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", wire.BinaryBytes(ch1Msg), ch1Msgs[0].Bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check message on ch2
|
// Check message on ch2
|
||||||
|
@ -182,8 +182,8 @@ func TestSwitches(t *testing.T) {
|
||||||
if len(ch2Msgs) != 1 {
|
if len(ch2Msgs) != 1 {
|
||||||
t.Errorf("Expected to have received 1 message in ch2")
|
t.Errorf("Expected to have received 1 message in ch2")
|
||||||
}
|
}
|
||||||
if !bytes.Equal(ch2Msgs[0].Bytes, binary.BinaryBytes(ch2Msg)) {
|
if !bytes.Equal(ch2Msgs[0].Bytes, wire.BinaryBytes(ch2Msg)) {
|
||||||
t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", binary.BinaryBytes(ch2Msg), ch2Msgs[0].Bytes)
|
t.Errorf("Unexpected message bytes. Wanted: %X, Got: %X", wire.BinaryBytes(ch2Msg), ch2Msgs[0].Bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
@ -25,16 +25,16 @@ const (
|
||||||
PermArgsTypeRmRole = byte(0x07)
|
PermArgsTypeRmRole = byte(0x07)
|
||||||
)
|
)
|
||||||
|
|
||||||
// for binary.readReflect
|
// for wire.readReflect
|
||||||
var _ = binary.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ PermArgs }{},
|
struct{ PermArgs }{},
|
||||||
binary.ConcreteType{&HasBaseArgs{}, PermArgsTypeHasBase},
|
wire.ConcreteType{&HasBaseArgs{}, PermArgsTypeHasBase},
|
||||||
binary.ConcreteType{&SetBaseArgs{}, PermArgsTypeSetBase},
|
wire.ConcreteType{&SetBaseArgs{}, PermArgsTypeSetBase},
|
||||||
binary.ConcreteType{&UnsetBaseArgs{}, PermArgsTypeUnsetBase},
|
wire.ConcreteType{&UnsetBaseArgs{}, PermArgsTypeUnsetBase},
|
||||||
binary.ConcreteType{&SetGlobalArgs{}, PermArgsTypeSetGlobal},
|
wire.ConcreteType{&SetGlobalArgs{}, PermArgsTypeSetGlobal},
|
||||||
binary.ConcreteType{&HasRoleArgs{}, PermArgsTypeHasRole},
|
wire.ConcreteType{&HasRoleArgs{}, PermArgsTypeHasRole},
|
||||||
binary.ConcreteType{&AddRoleArgs{}, PermArgsTypeAddRole},
|
wire.ConcreteType{&AddRoleArgs{}, PermArgsTypeAddRole},
|
||||||
binary.ConcreteType{&RmRoleArgs{}, PermArgsTypeRmRole},
|
wire.ConcreteType{&RmRoleArgs{}, PermArgsTypeRmRole},
|
||||||
)
|
)
|
||||||
|
|
||||||
type HasBaseArgs struct {
|
type HasBaseArgs struct {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
. "github.com/tendermint/tendermint/rpc/types"
|
. "github.com/tendermint/tendermint/rpc/types"
|
||||||
)
|
)
|
||||||
|
@ -20,7 +20,7 @@ func Call(remote string, method string, params []interface{}, dest interface{})
|
||||||
Params: params,
|
Params: params,
|
||||||
Id: "",
|
Id: "",
|
||||||
}
|
}
|
||||||
requestBytes := binary.JSONBytes(request)
|
requestBytes := wire.JSONBytes(request)
|
||||||
requestBuf := bytes.NewBuffer(requestBytes)
|
requestBuf := bytes.NewBuffer(requestBytes)
|
||||||
log.Info(Fmt("RPC request to %v: %v", remote, string(requestBytes)))
|
log.Info(Fmt("RPC request to %v: %v", remote, string(requestBytes)))
|
||||||
httpResponse, err := http.Post(remote, "text/json", requestBuf)
|
httpResponse, err := http.Post(remote, "text/json", requestBuf)
|
||||||
|
@ -46,6 +46,6 @@ func Call(remote string, method string, params []interface{}, dest interface{})
|
||||||
if errorStr != "" {
|
if errorStr != "" {
|
||||||
return dest, errors.New(errorStr)
|
return dest, errors.New(errorStr)
|
||||||
}
|
}
|
||||||
dest = binary.ReadJSONObject(dest, resultJSONObject, &err)
|
dest = wire.ReadJSONObject(dest, resultJSONObject, &err)
|
||||||
return dest, err
|
return dest, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
cm "github.com/tendermint/tendermint/consensus"
|
cm "github.com/tendermint/tendermint/consensus"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
|
@ -33,7 +33,7 @@ func DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) {
|
||||||
// TODO: clean this up?
|
// TODO: clean this up?
|
||||||
peerState := peer.Data.Get(cm.PeerStateKey).(*cm.PeerState)
|
peerState := peer.Data.Get(cm.PeerStateKey).(*cm.PeerState)
|
||||||
peerRoundState := peerState.GetRoundState()
|
peerRoundState := peerState.GetRoundState()
|
||||||
peerRoundStateStr := peer.Key + ":" + string(binary.JSONBytes(peerRoundState))
|
peerRoundStateStr := peer.Key + ":" + string(wire.JSONBytes(peerRoundState))
|
||||||
peerRoundStates = append(peerRoundStates, peerRoundStateStr)
|
peerRoundStates = append(peerRoundStates, peerRoundStateStr)
|
||||||
}
|
}
|
||||||
return &ctypes.ResponseDumpConsensusState{roundState.String(), peerRoundStates}, nil
|
return &ctypes.ResponseDumpConsensusState{roundState.String(), peerRoundStates}, nil
|
||||||
|
|
|
@ -39,11 +39,11 @@ func Call(fromAddress, toAddress, data []byte) (*ctypes.ResponseCall, error) {
|
||||||
BlockHeight: int64(st.LastBlockHeight),
|
BlockHeight: int64(st.LastBlockHeight),
|
||||||
BlockHash: LeftPadWord256(st.LastBlockHash),
|
BlockHash: LeftPadWord256(st.LastBlockHash),
|
||||||
BlockTime: st.LastBlockTime.Unix(),
|
BlockTime: st.LastBlockTime.Unix(),
|
||||||
GasLimit: 10000000,
|
GasLimit: st.GetGasLimit(),
|
||||||
}
|
}
|
||||||
|
|
||||||
vmach := vm.NewVM(txCache, params, caller.Address, nil)
|
vmach := vm.NewVM(txCache, params, caller.Address, nil)
|
||||||
gas := int64(1000000000)
|
gas := st.GetGasLimit()
|
||||||
ret, err := vmach.Call(caller, callee, callee.Code, data, 0, &gas)
|
ret, err := vmach.Call(caller, callee, callee.Code, data, 0, &gas)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -64,11 +64,11 @@ func CallCode(fromAddress, code, data []byte) (*ctypes.ResponseCall, error) {
|
||||||
BlockHeight: int64(st.LastBlockHeight),
|
BlockHeight: int64(st.LastBlockHeight),
|
||||||
BlockHash: LeftPadWord256(st.LastBlockHash),
|
BlockHash: LeftPadWord256(st.LastBlockHash),
|
||||||
BlockTime: st.LastBlockTime.Unix(),
|
BlockTime: st.LastBlockTime.Unix(),
|
||||||
GasLimit: 10000000,
|
GasLimit: st.GetGasLimit(),
|
||||||
}
|
}
|
||||||
|
|
||||||
vmach := vm.NewVM(txCache, params, caller.Address, nil)
|
vmach := vm.NewVM(txCache, params, caller.Address, nil)
|
||||||
gas := int64(1000000000)
|
gas := st.GetGasLimit()
|
||||||
ret, err := vmach.Call(caller, callee, code, data, 0, &gas)
|
ret, err := vmach.Call(caller, callee, code, data, 0, &gas)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -3,7 +3,7 @@ package core_client
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
rpctypes "github.com/tendermint/tendermint/rpc/types"
|
rpctypes "github.com/tendermint/tendermint/rpc/types"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -85,7 +85,7 @@ func argsToJson(args ...interface{}) ([]string, error) {
|
||||||
n, err := new(int64), new(error)
|
n, err := new(int64), new(error)
|
||||||
for i, a := range args {
|
for i, a := range args {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
binary.WriteJSON(a, buf, n, err)
|
wire.WriteJSON(a, buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
return nil, *err
|
return nil, *err
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ func argsToJson(args ...interface{}) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) RequestResponse(s rpctypes.RPCRequest) (b []byte, err error) {
|
func (c *ClientJSON) RequestResponse(s rpctypes.RPCRequest) (b []byte, err error) {
|
||||||
b = binary.JSONBytes(s)
|
b = wire.JSONBytes(s)
|
||||||
buf := bytes.NewBuffer(b)
|
buf := bytes.NewBuffer(b)
|
||||||
resp, err := http.Post(c.addr, "text/json", buf)
|
resp, err := http.Post(c.addr, "text/json", buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -124,7 +124,7 @@ func binaryWriter(args ...interface{}) ([]interface{}, error) {
|
||||||
list := []interface{}{}
|
list := []interface{}{}
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
binary.WriteJSON(a, buf, n, err)
|
wire.WriteJSON(a, buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
return nil, *err
|
return nil, *err
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ func argsToURLValues(argNames []string, args ...interface{}) (url.Values, error)
|
||||||
// import statements we will need for the templates
|
// import statements we will need for the templates
|
||||||
|
|
||||||
/*rpc-gen:imports:
|
/*rpc-gen:imports:
|
||||||
github.com/tendermint/tendermint/binary
|
github.com/tendermint/tendermint/wire
|
||||||
rpctypes github.com/tendermint/tendermint/rpc/types
|
rpctypes github.com/tendermint/tendermint/rpc/types
|
||||||
net/http
|
net/http
|
||||||
io/ioutil
|
io/ioutil
|
||||||
|
@ -185,7 +185,7 @@ fmt
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ fmt
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ package core_client
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
rpctypes "github.com/tendermint/tendermint/rpc/types"
|
rpctypes "github.com/tendermint/tendermint/rpc/types"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
|
@ -56,7 +56,7 @@ func (c *ClientHTTP) BlockchainInfo(minHeight int, maxHeight int) (*ctypes.Respo
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ func (c *ClientHTTP) BroadcastTx(tx types.Tx) (*ctypes.Receipt, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ func (c *ClientHTTP) Call(fromAddress []byte, toAddress []byte, data []byte) (*c
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ func (c *ClientHTTP) CallCode(fromAddress []byte, code []byte, data []byte) (*ct
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ func (c *ClientHTTP) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, e
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ func (c *ClientHTTP) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ func (c *ClientHTTP) GenPrivAccount() (*acm.PrivAccount, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -266,7 +266,7 @@ func (c *ClientHTTP) Genesis() (*sm.GenesisDoc, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -296,7 +296,7 @@ func (c *ClientHTTP) GetAccount(address []byte) (*acm.Account, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ func (c *ClientHTTP) GetBlock(height int) (*ctypes.ResponseGetBlock, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ func (c *ClientHTTP) GetName(name string) (*types.NameRegEntry, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ func (c *ClientHTTP) GetStorage(address []byte, key []byte) (*ctypes.ResponseGet
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -416,7 +416,7 @@ func (c *ClientHTTP) ListAccounts() (*ctypes.ResponseListAccounts, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -446,7 +446,7 @@ func (c *ClientHTTP) ListNames() (*ctypes.ResponseListNames, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -476,7 +476,7 @@ func (c *ClientHTTP) ListUnconfirmedTxs() ([]types.Tx, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -506,7 +506,7 @@ func (c *ClientHTTP) ListValidators() (*ctypes.ResponseListValidators, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -536,7 +536,7 @@ func (c *ClientHTTP) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -566,7 +566,7 @@ func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -596,7 +596,7 @@ func (c *ClientHTTP) Status() (*ctypes.ResponseStatus, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -623,7 +623,7 @@ func (c *ClientJSON) BlockchainInfo(minHeight int, maxHeight int) (*ctypes.Respo
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -650,7 +650,7 @@ func (c *ClientJSON) BroadcastTx(tx types.Tx) (*ctypes.Receipt, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -677,7 +677,7 @@ func (c *ClientJSON) Call(fromAddress []byte, toAddress []byte, data []byte) (*c
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -704,7 +704,7 @@ func (c *ClientJSON) CallCode(fromAddress []byte, code []byte, data []byte) (*ct
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -731,7 +731,7 @@ func (c *ClientJSON) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, e
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -758,7 +758,7 @@ func (c *ClientJSON) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -785,7 +785,7 @@ func (c *ClientJSON) GenPrivAccount() (*acm.PrivAccount, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -812,7 +812,7 @@ func (c *ClientJSON) Genesis() (*sm.GenesisDoc, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -839,7 +839,7 @@ func (c *ClientJSON) GetAccount(address []byte) (*acm.Account, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -866,7 +866,7 @@ func (c *ClientJSON) GetBlock(height int) (*ctypes.ResponseGetBlock, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -893,7 +893,7 @@ func (c *ClientJSON) GetName(name string) (*types.NameRegEntry, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -920,7 +920,7 @@ func (c *ClientJSON) GetStorage(address []byte, key []byte) (*ctypes.ResponseGet
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -947,7 +947,7 @@ func (c *ClientJSON) ListAccounts() (*ctypes.ResponseListAccounts, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -974,7 +974,7 @@ func (c *ClientJSON) ListNames() (*ctypes.ResponseListNames, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1001,7 +1001,7 @@ func (c *ClientJSON) ListUnconfirmedTxs() ([]types.Tx, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1028,7 +1028,7 @@ func (c *ClientJSON) ListValidators() (*ctypes.ResponseListValidators, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1055,7 +1055,7 @@ func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1082,7 +1082,7 @@ func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*acm.PrivAccount) (types
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1109,7 +1109,7 @@ func (c *ClientJSON) Status() (*ctypes.ResponseStatus, error) {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
}
|
}
|
||||||
binary.ReadJSON(&response, body, &err)
|
wire.ReadJSON(&response, body, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/events"
|
"github.com/tendermint/tendermint/events"
|
||||||
. "github.com/tendermint/tendermint/rpc/types"
|
. "github.com/tendermint/tendermint/rpc/types"
|
||||||
|
@ -138,7 +138,7 @@ func jsonParamsToArgs(rpcFunc *RPCFunc, params []interface{}) ([]reflect.Value,
|
||||||
func _jsonObjectToArg(ty reflect.Type, object interface{}) (reflect.Value, error) {
|
func _jsonObjectToArg(ty reflect.Type, object interface{}) (reflect.Value, error) {
|
||||||
var err error
|
var err error
|
||||||
v := reflect.New(ty)
|
v := reflect.New(ty)
|
||||||
binary.ReadJSONObjectPtr(v.Interface(), object, &err)
|
wire.ReadJSONObjectPtr(v.Interface(), object, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return v, err
|
return v, err
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ func httpParamsToArgs(rpcFunc *RPCFunc, r *http.Request) ([]reflect.Value, error
|
||||||
func _jsonStringToArg(ty reflect.Type, arg string) (reflect.Value, error) {
|
func _jsonStringToArg(ty reflect.Type, arg string) (reflect.Value, error) {
|
||||||
var err error
|
var err error
|
||||||
v := reflect.New(ty)
|
v := reflect.New(ty)
|
||||||
binary.ReadJSONPtr(v.Interface(), []byte(arg), &err)
|
wire.ReadJSONPtr(v.Interface(), []byte(arg), &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return v, err
|
return v, err
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,7 @@ func (wsc *WSConnection) writeRoutine() {
|
||||||
return
|
return
|
||||||
case msg := <-wsc.writeChan:
|
case msg := <-wsc.writeChan:
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
binary.WriteJSON(msg, buf, n, err)
|
wire.WriteJSON(msg, buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
log.Error("Failed to marshal RPCResponse to JSON", "error", err)
|
log.Error("Failed to marshal RPCResponse to JSON", "error", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/alert"
|
"github.com/tendermint/tendermint/alert"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
. "github.com/tendermint/tendermint/rpc/types"
|
. "github.com/tendermint/tendermint/rpc/types"
|
||||||
)
|
)
|
||||||
|
@ -34,7 +34,7 @@ func StartHTTPServer(listenAddr string, handler http.Handler) (net.Listener, err
|
||||||
|
|
||||||
func WriteRPCResponse(w http.ResponseWriter, res RPCResponse) {
|
func WriteRPCResponse(w http.ResponseWriter, res RPCResponse) {
|
||||||
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
binary.WriteJSON(res, buf, n, err)
|
wire.WriteJSON(res, buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
log.Warn("Failed to write RPC response", "error", err)
|
log.Warn("Failed to write RPC response", "error", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
_ "github.com/tendermint/tendermint/config/tendermint_test"
|
_ "github.com/tendermint/tendermint/config/tendermint_test"
|
||||||
"github.com/tendermint/tendermint/rpc/server"
|
"github.com/tendermint/tendermint/rpc/server"
|
||||||
"github.com/tendermint/tendermint/rpc/types"
|
"github.com/tendermint/tendermint/rpc/types"
|
||||||
|
@ -149,7 +149,7 @@ func unmarshalResponseNewBlock(b []byte) (*types.Block, error) {
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
binary.ReadJSON(&response, b, &err)
|
wire.ReadJSON(&response, b, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ func unmarshalValidateSend(amt int64, toAddr []byte) func(string, []byte) error
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
binary.ReadJSON(&response, b, &err)
|
wire.ReadJSON(&response, b, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ func unmarshalValidateCall(amt int64, returnCode []byte) func(string, []byte) er
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
binary.ReadJSON(&response, b, &err)
|
wire.ReadJSON(&response, b, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ func unmarshalValidateCallCall(origin, returnCode []byte, txid *[]byte) func(str
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
binary.ReadJSON(&response, b, &err)
|
wire.ReadJSON(&response, b, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
dbm "github.com/tendermint/tendermint/db"
|
dbm "github.com/tendermint/tendermint/db"
|
||||||
"github.com/tendermint/tendermint/merkle"
|
"github.com/tendermint/tendermint/merkle"
|
||||||
|
@ -14,8 +14,8 @@ import (
|
||||||
|
|
||||||
func makeStorage(db dbm.DB, root []byte) merkle.Tree {
|
func makeStorage(db dbm.DB, root []byte) merkle.Tree {
|
||||||
storage := merkle.NewIAVLTree(
|
storage := merkle.NewIAVLTree(
|
||||||
binary.BasicCodec,
|
wire.BasicCodec,
|
||||||
binary.BasicCodec,
|
wire.BasicCodec,
|
||||||
1024,
|
1024,
|
||||||
db,
|
db,
|
||||||
)
|
)
|
||||||
|
|
|
@ -356,10 +356,10 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||||
return types.ErrTxInvalidAddress
|
return types.ErrTxInvalidAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
createAccount := len(tx.Address) == 0
|
createContract := len(tx.Address) == 0
|
||||||
if createAccount {
|
if createContract {
|
||||||
if !hasCreateContractPermission(blockCache, inAcc) {
|
if !hasCreateContractPermission(blockCache, inAcc) {
|
||||||
return fmt.Errorf("Account %X does not have Create permission", tx.Input.Address)
|
return fmt.Errorf("Account %X does not have CreateContract permission", tx.Input.Address)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !hasCallPermission(blockCache, inAcc) {
|
if !hasCallPermission(blockCache, inAcc) {
|
||||||
|
@ -383,13 +383,18 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||||
return types.ErrTxInsufficientFunds
|
return types.ErrTxInsufficientFunds
|
||||||
}
|
}
|
||||||
|
|
||||||
if !createAccount {
|
if !createContract {
|
||||||
// Validate output
|
// Validate output
|
||||||
if len(tx.Address) != 20 {
|
if len(tx.Address) != 20 {
|
||||||
log.Info(Fmt("Destination address is not 20 bytes %X", tx.Address))
|
log.Info(Fmt("Destination address is not 20 bytes %X", tx.Address))
|
||||||
return types.ErrTxInvalidAddress
|
return types.ErrTxInvalidAddress
|
||||||
}
|
}
|
||||||
// this may be nil if we are still in mempool and contract was created in same block as this tx
|
// check if its a native contract
|
||||||
|
if vm.RegisteredNativeContract(LeftPadWord256(tx.Address)) {
|
||||||
|
return fmt.Errorf("NativeContracts can not be called using CallTx. Use a contract or the appropriate tx type (eg. PermissionsTx, NameTx)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output account may be nil if we are still in mempool and contract was created in same block as this tx
|
||||||
// but that's fine, because the account will be created properly when the create tx runs in the block
|
// but that's fine, because the account will be created properly when the create tx runs in the block
|
||||||
// and then this won't return nil. otherwise, we take their fee
|
// and then this won't return nil. otherwise, we take their fee
|
||||||
outAcc = blockCache.GetAccount(tx.Address)
|
outAcc = blockCache.GetAccount(tx.Address)
|
||||||
|
@ -400,90 +405,101 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||||
// Good!
|
// Good!
|
||||||
value := tx.Input.Amount - tx.Fee
|
value := tx.Input.Amount - tx.Fee
|
||||||
inAcc.Sequence += 1
|
inAcc.Sequence += 1
|
||||||
|
inAcc.Balance -= tx.Fee
|
||||||
|
blockCache.UpdateAccount(inAcc)
|
||||||
|
|
||||||
|
// The logic in runCall MUST NOT return.
|
||||||
if runCall {
|
if runCall {
|
||||||
|
|
||||||
|
// VM call variables
|
||||||
var (
|
var (
|
||||||
gas int64 = tx.GasLimit
|
gas int64 = tx.GasLimit
|
||||||
err error = nil
|
err error = nil
|
||||||
caller *vm.Account = toVMAccount(inAcc)
|
caller *vm.Account = toVMAccount(inAcc)
|
||||||
callee *vm.Account = nil
|
callee *vm.Account = nil // initialized below
|
||||||
code []byte = nil
|
code []byte = nil
|
||||||
|
ret []byte = nil
|
||||||
txCache = NewTxCache(blockCache)
|
txCache = NewTxCache(blockCache)
|
||||||
params = vm.Params{
|
params = vm.Params{
|
||||||
BlockHeight: int64(_s.LastBlockHeight),
|
BlockHeight: int64(_s.LastBlockHeight),
|
||||||
BlockHash: LeftPadWord256(_s.LastBlockHash),
|
BlockHash: LeftPadWord256(_s.LastBlockHash),
|
||||||
BlockTime: _s.LastBlockTime.Unix(),
|
BlockTime: _s.LastBlockTime.Unix(),
|
||||||
GasLimit: 10000000,
|
GasLimit: _s.GetGasLimit(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// get or create callee
|
if !createContract && (outAcc == nil || len(outAcc.Code) == 0) {
|
||||||
if !createAccount {
|
|
||||||
|
|
||||||
if outAcc == nil || len(outAcc.Code) == 0 {
|
|
||||||
// check if its a native contract
|
|
||||||
if vm.RegisteredNativeContract(LeftPadWord256(tx.Address)) {
|
|
||||||
return fmt.Errorf("NativeContracts can not be called using CallTx. Use a contract or the appropriate tx type (eg. PermissionsTx, NameTx)")
|
|
||||||
}
|
|
||||||
|
|
||||||
// if you call an account that doesn't exist
|
// if you call an account that doesn't exist
|
||||||
// or an account with no code then we take fees (sorry pal)
|
// or an account with no code then we take fees (sorry pal)
|
||||||
// NOTE: it's fine to create a contract and call it within one
|
// NOTE: it's fine to create a contract and call it within one
|
||||||
// block (nonce will prevent re-ordering of those txs)
|
// block (nonce will prevent re-ordering of those txs)
|
||||||
// but to create with one account and call with another
|
// but to create with one contract and call with another
|
||||||
// you have to wait a block to avoid a re-ordering attack
|
// you have to wait a block to avoid a re-ordering attack
|
||||||
// that will take your fees
|
// that will take your fees
|
||||||
inAcc.Balance -= tx.Fee
|
|
||||||
blockCache.UpdateAccount(inAcc)
|
|
||||||
if outAcc == nil {
|
if outAcc == nil {
|
||||||
log.Info(Fmt("Cannot find destination address %X. Deducting fee from caller", tx.Address))
|
log.Info(Fmt("%X tries to call %X but it does not exist.",
|
||||||
|
inAcc.Address, tx.Address))
|
||||||
} else {
|
} else {
|
||||||
log.Info(Fmt("Attempting to call an account (%X) with no code. Deducting fee from caller", tx.Address))
|
log.Info(Fmt("%X tries to call %X but code is blank.",
|
||||||
|
inAcc.Address, tx.Address))
|
||||||
}
|
}
|
||||||
return types.ErrTxInvalidAddress
|
err = types.ErrTxInvalidAddress
|
||||||
|
goto CALL_COMPLETE
|
||||||
}
|
}
|
||||||
callee = toVMAccount(outAcc)
|
|
||||||
code = callee.Code
|
// get or create callee
|
||||||
log.Info(Fmt("Calling contract %X with code %X", callee.Address, callee.Code))
|
if createContract {
|
||||||
} else {
|
if HasPermission(blockCache, inAcc, ptypes.CreateContract) {
|
||||||
callee = txCache.CreateAccount(caller)
|
callee = txCache.CreateAccount(caller)
|
||||||
log.Info(Fmt("Created new account %X", callee.Address))
|
log.Info(Fmt("Created new contract %X", callee.Address))
|
||||||
code = tx.Data
|
code = tx.Data
|
||||||
|
} else {
|
||||||
|
log.Info(Fmt("Error on execution: Caller %X cannot create contract",
|
||||||
|
caller.Address))
|
||||||
|
err = types.ErrTxPermissionDenied
|
||||||
|
goto CALL_COMPLETE
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
callee = toVMAccount(outAcc)
|
||||||
|
log.Info(Fmt("Calling contract %X with code %X", callee.Address, callee.Code))
|
||||||
|
code = callee.Code
|
||||||
}
|
}
|
||||||
log.Info(Fmt("Code for this contract: %X", code))
|
log.Info(Fmt("Code for this contract: %X", code))
|
||||||
|
|
||||||
txCache.UpdateAccount(caller) // because we bumped nonce
|
// Run VM call and sync txCache to blockCache.
|
||||||
txCache.UpdateAccount(callee) // so the txCache knows about the callee and the create and/or transfer takes effect
|
{ // Capture scope for goto.
|
||||||
|
// Write caller/callee to txCache.
|
||||||
|
txCache.UpdateAccount(caller)
|
||||||
|
txCache.UpdateAccount(callee)
|
||||||
vmach := vm.NewVM(txCache, params, caller.Address, types.TxID(_s.ChainID, tx))
|
vmach := vm.NewVM(txCache, params, caller.Address, types.TxID(_s.ChainID, tx))
|
||||||
vmach.SetFireable(evc)
|
vmach.SetFireable(evc)
|
||||||
|
|
||||||
// NOTE: Call() transfers the value from caller to callee iff call succeeds.
|
// NOTE: Call() transfers the value from caller to callee iff call succeeds.
|
||||||
ret, err := vmach.Call(caller, callee, code, tx.Data, value, &gas)
|
ret, err = vmach.Call(caller, callee, code, tx.Data, value, &gas)
|
||||||
exception := ""
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exception = err.Error()
|
|
||||||
// Failure. Charge the gas fee. The 'value' was otherwise not transferred.
|
// Failure. Charge the gas fee. The 'value' was otherwise not transferred.
|
||||||
log.Info(Fmt("Error on execution: %v", err))
|
log.Info(Fmt("Error on execution: %v", err))
|
||||||
inAcc.Balance -= tx.Fee
|
goto CALL_COMPLETE
|
||||||
blockCache.UpdateAccount(inAcc)
|
|
||||||
// Throw away 'txCache' which holds incomplete updates (don't sync it).
|
|
||||||
} else {
|
|
||||||
log.Info("Successful execution")
|
|
||||||
// Success
|
|
||||||
if createAccount {
|
|
||||||
callee.Code = ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Info("Successful execution")
|
||||||
|
if createContract {
|
||||||
|
callee.Code = ret
|
||||||
|
}
|
||||||
txCache.Sync()
|
txCache.Sync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CALL_COMPLETE: // err may or may not be nil.
|
||||||
|
|
||||||
// Create a receipt from the ret and whether errored.
|
// Create a receipt from the ret and whether errored.
|
||||||
log.Notice("VM call complete", "caller", caller, "callee", callee, "return", ret, "err", err)
|
log.Notice("VM call complete", "caller", caller, "callee", callee, "return", ret, "err", err)
|
||||||
|
|
||||||
// Fire Events for sender and receiver
|
// Fire Events for sender and receiver
|
||||||
// a separate event will be fired from vm for each additional call
|
// a separate event will be fired from vm for each additional call
|
||||||
if evc != nil {
|
if evc != nil {
|
||||||
|
exception := ""
|
||||||
|
if err != nil {
|
||||||
|
exception = err.Error()
|
||||||
|
}
|
||||||
evc.FireEvent(types.EventStringAccInput(tx.Input.Address), types.EventMsgCallTx{tx, ret, exception})
|
evc.FireEvent(types.EventStringAccInput(tx.Input.Address), types.EventMsgCallTx{tx, ret, exception})
|
||||||
evc.FireEvent(types.EventStringAccOutput(tx.Address), types.EventMsgCallTx{tx, ret, exception})
|
evc.FireEvent(types.EventStringAccOutput(tx.Address), types.EventMsgCallTx{tx, ret, exception})
|
||||||
}
|
}
|
||||||
|
@ -493,7 +509,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||||
// So mempool will skip the actual .Call(),
|
// So mempool will skip the actual .Call(),
|
||||||
// and only deduct from the caller's balance.
|
// and only deduct from the caller's balance.
|
||||||
inAcc.Balance -= value
|
inAcc.Balance -= value
|
||||||
if createAccount {
|
if createContract {
|
||||||
inAcc.Sequence += 1
|
inAcc.Sequence += 1
|
||||||
}
|
}
|
||||||
blockCache.UpdateAccount(inAcc)
|
blockCache.UpdateAccount(inAcc)
|
||||||
|
@ -556,7 +572,7 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab
|
||||||
// ensure we are owner
|
// ensure we are owner
|
||||||
if bytes.Compare(entry.Owner, tx.Input.Address) != 0 {
|
if bytes.Compare(entry.Owner, tx.Input.Address) != 0 {
|
||||||
log.Info(Fmt("Sender %X is trying to update a name (%s) for which he is not owner", tx.Input.Address, tx.Name))
|
log.Info(Fmt("Sender %X is trying to update a name (%s) for which he is not owner", tx.Input.Address, tx.Name))
|
||||||
return types.ErrIncorrectOwner
|
return types.ErrTxPermissionDenied
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
expired = true
|
expired = true
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
dbm "github.com/tendermint/tendermint/db"
|
dbm "github.com/tendermint/tendermint/db"
|
||||||
"github.com/tendermint/tendermint/merkle"
|
"github.com/tendermint/tendermint/merkle"
|
||||||
|
@ -58,7 +58,7 @@ type GenesisDoc struct {
|
||||||
|
|
||||||
func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) {
|
func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) {
|
||||||
var err error
|
var err error
|
||||||
binary.ReadJSONPtr(&genState, jsonBlob, &err)
|
wire.ReadJSONPtr(&genState, jsonBlob, &err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(Fmt("Couldn't read GenesisDoc: %v", err))
|
log.Error(Fmt("Couldn't read GenesisDoc: %v", err))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -86,7 +86,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make accounts state tree
|
// Make accounts state tree
|
||||||
accounts := merkle.NewIAVLTree(binary.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db)
|
accounts := merkle.NewIAVLTree(wire.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db)
|
||||||
for _, genAcc := range genDoc.Accounts {
|
for _, genAcc := range genDoc.Accounts {
|
||||||
perm := ptypes.ZeroAccountPermissions
|
perm := ptypes.ZeroAccountPermissions
|
||||||
if genAcc.Permissions != nil {
|
if genAcc.Permissions != nil {
|
||||||
|
@ -122,7 +122,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
|
||||||
accounts.Set(permsAcc.Address, permsAcc)
|
accounts.Set(permsAcc.Address, permsAcc)
|
||||||
|
|
||||||
// Make validatorInfos state tree && validators slice
|
// Make validatorInfos state tree && validators slice
|
||||||
validatorInfos := merkle.NewIAVLTree(binary.BasicCodec, ValidatorInfoCodec, 0, db)
|
validatorInfos := merkle.NewIAVLTree(wire.BasicCodec, ValidatorInfoCodec, 0, db)
|
||||||
validators := make([]*Validator, len(genDoc.Validators))
|
validators := make([]*Validator, len(genDoc.Validators))
|
||||||
for i, val := range genDoc.Validators {
|
for i, val := range genDoc.Validators {
|
||||||
pubKey := val.PubKey
|
pubKey := val.PubKey
|
||||||
|
@ -153,7 +153,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make namereg tree
|
// Make namereg tree
|
||||||
nameReg := merkle.NewIAVLTree(binary.BasicCodec, NameRegCodec, 0, db)
|
nameReg := merkle.NewIAVLTree(wire.BasicCodec, NameRegCodec, 0, db)
|
||||||
// TODO: add names, contracts to genesis.json
|
// TODO: add names, contracts to genesis.json
|
||||||
|
|
||||||
// IAVLTrees must be persisted before copy operations.
|
// IAVLTrees must be persisted before copy operations.
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
. "github.com/tendermint/tendermint/consensus/types"
|
. "github.com/tendermint/tendermint/consensus/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
@ -72,7 +72,7 @@ func LoadPrivValidator(filePath string) *PrivValidator {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
Exit(err.Error())
|
||||||
}
|
}
|
||||||
privVal := binary.ReadJSON(&PrivValidator{}, privValJSONBytes, &err).(*PrivValidator)
|
privVal := wire.ReadJSON(&PrivValidator{}, privValJSONBytes, &err).(*PrivValidator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(Fmt("Error reading PrivValidator from %v: %v\n", filePath, err))
|
Exit(Fmt("Error reading PrivValidator from %v: %v\n", filePath, err))
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ func (privVal *PrivValidator) save() {
|
||||||
if privVal.filePath == "" {
|
if privVal.filePath == "" {
|
||||||
PanicSanity("Cannot save PrivValidator: filePath not set")
|
PanicSanity("Cannot save PrivValidator: filePath not set")
|
||||||
}
|
}
|
||||||
jsonBytes := binary.JSONBytes(privVal)
|
jsonBytes := wire.JSONBytes(privVal)
|
||||||
err := WriteFileAtomic(privVal.filePath, jsonBytes)
|
err := WriteFileAtomic(privVal.filePath, jsonBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// `@; BOOM!!!
|
// `@; BOOM!!!
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
dbm "github.com/tendermint/tendermint/db"
|
dbm "github.com/tendermint/tendermint/db"
|
||||||
"github.com/tendermint/tendermint/events"
|
"github.com/tendermint/tendermint/events"
|
||||||
|
@ -49,22 +49,22 @@ func LoadState(db dbm.DB) *State {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
r, n, err := bytes.NewReader(buf), new(int64), new(error)
|
r, n, err := bytes.NewReader(buf), new(int64), new(error)
|
||||||
s.ChainID = binary.ReadString(r, n, err)
|
s.ChainID = wire.ReadString(r, n, err)
|
||||||
s.LastBlockHeight = binary.ReadVarint(r, n, err)
|
s.LastBlockHeight = wire.ReadVarint(r, n, err)
|
||||||
s.LastBlockHash = binary.ReadByteSlice(r, n, err)
|
s.LastBlockHash = wire.ReadByteSlice(r, n, err)
|
||||||
s.LastBlockParts = binary.ReadBinary(types.PartSetHeader{}, r, n, err).(types.PartSetHeader)
|
s.LastBlockParts = wire.ReadBinary(types.PartSetHeader{}, r, n, err).(types.PartSetHeader)
|
||||||
s.LastBlockTime = binary.ReadTime(r, n, err)
|
s.LastBlockTime = wire.ReadTime(r, n, err)
|
||||||
s.BondedValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
|
s.BondedValidators = wire.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
|
||||||
s.LastBondedValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
|
s.LastBondedValidators = wire.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
|
||||||
s.UnbondingValidators = binary.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
|
s.UnbondingValidators = wire.ReadBinary(&ValidatorSet{}, r, n, err).(*ValidatorSet)
|
||||||
accountsHash := binary.ReadByteSlice(r, n, err)
|
accountsHash := wire.ReadByteSlice(r, n, err)
|
||||||
s.accounts = merkle.NewIAVLTree(binary.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db)
|
s.accounts = merkle.NewIAVLTree(wire.BasicCodec, acm.AccountCodec, defaultAccountsCacheCapacity, db)
|
||||||
s.accounts.Load(accountsHash)
|
s.accounts.Load(accountsHash)
|
||||||
validatorInfosHash := binary.ReadByteSlice(r, n, err)
|
validatorInfosHash := wire.ReadByteSlice(r, n, err)
|
||||||
s.validatorInfos = merkle.NewIAVLTree(binary.BasicCodec, ValidatorInfoCodec, 0, db)
|
s.validatorInfos = merkle.NewIAVLTree(wire.BasicCodec, ValidatorInfoCodec, 0, db)
|
||||||
s.validatorInfos.Load(validatorInfosHash)
|
s.validatorInfos.Load(validatorInfosHash)
|
||||||
nameRegHash := binary.ReadByteSlice(r, n, err)
|
nameRegHash := wire.ReadByteSlice(r, n, err)
|
||||||
s.nameReg = merkle.NewIAVLTree(binary.BasicCodec, NameRegCodec, 0, db)
|
s.nameReg = merkle.NewIAVLTree(wire.BasicCodec, NameRegCodec, 0, db)
|
||||||
s.nameReg.Load(nameRegHash)
|
s.nameReg.Load(nameRegHash)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
|
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
|
||||||
|
@ -80,17 +80,17 @@ func (s *State) Save() {
|
||||||
s.validatorInfos.Save()
|
s.validatorInfos.Save()
|
||||||
s.nameReg.Save()
|
s.nameReg.Save()
|
||||||
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
binary.WriteString(s.ChainID, buf, n, err)
|
wire.WriteString(s.ChainID, buf, n, err)
|
||||||
binary.WriteVarint(s.LastBlockHeight, buf, n, err)
|
wire.WriteVarint(s.LastBlockHeight, buf, n, err)
|
||||||
binary.WriteByteSlice(s.LastBlockHash, buf, n, err)
|
wire.WriteByteSlice(s.LastBlockHash, buf, n, err)
|
||||||
binary.WriteBinary(s.LastBlockParts, buf, n, err)
|
wire.WriteBinary(s.LastBlockParts, buf, n, err)
|
||||||
binary.WriteTime(s.LastBlockTime, buf, n, err)
|
wire.WriteTime(s.LastBlockTime, buf, n, err)
|
||||||
binary.WriteBinary(s.BondedValidators, buf, n, err)
|
wire.WriteBinary(s.BondedValidators, buf, n, err)
|
||||||
binary.WriteBinary(s.LastBondedValidators, buf, n, err)
|
wire.WriteBinary(s.LastBondedValidators, buf, n, err)
|
||||||
binary.WriteBinary(s.UnbondingValidators, buf, n, err)
|
wire.WriteBinary(s.UnbondingValidators, buf, n, err)
|
||||||
binary.WriteByteSlice(s.accounts.Hash(), buf, n, err)
|
wire.WriteByteSlice(s.accounts.Hash(), buf, n, err)
|
||||||
binary.WriteByteSlice(s.validatorInfos.Hash(), buf, n, err)
|
wire.WriteByteSlice(s.validatorInfos.Hash(), buf, n, err)
|
||||||
binary.WriteByteSlice(s.nameReg.Hash(), buf, n, err)
|
wire.WriteByteSlice(s.nameReg.Hash(), buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
PanicCrisis(*err)
|
PanicCrisis(*err)
|
||||||
}
|
}
|
||||||
|
@ -147,6 +147,14 @@ func (s *State) SetDB(db dbm.DB) {
|
||||||
s.DB = db
|
s.DB = db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
// State.params
|
||||||
|
|
||||||
|
func (s *State) GetGasLimit() int64 {
|
||||||
|
return 1000000 // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// State.params
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
// State.accounts
|
// State.accounts
|
||||||
|
|
||||||
|
@ -294,7 +302,7 @@ func (s *State) SetValidatorInfos(validatorInfos merkle.Tree) {
|
||||||
// State.storage
|
// State.storage
|
||||||
|
|
||||||
func (s *State) LoadStorage(hash []byte) (storage merkle.Tree) {
|
func (s *State) LoadStorage(hash []byte) (storage merkle.Tree) {
|
||||||
storage = merkle.NewIAVLTree(binary.BasicCodec, binary.BasicCodec, 1024, s.DB)
|
storage = merkle.NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 1024, s.DB)
|
||||||
storage.Load(hash)
|
storage.Load(hash)
|
||||||
return storage
|
return storage
|
||||||
}
|
}
|
||||||
|
@ -331,14 +339,14 @@ func (s *State) SetNameReg(nameReg merkle.Tree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NameRegEncoder(o interface{}, w io.Writer, n *int64, err *error) {
|
func NameRegEncoder(o interface{}, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteBinary(o.(*types.NameRegEntry), w, n, err)
|
wire.WriteBinary(o.(*types.NameRegEntry), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NameRegDecoder(r io.Reader, n *int64, err *error) interface{} {
|
func NameRegDecoder(r io.Reader, n *int64, err *error) interface{} {
|
||||||
return binary.ReadBinary(&types.NameRegEntry{}, r, n, err)
|
return wire.ReadBinary(&types.NameRegEntry{}, r, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var NameRegCodec = binary.Codec{
|
var NameRegCodec = wire.Codec{
|
||||||
Encode: NameRegEncoder,
|
Encode: NameRegEncoder,
|
||||||
Decode: NameRegDecoder,
|
Decode: NameRegDecoder,
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ func toStateAccount(acc *vm.Account) *acm.Account {
|
||||||
if acc.StorageRoot.IsZero() {
|
if acc.StorageRoot.IsZero() {
|
||||||
storageRoot = nil
|
storageRoot = nil
|
||||||
} else {
|
} else {
|
||||||
storageRoot = acc.StorageRoot.Bytes()
|
storageRoot = acc.StorageRoot.Postfix(20)
|
||||||
}
|
}
|
||||||
return &acm.Account{
|
return &acm.Account{
|
||||||
Address: acc.Address.Postfix(20),
|
Address: acc.Address.Postfix(20),
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package state
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
"github.com/tendermint/tendermint/wire"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStateToFromVMAccount(t *testing.T) {
|
||||||
|
acmAcc1, _ := RandAccount(true, 456)
|
||||||
|
acmAcc1.StorageRoot = RandBytes(20)
|
||||||
|
vmAcc := toVMAccount(acmAcc1)
|
||||||
|
acmAcc2 := toStateAccount(vmAcc)
|
||||||
|
|
||||||
|
acmAcc1Bytes := wire.BinaryBytes(acmAcc1)
|
||||||
|
acmAcc2Bytes := wire.BinaryBytes(acmAcc2)
|
||||||
|
if !bytes.Equal(acmAcc1Bytes, acmAcc2Bytes) {
|
||||||
|
t.Errorf("Unexpected account wire bytes\n%X vs\n%X",
|
||||||
|
acmAcc1Bytes, acmAcc2Bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
@ -29,14 +29,14 @@ func (valInfo *ValidatorInfo) Copy() *ValidatorInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidatorInfoEncoder(o interface{}, w io.Writer, n *int64, err *error) {
|
func ValidatorInfoEncoder(o interface{}, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteBinary(o.(*ValidatorInfo), w, n, err)
|
wire.WriteBinary(o.(*ValidatorInfo), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidatorInfoDecoder(r io.Reader, n *int64, err *error) interface{} {
|
func ValidatorInfoDecoder(r io.Reader, n *int64, err *error) interface{} {
|
||||||
return binary.ReadBinary(&ValidatorInfo{}, r, n, err)
|
return wire.ReadBinary(&ValidatorInfo{}, r, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var ValidatorInfoCodec = binary.Codec{
|
var ValidatorInfoCodec = wire.Codec{
|
||||||
Encode: ValidatorInfoEncoder,
|
Encode: ValidatorInfoEncoder,
|
||||||
Decode: ValidatorInfoDecoder,
|
Decode: ValidatorInfoDecoder,
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ func (v *Validator) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Validator) Hash() []byte {
|
func (v *Validator) Hash() []byte {
|
||||||
return binary.BinaryRipemd160(v)
|
return wire.BinaryRipemd160(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
@ -109,11 +109,11 @@ var ValidatorCodec = validatorCodec{}
|
||||||
type validatorCodec struct{}
|
type validatorCodec struct{}
|
||||||
|
|
||||||
func (vc validatorCodec) Encode(o interface{}, w io.Writer, n *int64, err *error) {
|
func (vc validatorCodec) Encode(o interface{}, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteBinary(o.(*Validator), w, n, err)
|
wire.WriteBinary(o.(*Validator), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vc validatorCodec) Decode(r io.Reader, n *int64, err *error) interface{} {
|
func (vc validatorCodec) Decode(r io.Reader, n *int64, err *error) interface{} {
|
||||||
return binary.ReadBinary(&Validator{}, r, n, err)
|
return wire.ReadBinary(&Validator{}, r, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vc validatorCodec) Compare(o1 interface{}, o2 interface{}) int {
|
func (vc validatorCodec) Compare(o1 interface{}, o2 interface{}) int {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/merkle"
|
"github.com/tendermint/tendermint/merkle"
|
||||||
)
|
)
|
||||||
|
@ -75,7 +75,7 @@ func (b *Block) Hash() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Block) MakePartSet() *PartSet {
|
func (b *Block) MakePartSet() *PartSet {
|
||||||
return NewPartSetFromData(binary.BinaryBytes(b))
|
return NewPartSetFromData(wire.BinaryBytes(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convenience.
|
// Convenience.
|
||||||
|
@ -137,7 +137,7 @@ func (h *Header) Hash() []byte {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return binary.BinaryRipemd160(h)
|
return wire.BinaryRipemd160(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Header) StringIndented(indent string) string {
|
func (h *Header) StringIndented(indent string) string {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/code.google.com/p/go.crypto/ripemd160"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/merkle"
|
"github.com/tendermint/tendermint/merkle"
|
||||||
)
|
)
|
||||||
|
@ -76,7 +76,7 @@ func (psh PartSetHeader) Equals(other PartSetHeader) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (psh PartSetHeader) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
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)
|
wire.WriteTo([]byte(Fmt(`{"hash":"%X","total":%v}`, psh.Hash, psh.Total)), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
|
94
types/tx.go
94
types/tx.go
|
@ -6,7 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
ptypes "github.com/tendermint/tendermint/permission/types"
|
ptypes "github.com/tendermint/tendermint/permission/types"
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,7 @@ var (
|
||||||
ErrTxInvalidPubKey = errors.New("Error invalid pubkey")
|
ErrTxInvalidPubKey = errors.New("Error invalid pubkey")
|
||||||
ErrTxInvalidSignature = errors.New("Error invalid signature")
|
ErrTxInvalidSignature = errors.New("Error invalid signature")
|
||||||
ErrTxInvalidString = errors.New("Error invalid string")
|
ErrTxInvalidString = errors.New("Error invalid string")
|
||||||
ErrIncorrectOwner = errors.New("Error incorrect owner")
|
ErrTxPermissionDenied = errors.New("Error permission denied")
|
||||||
)
|
)
|
||||||
|
|
||||||
type ErrTxInvalidSequence struct {
|
type ErrTxInvalidSequence struct {
|
||||||
|
@ -71,17 +71,17 @@ const (
|
||||||
TxTypePermissions = byte(0x20)
|
TxTypePermissions = byte(0x20)
|
||||||
)
|
)
|
||||||
|
|
||||||
// for binary.readReflect
|
// for wire.readReflect
|
||||||
var _ = binary.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ Tx }{},
|
struct{ Tx }{},
|
||||||
binary.ConcreteType{&SendTx{}, TxTypeSend},
|
wire.ConcreteType{&SendTx{}, TxTypeSend},
|
||||||
binary.ConcreteType{&CallTx{}, TxTypeCall},
|
wire.ConcreteType{&CallTx{}, TxTypeCall},
|
||||||
binary.ConcreteType{&NameTx{}, TxTypeName},
|
wire.ConcreteType{&NameTx{}, TxTypeName},
|
||||||
binary.ConcreteType{&BondTx{}, TxTypeBond},
|
wire.ConcreteType{&BondTx{}, TxTypeBond},
|
||||||
binary.ConcreteType{&UnbondTx{}, TxTypeUnbond},
|
wire.ConcreteType{&UnbondTx{}, TxTypeUnbond},
|
||||||
binary.ConcreteType{&RebondTx{}, TxTypeRebond},
|
wire.ConcreteType{&RebondTx{}, TxTypeRebond},
|
||||||
binary.ConcreteType{&DupeoutTx{}, TxTypeDupeout},
|
wire.ConcreteType{&DupeoutTx{}, TxTypeDupeout},
|
||||||
binary.ConcreteType{&PermissionsTx{}, TxTypePermissions},
|
wire.ConcreteType{&PermissionsTx{}, TxTypePermissions},
|
||||||
)
|
)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -105,7 +105,7 @@ func (txIn *TxInput) ValidateBasic() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (txIn *TxInput) WriteSignBytes(w io.Writer, n *int64, err *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)
|
wire.WriteTo([]byte(Fmt(`{"address":"%X","amount":%v,"sequence":%v}`, txIn.Address, txIn.Amount, txIn.Sequence)), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (txIn *TxInput) String() string {
|
func (txIn *TxInput) String() string {
|
||||||
|
@ -130,7 +130,7 @@ func (txOut *TxOutput) ValidateBasic() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (txOut *TxOutput) WriteSignBytes(w io.Writer, n *int64, err *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)
|
wire.WriteTo([]byte(Fmt(`{"address":"%X","amount":%v}`, txOut.Address, txOut.Amount)), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (txOut *TxOutput) String() string {
|
func (txOut *TxOutput) String() string {
|
||||||
|
@ -145,22 +145,22 @@ type SendTx struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *SendTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (tx *SendTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err)
|
||||||
for i, in := range tx.Inputs {
|
for i, in := range tx.Inputs {
|
||||||
in.WriteSignBytes(w, n, err)
|
in.WriteSignBytes(w, n, err)
|
||||||
if i != len(tx.Inputs)-1 {
|
if i != len(tx.Inputs)-1 {
|
||||||
binary.WriteTo([]byte(","), w, n, err)
|
wire.WriteTo([]byte(","), w, n, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binary.WriteTo([]byte(`],"outputs":[`), w, n, err)
|
wire.WriteTo([]byte(`],"outputs":[`), w, n, err)
|
||||||
for i, out := range tx.Outputs {
|
for i, out := range tx.Outputs {
|
||||||
out.WriteSignBytes(w, n, err)
|
out.WriteSignBytes(w, n, err)
|
||||||
if i != len(tx.Outputs)-1 {
|
if i != len(tx.Outputs)-1 {
|
||||||
binary.WriteTo([]byte(","), w, n, err)
|
wire.WriteTo([]byte(","), w, n, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binary.WriteTo([]byte(`]}]}`), w, n, err)
|
wire.WriteTo([]byte(`]}]}`), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *SendTx) String() string {
|
func (tx *SendTx) String() string {
|
||||||
|
@ -178,11 +178,11 @@ type CallTx struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *CallTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (tx *CallTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","data":"%X"`, TxTypeCall, tx.Address, tx.Data)), w, n, err)
|
wire.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)
|
wire.WriteTo([]byte(Fmt(`,"fee":%v,"gas_limit":%v,"input":`, tx.Fee, tx.GasLimit)), w, n, err)
|
||||||
tx.Input.WriteSignBytes(w, n, err)
|
tx.Input.WriteSignBytes(w, n, err)
|
||||||
binary.WriteTo([]byte(`}]}`), w, n, err)
|
wire.WriteTo([]byte(`}]}`), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *CallTx) String() string {
|
func (tx *CallTx) String() string {
|
||||||
|
@ -199,12 +199,12 @@ type NameTx struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *NameTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (tx *NameTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"data":%s,"fee":%v`, TxTypeName, jsonEscape(tx.Data), tx.Fee)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"data":%s,"fee":%v`, TxTypeName, jsonEscape(tx.Data), tx.Fee)), w, n, err)
|
||||||
binary.WriteTo([]byte(`,"input":`), w, n, err)
|
wire.WriteTo([]byte(`,"input":`), w, n, err)
|
||||||
tx.Input.WriteSignBytes(w, n, err)
|
tx.Input.WriteSignBytes(w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"name":%s`, jsonEscape(tx.Name))), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"name":%s`, jsonEscape(tx.Name))), w, n, err)
|
||||||
binary.WriteTo([]byte(`}]}`), w, n, err)
|
wire.WriteTo([]byte(`}]}`), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *NameTx) ValidateStrings() error {
|
func (tx *NameTx) ValidateStrings() error {
|
||||||
|
@ -247,24 +247,24 @@ type BondTx struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err)
|
||||||
for i, in := range tx.Inputs {
|
for i, in := range tx.Inputs {
|
||||||
in.WriteSignBytes(w, n, err)
|
in.WriteSignBytes(w, n, err)
|
||||||
if i != len(tx.Inputs)-1 {
|
if i != len(tx.Inputs)-1 {
|
||||||
binary.WriteTo([]byte(","), w, n, err)
|
wire.WriteTo([]byte(","), w, n, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binary.WriteTo([]byte(Fmt(`],"pub_key":`)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`],"pub_key":`)), w, n, err)
|
||||||
binary.WriteTo(binary.JSONBytes(tx.PubKey), w, n, err)
|
wire.WriteTo(wire.JSONBytes(tx.PubKey), w, n, err)
|
||||||
binary.WriteTo([]byte(`,"unbond_to":[`), w, n, err)
|
wire.WriteTo([]byte(`,"unbond_to":[`), w, n, err)
|
||||||
for i, out := range tx.UnbondTo {
|
for i, out := range tx.UnbondTo {
|
||||||
out.WriteSignBytes(w, n, err)
|
out.WriteSignBytes(w, n, err)
|
||||||
if i != len(tx.UnbondTo)-1 {
|
if i != len(tx.UnbondTo)-1 {
|
||||||
binary.WriteTo([]byte(","), w, n, err)
|
wire.WriteTo([]byte(","), w, n, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binary.WriteTo([]byte(`]}]}`), w, n, err)
|
wire.WriteTo([]byte(`]}]}`), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *BondTx) String() string {
|
func (tx *BondTx) String() string {
|
||||||
|
@ -280,8 +280,8 @@ type UnbondTx struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (tx *UnbondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *UnbondTx) String() string {
|
func (tx *UnbondTx) String() string {
|
||||||
|
@ -297,8 +297,8 @@ type RebondTx struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (tx *RebondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *RebondTx) String() string {
|
func (tx *RebondTx) String() string {
|
||||||
|
@ -329,12 +329,12 @@ type PermissionsTx struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *PermissionsTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (tx *PermissionsTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"args":"`, TxTypePermissions)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"args":"`, TxTypePermissions)), w, n, err)
|
||||||
binary.WriteJSON(tx.PermArgs, w, n, err)
|
wire.WriteJSON(tx.PermArgs, w, n, err)
|
||||||
binary.WriteTo([]byte(`","input":`), w, n, err)
|
wire.WriteTo([]byte(`","input":`), w, n, err)
|
||||||
tx.Input.WriteSignBytes(w, n, err)
|
tx.Input.WriteSignBytes(w, n, err)
|
||||||
binary.WriteTo([]byte(`}]}`), w, n, err)
|
wire.WriteTo([]byte(`}]}`), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *PermissionsTx) String() string {
|
func (tx *PermissionsTx) String() string {
|
||||||
|
@ -346,7 +346,7 @@ func (tx *PermissionsTx) String() string {
|
||||||
// This should match the leaf hashes of Block.Data.Hash()'s SimpleMerkleTree.
|
// This should match the leaf hashes of Block.Data.Hash()'s SimpleMerkleTree.
|
||||||
func TxID(chainID string, tx Tx) []byte {
|
func TxID(chainID string, tx Tx) []byte {
|
||||||
signBytes := acm.SignBytes(chainID, tx)
|
signBytes := acm.SignBytes(chainID, tx)
|
||||||
return binary.BinaryRipemd160(signBytes)
|
return wire.BinaryRipemd160(signBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
acm "github.com/tendermint/tendermint/account"
|
acm "github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/wire"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||||
binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
|
wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
|
||||||
binary.WriteTo([]byte(Fmt(`,"vote":{"block_hash":"%X","block_parts":%v`, vote.BlockHash, vote.BlockParts)), w, n, err)
|
wire.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)
|
wire.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vote *Vote) Copy() *Vote {
|
func (vote *Vote) Copy() *Vote {
|
||||||
|
|
|
@ -5,6 +5,7 @@ const (
|
||||||
GasGetAccount int64 = 1
|
GasGetAccount int64 = 1
|
||||||
GasStorageUpdate int64 = 1
|
GasStorageUpdate int64 = 1
|
||||||
|
|
||||||
|
GasBaseOp int64 = 0 // TODO: make this 1
|
||||||
GasStackOp int64 = 1
|
GasStackOp int64 = 1
|
||||||
|
|
||||||
GasEcRecover int64 = 1
|
GasEcRecover int64 = 1
|
||||||
|
|
|
@ -21,6 +21,9 @@ type Account struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (acc *Account) String() string {
|
func (acc *Account) String() string {
|
||||||
|
if acc == nil {
|
||||||
|
return "nil-VMAccount"
|
||||||
|
}
|
||||||
return Fmt("VMAccount{%X B:%v C:%X N:%v S:%X}",
|
return Fmt("VMAccount{%X B:%v C:%X N:%v S:%X}",
|
||||||
acc.Address, acc.Balance, acc.Code, acc.Nonce, acc.StorageRoot)
|
acc.Address, acc.Balance, acc.Code, acc.Nonce, acc.StorageRoot)
|
||||||
}
|
}
|
||||||
|
|
59
vm/vm.go
59
vm/vm.go
|
@ -140,6 +140,18 @@ func (vm *VM) Call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to deduct gasToUse from gasLeft. If ok return false, otherwise
|
||||||
|
// set err and return true.
|
||||||
|
func useGasNegative(gasLeft *int64, gasToUse int64, err *error) bool {
|
||||||
|
if *gasLeft >= gasToUse {
|
||||||
|
*gasLeft -= gasToUse
|
||||||
|
return false
|
||||||
|
} else if *err == nil {
|
||||||
|
*err = ErrInsufficientGas
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Just like Call() but does not transfer 'value' or modify the callDepth.
|
// Just like Call() but does not transfer 'value' or modify the callDepth.
|
||||||
func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas *int64) (output []byte, err error) {
|
func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas *int64) (output []byte, err error) {
|
||||||
dbg.Printf("(%d) (%X) %X (code=%d) gas: %v (d) %X\n", vm.callDepth, caller.Address[:4], callee.Address, len(callee.Code), *gas, input)
|
dbg.Printf("(%d) (%X) %X (code=%d) gas: %v (d) %X\n", vm.callDepth, caller.Address[:4], callee.Address, len(callee.Code), *gas, input)
|
||||||
|
@ -148,12 +160,12 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
pc int64 = 0
|
pc int64 = 0
|
||||||
stack = NewStack(dataStackCapacity, gas, &err)
|
stack = NewStack(dataStackCapacity, gas, &err)
|
||||||
memory = make([]byte, memoryCapacity)
|
memory = make([]byte, memoryCapacity)
|
||||||
ok = false // convenience
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// If there is an error, return
|
|
||||||
if err != nil {
|
// Use BaseOp gas.
|
||||||
|
if useGasNegative(gas, GasBaseOp, &err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,8 +436,8 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
dbg.Printf(" => 0x%X\n", res)
|
dbg.Printf(" => 0x%X\n", res)
|
||||||
|
|
||||||
case SHA3: // 0x20
|
case SHA3: // 0x20
|
||||||
if ok = useGas(gas, GasSha3); !ok {
|
if useGasNegative(gas, GasSha3, &err) {
|
||||||
return nil, firstErr(err, ErrInsufficientGas)
|
return nil, err
|
||||||
}
|
}
|
||||||
offset, size := stack.Pop64(), stack.Pop64()
|
offset, size := stack.Pop64(), stack.Pop64()
|
||||||
data, ok := subslice(memory, offset, size)
|
data, ok := subslice(memory, offset, size)
|
||||||
|
@ -442,8 +454,8 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
|
|
||||||
case BALANCE: // 0x31
|
case BALANCE: // 0x31
|
||||||
addr := stack.Pop()
|
addr := stack.Pop()
|
||||||
if ok = useGas(gas, GasGetAccount); !ok {
|
if useGasNegative(gas, GasGetAccount, &err) {
|
||||||
return nil, firstErr(err, ErrInsufficientGas)
|
return nil, err
|
||||||
}
|
}
|
||||||
acc := vm.appState.GetAccount(addr)
|
acc := vm.appState.GetAccount(addr)
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
|
@ -520,8 +532,8 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
|
|
||||||
case EXTCODESIZE: // 0x3B
|
case EXTCODESIZE: // 0x3B
|
||||||
addr := stack.Pop()
|
addr := stack.Pop()
|
||||||
if ok = useGas(gas, GasGetAccount); !ok {
|
if useGasNegative(gas, GasGetAccount, &err) {
|
||||||
return nil, firstErr(err, ErrInsufficientGas)
|
return nil, err
|
||||||
}
|
}
|
||||||
acc := vm.appState.GetAccount(addr)
|
acc := vm.appState.GetAccount(addr)
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
|
@ -534,8 +546,8 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
|
|
||||||
case EXTCODECOPY: // 0x3C
|
case EXTCODECOPY: // 0x3C
|
||||||
addr := stack.Pop()
|
addr := stack.Pop()
|
||||||
if ok = useGas(gas, GasGetAccount); !ok {
|
if useGasNegative(gas, GasGetAccount, &err) {
|
||||||
return nil, firstErr(err, ErrInsufficientGas)
|
return nil, err
|
||||||
}
|
}
|
||||||
acc := vm.appState.GetAccount(addr)
|
acc := vm.appState.GetAccount(addr)
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
|
@ -579,8 +591,8 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
dbg.Printf(" => %v\n", vm.params.GasLimit)
|
dbg.Printf(" => %v\n", vm.params.GasLimit)
|
||||||
|
|
||||||
case POP: // 0x50
|
case POP: // 0x50
|
||||||
stack.Pop()
|
popped := stack.Pop()
|
||||||
dbg.Printf(" => %v\n", vm.params.GasLimit)
|
dbg.Printf(" => 0x%X\n", popped)
|
||||||
|
|
||||||
case MLOAD: // 0x51
|
case MLOAD: // 0x51
|
||||||
offset := stack.Pop64()
|
offset := stack.Pop64()
|
||||||
|
@ -616,8 +628,10 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
|
|
||||||
case SSTORE: // 0x55
|
case SSTORE: // 0x55
|
||||||
loc, data := stack.Pop(), stack.Pop()
|
loc, data := stack.Pop(), stack.Pop()
|
||||||
|
if useGasNegative(gas, GasStorageUpdate, &err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
vm.appState.SetStorage(callee.Address, loc, data)
|
vm.appState.SetStorage(callee.Address, loc, data)
|
||||||
useGas(gas, GasStorageUpdate)
|
|
||||||
dbg.Printf(" {0x%X : 0x%X}\n", loc, data)
|
dbg.Printf(" {0x%X : 0x%X}\n", loc, data)
|
||||||
|
|
||||||
case JUMP: // 0x56
|
case JUMP: // 0x56
|
||||||
|
@ -762,8 +776,8 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
vm.fireCallEvent(&exception, &ret, callee, &Account{Address: addr}, args, value, gas)
|
vm.fireCallEvent(&exception, &ret, callee, &Account{Address: addr}, args, value, gas)
|
||||||
} else {
|
} else {
|
||||||
// EVM contract
|
// EVM contract
|
||||||
if ok = useGas(gas, GasGetAccount); !ok {
|
if useGasNegative(gas, GasGetAccount, &err) {
|
||||||
return nil, firstErr(err, ErrInsufficientGas)
|
return nil, err
|
||||||
}
|
}
|
||||||
acc := vm.appState.GetAccount(addr)
|
acc := vm.appState.GetAccount(addr)
|
||||||
// since CALL is used also for sending funds,
|
// since CALL is used also for sending funds,
|
||||||
|
@ -821,8 +835,8 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
|
||||||
|
|
||||||
case SUICIDE: // 0xFF
|
case SUICIDE: // 0xFF
|
||||||
addr := stack.Pop()
|
addr := stack.Pop()
|
||||||
if ok = useGas(gas, GasGetAccount); !ok {
|
if useGasNegative(gas, GasGetAccount, &err) {
|
||||||
return nil, firstErr(err, ErrInsufficientGas)
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO if the receiver is , then make it the fee.
|
// TODO if the receiver is , then make it the fee.
|
||||||
receiver := vm.appState.GetAccount(addr)
|
receiver := vm.appState.GetAccount(addr)
|
||||||
|
@ -893,15 +907,6 @@ func firstErr(errA, errB error) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func useGas(gas *int64, gasToUse int64) bool {
|
|
||||||
if *gas > gasToUse {
|
|
||||||
*gas -= gasToUse
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func transfer(from, to *Account, amount int64) error {
|
func transfer(from, to *Account, amount int64) error {
|
||||||
if from.Balance < amount {
|
if from.Balance < amount {
|
||||||
return ErrInsufficientBalance
|
return ErrInsufficientBalance
|
||||||
|
|
|
@ -6,7 +6,7 @@ This documentation is out of date.
|
||||||
* Pointers that don't have a declared TypeByte() are
|
* Pointers that don't have a declared TypeByte() are
|
||||||
encoded with a leading 0x00 (nil) or 0x01.
|
encoded with a leading 0x00 (nil) or 0x01.
|
||||||
|
|
||||||
# `tendermint/binary`
|
# `tendermint/wire`
|
||||||
|
|
||||||
The `binary` submodule encodes primary types and structs into bytes.
|
The `binary` submodule encodes primary types and structs into bytes.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/log15"
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/log15"
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
@ -442,7 +442,7 @@ func writeReflectBinary(rv reflect.Value, rt reflect.Type, opts Options, w io.Wr
|
||||||
typeInfo = GetTypeInfo(rt)
|
typeInfo = GetTypeInfo(rt)
|
||||||
if !rv.IsValid() {
|
if !rv.IsValid() {
|
||||||
// For better compatibility with other languages,
|
// For better compatibility with other languages,
|
||||||
// as far as tendermint/binary is concerned,
|
// as far as tendermint/wire is concerned,
|
||||||
// pointers to nil values are the same as nil.
|
// pointers to nil values are the same as nil.
|
||||||
WriteByte(0x00, w, n, err)
|
WriteByte(0x00, w, n, err)
|
||||||
return
|
return
|
||||||
|
@ -841,7 +841,7 @@ func writeReflectJSON(rv reflect.Value, rt reflect.Type, w io.Writer, n *int64,
|
||||||
typeInfo = GetTypeInfo(rt)
|
typeInfo = GetTypeInfo(rt)
|
||||||
if !rv.IsValid() {
|
if !rv.IsValid() {
|
||||||
// For better compatibility with other languages,
|
// For better compatibility with other languages,
|
||||||
// as far as tendermint/binary is concerned,
|
// as far as tendermint/wire is concerned,
|
||||||
// pointers to nil values are the same as nil.
|
// pointers to nil values are the same as nil.
|
||||||
WriteTo([]byte("null"), w, n, err)
|
WriteTo([]byte("null"), w, n, err)
|
||||||
return
|
return
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
|
@ -1,4 +1,4 @@
|
||||||
package binary
|
package wire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
Loading…
Reference in New Issue