예제 #1
0
파일: tx.go 프로젝트: jsp282/tendermint
	TxTypeBond    = byte(0x11)
	TxTypeUnbond  = byte(0x12)
	TxTypeRebond  = byte(0x13)
	TxTypeDupeout = byte(0x14)

	// Admin transactions
	TxTypePermissions = byte(0x20)
)

// for wire.readReflect
var _ = wire.RegisterInterface(
	struct{ Tx }{},
	wire.ConcreteType{&SendTx{}, TxTypeSend},
	wire.ConcreteType{&CallTx{}, TxTypeCall},
	wire.ConcreteType{&NameTx{}, TxTypeName},
	wire.ConcreteType{&BondTx{}, TxTypeBond},
	wire.ConcreteType{&UnbondTx{}, TxTypeUnbond},
	wire.ConcreteType{&RebondTx{}, TxTypeRebond},
	wire.ConcreteType{&DupeoutTx{}, TxTypeDupeout},
	wire.ConcreteType{&PermissionsTx{}, TxTypePermissions},
)

//-----------------------------------------------------------------------------

type TxInput struct {
	Address   []byte        `json:"address"`   // Hash of the PubKey
	Amount    int64         `json:"amount"`    // Must not exceed account balance
	Sequence  int           `json:"sequence"`  // Must be 1 greater than the last committed TxInput
	Signature acm.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx
	PubKey    acm.PubKey    `json:"pub_key"`   // Must not be nil, may be nil
}
예제 #2
0
	EventDataTypeCall     = byte(0x04)
	EventDataTypeLog      = byte(0x05)

	EventDataTypeRoundState = byte(0x11)
	EventDataTypeVote       = byte(0x12)
)

type EventData interface {
	AssertIsEventData()
}

var _ = wire.RegisterInterface(
	struct{ EventData }{},
	wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock},
	// wire.ConcreteType{EventDataFork{}, EventDataTypeFork },
	wire.ConcreteType{EventDataTx{}, EventDataTypeTx},
	wire.ConcreteType{EventDataCall{}, EventDataTypeCall},
	wire.ConcreteType{EventDataLog{}, EventDataTypeLog},
	wire.ConcreteType{EventDataRoundState{}, EventDataTypeRoundState},
	wire.ConcreteType{EventDataVote{}, EventDataTypeVote},
)

// Most event messages are basic types (a block, a transaction)
// but some (an input to a call tx or a receive) are more exotic

type EventDataNewBlock struct {
	Block *Block `json:"block"`
}

// All txs fire EventDataTx, but only CallTx might have Return or Exception
type EventDataTx struct {
	Tx        Tx     `json:"tx"`
예제 #3
0
//-----------------------------------------------------------------------------
// Messages

const (
	msgTypeBlockRequest   = byte(0x10)
	msgTypeBlockResponse  = byte(0x11)
	msgTypeStatusResponse = byte(0x20)
	msgTypeStatusRequest  = byte(0x21)
)

type BlockchainMessage interface{}

var _ = wire.RegisterInterface(
	struct{ BlockchainMessage }{},
	wire.ConcreteType{&bcBlockRequestMessage{}, msgTypeBlockRequest},
	wire.ConcreteType{&bcBlockResponseMessage{}, msgTypeBlockResponse},
	wire.ConcreteType{&bcStatusResponseMessage{}, msgTypeStatusResponse},
	wire.ConcreteType{&bcStatusRequestMessage{}, msgTypeStatusRequest},
)

// TODO: ensure that bz is completely read.
func DecodeMessage(bz []byte) (msgType byte, msg BlockchainMessage, err error) {
	msgType = bz[0]
	n := int64(0)
	r := bytes.NewReader(bz)
	msg = wire.ReadBinary(struct{ BlockchainMessage }{}, r, &n, &err).(struct{ BlockchainMessage }).BlockchainMessage
	if err != nil && n != int64(len(bz)) {
		err = errors.New("DecodeMessage() had bytes left over.")
	}
	return
}
예제 #4
0
const (
	commandTypeStartProcess  = 0x01
	commandTypeStopProcess   = 0x02
	commandTypeListProcesses = 0x03
	commandTypeServeFile     = 0x04
	commandTypeOpenListener  = 0x05
	commandTypeCloseListener = 0x06
	commandTypeQuit          = 0x07
)

// for wire.readReflect
var _ = wire.RegisterInterface(
	struct{ Command }{},
	wire.ConcreteType{CommandStartProcess{}, commandTypeStartProcess},
	wire.ConcreteType{CommandStopProcess{}, commandTypeStopProcess},
	wire.ConcreteType{CommandListProcesses{}, commandTypeListProcesses},
	wire.ConcreteType{CommandServeFile{}, commandTypeServeFile},
	wire.ConcreteType{CommandOpenListener{}, commandTypeOpenListener},
	wire.ConcreteType{CommandCloseListener{}, commandTypeCloseListener},
	wire.ConcreteType{CommandQuit{}, commandTypeQuit},
)

type CommandStartProcess struct {
	Wait     bool
	Label    string
	ExecPath string
	Args     []string
	Input    string
}

type CommandStopProcess struct {
	Label string
예제 #5
0
	pexR.evsw = evsw
}

//-----------------------------------------------------------------------------
// Messages

const (
	msgTypeRequest = byte(0x01)
	msgTypeAddrs   = byte(0x02)
)

type PexMessage interface{}

var _ = wire.RegisterInterface(
	struct{ PexMessage }{},
	wire.ConcreteType{&pexRequestMessage{}, msgTypeRequest},
	wire.ConcreteType{&pexAddrsMessage{}, msgTypeAddrs},
)

func DecodeMessage(bz []byte) (msgType byte, msg PexMessage, err error) {
	msgType = bz[0]
	n := new(int64)
	r := bytes.NewReader(bz)
	msg = wire.ReadBinary(struct{ PexMessage }{}, r, n, &err).(struct{ PexMessage }).PexMessage
	return
}

/*
A pexRequestMessage requests additional peer addresses.
*/
type pexRequestMessage struct {
예제 #6
0
const (
	PermArgsTypeHasBase   = byte(0x01)
	PermArgsTypeSetBase   = byte(0x02)
	PermArgsTypeUnsetBase = byte(0x03)
	PermArgsTypeSetGlobal = byte(0x04)
	PermArgsTypeHasRole   = byte(0x05)
	PermArgsTypeAddRole   = byte(0x06)
	PermArgsTypeRmRole    = byte(0x07)
)

// for wire.readReflect
var _ = wire.RegisterInterface(
	struct{ PermArgs }{},
	wire.ConcreteType{&HasBaseArgs{}, PermArgsTypeHasBase},
	wire.ConcreteType{&SetBaseArgs{}, PermArgsTypeSetBase},
	wire.ConcreteType{&UnsetBaseArgs{}, PermArgsTypeUnsetBase},
	wire.ConcreteType{&SetGlobalArgs{}, PermArgsTypeSetGlobal},
	wire.ConcreteType{&HasRoleArgs{}, PermArgsTypeHasRole},
	wire.ConcreteType{&AddRoleArgs{}, PermArgsTypeAddRole},
	wire.ConcreteType{&RmRoleArgs{}, PermArgsTypeRmRole},
)

type HasBaseArgs struct {
	Address    []byte   `json:"address"`
	Permission PermFlag `json:"permission"`
}

func (*HasBaseArgs) PermFlag() PermFlag {
	return HasBase
}

type SetBaseArgs struct {
예제 #7
0
	. "github.com/tendermint/tendermint/common"
	"github.com/tendermint/tendermint/wire"
)

// Signature is a part of Txs and consensus Votes.
type Signature interface {
	IsZero() bool
	String() string
}

// Types of Signature implementations
const (
	SignatureTypeEd25519 = byte(0x01)
)

// for wire.readReflect
var _ = wire.RegisterInterface(
	struct{ Signature }{},
	wire.ConcreteType{SignatureEd25519{}, SignatureTypeEd25519},
)

//-------------------------------------

// Implements Signature
type SignatureEd25519 [64]byte

func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }

func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
예제 #8
0
)

// PubKey is part of Account and Validator.
type PubKey interface {
	Address() []byte
	VerifyBytes(msg []byte, sig Signature) bool
}

// Types of PubKey implementations
const (
	PubKeyTypeEd25519 = byte(0x01)
)

// for wire.readReflect
var _ = wire.RegisterInterface(
	struct{ PubKey }{},
	wire.ConcreteType{PubKeyEd25519{}, PubKeyTypeEd25519},
)

//-------------------------------------

// Implements PubKey
type PubKeyEd25519 [32]byte

// TODO: Slicing the array gives us length prefixing but loses the type byte.
// Revisit if we add more pubkey types.
// For now, we artificially append the type byte in front to give us backwards
// compatibility for when the pubkey wasn't fixed length array
func (pubKey PubKeyEd25519) Address() []byte {
	w, n, err := new(bytes.Buffer), new(int64), new(error)
	wire.WriteBinary(pubKey[:], w, n, err)
	if *err != nil {
예제 #9
0
	msgTypeNewRoundStep = byte(0x01)
	msgTypeCommitStep   = byte(0x02)
	msgTypeProposal     = byte(0x11)
	msgTypeProposalPOL  = byte(0x12)
	msgTypeBlockPart    = byte(0x13) // both block & POL
	msgTypeVote         = byte(0x14)
	msgTypeHasVote      = byte(0x15)
)

type ConsensusMessage interface{}

var _ = wire.RegisterInterface(
	struct{ ConsensusMessage }{},
	wire.ConcreteType{&NewRoundStepMessage{}, msgTypeNewRoundStep},
	wire.ConcreteType{&CommitStepMessage{}, msgTypeCommitStep},
	wire.ConcreteType{&ProposalMessage{}, msgTypeProposal},
	wire.ConcreteType{&ProposalPOLMessage{}, msgTypeProposalPOL},
	wire.ConcreteType{&BlockPartMessage{}, msgTypeBlockPart},
	wire.ConcreteType{&VoteMessage{}, msgTypeVote},
	wire.ConcreteType{&HasVoteMessage{}, msgTypeHasVote},
)

// TODO: check for unnecessary extra bytes at the end.
func DecodeMessage(bz []byte) (msgType byte, msg ConsensusMessage, err error) {
	msgType = bz[0]
	n := new(int64)
	r := bytes.NewReader(bz)
	msg = wire.ReadBinary(struct{ ConsensusMessage }{}, r, n, &err).(struct{ ConsensusMessage }).ConsensusMessage
	return
}

//-------------------------------------
예제 #10
0
	ResultTypeGenesis            = byte(0x11)
	ResultTypeSignTx             = byte(0x12)
	ResultTypeEvent              = byte(0x13) // so websockets can respond to rpc functions
)

type Result interface{}

// for wire.readReflect
var _ = wire.RegisterInterface(
	struct{ Result }{},
	wire.ConcreteType{&ResultGetStorage{}, ResultTypeGetStorage},
	wire.ConcreteType{&ResultCall{}, ResultTypeCall},
	wire.ConcreteType{&ResultListAccounts{}, ResultTypeListAccounts},
	wire.ConcreteType{&ResultDumpStorage{}, ResultTypeDumpStorage},
	wire.ConcreteType{&ResultBlockchainInfo{}, ResultTypeBlockchainInfo},
	wire.ConcreteType{&ResultGetBlock{}, ResultTypeGetBlock},
	wire.ConcreteType{&ResultStatus{}, ResultTypeStatus},
	wire.ConcreteType{&ResultNetInfo{}, ResultTypeNetInfo},
	wire.ConcreteType{&ResultListValidators{}, ResultTypeListValidators},
	wire.ConcreteType{&ResultDumpConsensusState{}, ResultTypeDumpConsensusState},
	wire.ConcreteType{&ResultListNames{}, ResultTypeListNames},
	wire.ConcreteType{&ResultGenPrivAccount{}, ResultTypeGenPrivAccount},
	wire.ConcreteType{&ResultGetAccount{}, ResultTypeGetAccount},
	wire.ConcreteType{&ResultBroadcastTx{}, ResultTypeBroadcastTx},
	wire.ConcreteType{&ResultListUnconfirmedTxs{}, ResultTypeListUnconfirmedTxs},
	wire.ConcreteType{&ResultGetName{}, ResultTypeGetName},
	wire.ConcreteType{&ResultGenesis{}, ResultTypeGenesis},
	wire.ConcreteType{&ResultSignTx{}, ResultTypeSignTx},
	wire.ConcreteType{&ResultEvent{}, ResultTypeEvent},
)
예제 #11
0
// implements events.Eventable
func (memR *MempoolReactor) SetFireable(evsw events.Fireable) {
	memR.evsw = evsw
}

//-----------------------------------------------------------------------------
// Messages

const (
	msgTypeTx = byte(0x01)
)

type MempoolMessage interface{}

var _ = wire.RegisterInterface(
	struct{ MempoolMessage }{},
	wire.ConcreteType{&TxMessage{}, msgTypeTx},
)

func DecodeMessage(bz []byte) (msgType byte, msg MempoolMessage, err error) {
	msgType = bz[0]
	n := new(int64)
	r := bytes.NewReader(bz)
	msg = wire.ReadBinary(struct{ MempoolMessage }{}, r, n, &err).(struct{ MempoolMessage }).MempoolMessage
	return
}

//-------------------------------------

type TxMessage struct {
	Tx types.Tx
}