TMSP -> ABCI
This commit is contained in:
parent
8a6e4095b7
commit
6cb95498fd
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
*.swp
|
||||
vendor
|
||||
|
||||
36
app/app.go
36
app/app.go
@ -3,12 +3,12 @@ package app
|
||||
import (
|
||||
"strings"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
sm "github.com/tendermint/basecoin/state"
|
||||
"github.com/tendermint/basecoin/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
"github.com/tendermint/go-wire"
|
||||
eyes "github.com/tendermint/merkleeyes/client"
|
||||
tmsp "github.com/tendermint/tmsp/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -37,8 +37,8 @@ func NewBasecoin(eyesCli *eyes.Client) *Basecoin {
|
||||
}
|
||||
|
||||
// TMSP::Info
|
||||
func (app *Basecoin) Info() string {
|
||||
return Fmt("Basecoin v%v", version)
|
||||
func (app *Basecoin) Info() abci.ResponseInfo {
|
||||
return abci.ResponseInfo{Data: Fmt("Basecoin v%v", version)}
|
||||
}
|
||||
|
||||
func (app *Basecoin) RegisterPlugin(name string, plugin types.Plugin) {
|
||||
@ -75,38 +75,38 @@ func (app *Basecoin) SetOption(key string, value string) (log string) {
|
||||
}
|
||||
}
|
||||
|
||||
// TMSP::AppendTx
|
||||
func (app *Basecoin) AppendTx(txBytes []byte) (res tmsp.Result) {
|
||||
// TMSP::DeliverTx
|
||||
func (app *Basecoin) DeliverTx(txBytes []byte) (res abci.Result) {
|
||||
if len(txBytes) > maxTxSize {
|
||||
return tmsp.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
|
||||
return abci.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
|
||||
}
|
||||
|
||||
// Decode tx
|
||||
var tx types.Tx
|
||||
err := wire.ReadBinaryBytes(txBytes, &tx)
|
||||
if err != nil {
|
||||
return tmsp.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
|
||||
return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
|
||||
}
|
||||
|
||||
// Validate and exec tx
|
||||
res = sm.ExecTx(app.state, app.plugins, tx, false, nil)
|
||||
if res.IsErr() {
|
||||
return res.PrependLog("Error in AppendTx")
|
||||
return res.PrependLog("Error in DeliverTx")
|
||||
}
|
||||
return tmsp.OK
|
||||
return abci.OK
|
||||
}
|
||||
|
||||
// TMSP::CheckTx
|
||||
func (app *Basecoin) CheckTx(txBytes []byte) (res tmsp.Result) {
|
||||
func (app *Basecoin) CheckTx(txBytes []byte) (res abci.Result) {
|
||||
if len(txBytes) > maxTxSize {
|
||||
return tmsp.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
|
||||
return abci.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
|
||||
}
|
||||
|
||||
// Decode tx
|
||||
var tx types.Tx
|
||||
err := wire.ReadBinaryBytes(txBytes, &tx)
|
||||
if err != nil {
|
||||
return tmsp.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
|
||||
return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
|
||||
}
|
||||
|
||||
// Validate tx
|
||||
@ -114,20 +114,20 @@ func (app *Basecoin) CheckTx(txBytes []byte) (res tmsp.Result) {
|
||||
if res.IsErr() {
|
||||
return res.PrependLog("Error in CheckTx")
|
||||
}
|
||||
return tmsp.OK
|
||||
return abci.OK
|
||||
}
|
||||
|
||||
// TMSP::Query
|
||||
func (app *Basecoin) Query(query []byte) (res tmsp.Result) {
|
||||
func (app *Basecoin) Query(query []byte) (res abci.Result) {
|
||||
if len(query) == 0 {
|
||||
return tmsp.ErrEncodingError.SetLog("Query cannot be zero length")
|
||||
return abci.ErrEncodingError.SetLog("Query cannot be zero length")
|
||||
}
|
||||
|
||||
return app.eyesCli.QuerySync(query)
|
||||
}
|
||||
|
||||
// TMSP::Commit
|
||||
func (app *Basecoin) Commit() (res tmsp.Result) {
|
||||
func (app *Basecoin) Commit() (res abci.Result) {
|
||||
|
||||
// Commit state
|
||||
res = app.state.Commit()
|
||||
@ -142,7 +142,7 @@ func (app *Basecoin) Commit() (res tmsp.Result) {
|
||||
}
|
||||
|
||||
// TMSP::InitChain
|
||||
func (app *Basecoin) InitChain(validators []*tmsp.Validator) {
|
||||
func (app *Basecoin) InitChain(validators []*abci.Validator) {
|
||||
for _, plugin := range app.plugins.GetList() {
|
||||
plugin.Plugin.InitChain(app.state, validators)
|
||||
}
|
||||
@ -156,7 +156,7 @@ func (app *Basecoin) BeginBlock(height uint64) {
|
||||
}
|
||||
|
||||
// TMSP::EndBlock
|
||||
func (app *Basecoin) EndBlock(height uint64) (diffs []*tmsp.Validator) {
|
||||
func (app *Basecoin) EndBlock(height uint64) (diffs []*abci.Validator) {
|
||||
for _, plugin := range app.plugins.GetList() {
|
||||
moreDiffs := plugin.Plugin.EndBlock(app.state, height)
|
||||
diffs = append(diffs, moreDiffs...)
|
||||
|
||||
@ -54,7 +54,7 @@ func TestSendTx(t *testing.T) {
|
||||
|
||||
// Write request
|
||||
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
|
||||
res = bcApp.AppendTx(txBytes)
|
||||
res = bcApp.DeliverTx(txBytes)
|
||||
t.Log(res)
|
||||
if res.IsErr() {
|
||||
t.Errorf(Fmt("Failed: %v", res.Error()))
|
||||
@ -111,9 +111,9 @@ func TestSequence(t *testing.T) {
|
||||
|
||||
// Write request
|
||||
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
|
||||
res := bcApp.AppendTx(txBytes)
|
||||
res := bcApp.DeliverTx(txBytes)
|
||||
if res.IsErr() {
|
||||
t.Errorf("AppendTx error: " + res.Error())
|
||||
t.Errorf("DeliverTx error: " + res.Error())
|
||||
}
|
||||
|
||||
}
|
||||
@ -160,9 +160,9 @@ func TestSequence(t *testing.T) {
|
||||
|
||||
// Write request
|
||||
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
|
||||
res := bcApp.AppendTx(txBytes)
|
||||
res := bcApp.DeliverTx(txBytes)
|
||||
if res.IsErr() {
|
||||
t.Errorf("AppendTx error: " + res.Error())
|
||||
t.Errorf("DeliverTx error: " + res.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,10 +6,10 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/tendermint/abci/server"
|
||||
"github.com/tendermint/basecoin/app"
|
||||
. "github.com/tendermint/go-common"
|
||||
eyes "github.com/tendermint/merkleeyes/client"
|
||||
"github.com/tendermint/tmsp/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
37
glide.lock
generated
37
glide.lock
generated
@ -1,5 +1,5 @@
|
||||
hash: 3550b32be3d9224dd67ec367be27ba3e4c1ca93b3f01d80e08e00e262e9af486
|
||||
updated: 2017-01-11T17:17:20.813714637-05:00
|
||||
hash: e8f0171452f338f27e6f0d4ae47af7d33d7513ec3ecb7e2bceb0bc8721b539ff
|
||||
updated: 2017-01-14T20:35:19.839138786-08:00
|
||||
imports:
|
||||
- name: github.com/btcsuite/btcd
|
||||
version: afec1bd1245a4a19e6dfe1306974b733e7cbb9b8
|
||||
@ -40,13 +40,19 @@ imports:
|
||||
- leveldb/storage
|
||||
- leveldb/table
|
||||
- leveldb/util
|
||||
- name: github.com/tendermint/abci
|
||||
version: 6526ab2137fadd0f4d2e25002bbfc1784b4f3c27
|
||||
subpackages:
|
||||
- client
|
||||
- server
|
||||
- types
|
||||
- name: github.com/tendermint/ed25519
|
||||
version: 1f52c6f8b8a5c7908aff4497c186af344b428925
|
||||
subpackages:
|
||||
- edwards25519
|
||||
- extra25519
|
||||
- name: github.com/tendermint/go-common
|
||||
version: 47e06734f6ee488cc2e61550a38642025e1d4227
|
||||
version: 70e694ee76f09058ea38c9ba81b4aa621bd54df1
|
||||
- name: github.com/tendermint/go-config
|
||||
version: e64b424499acd0eb9856b88e10c0dff41628c0d6
|
||||
- name: github.com/tendermint/go-crypto
|
||||
@ -54,7 +60,7 @@ imports:
|
||||
- name: github.com/tendermint/go-db
|
||||
version: 2645626c33d8702739e52a61a55d705c2dfe4530
|
||||
- name: github.com/tendermint/go-events
|
||||
version: 1c85cb98a4e8ca9e92fe585bc9687fd69b98f841
|
||||
version: 2337086736a6adeb2de6f66739b66ecd77535997
|
||||
- name: github.com/tendermint/go-flowrate
|
||||
version: a20c98e61957faa93b4014fbd902f20ab9317a6a
|
||||
subpackages:
|
||||
@ -68,37 +74,26 @@ imports:
|
||||
subpackages:
|
||||
- upnp
|
||||
- name: github.com/tendermint/go-rpc
|
||||
version: e6e3853dc711b8ad92109cf9ea31319588b94fe0
|
||||
version: 6177eb8398ebd4613fbecb71fd96d7c7d97303ec
|
||||
subpackages:
|
||||
- client
|
||||
- types
|
||||
- name: github.com/tendermint/go-wire
|
||||
version: 3b0adbc86ed8425eaed98516165b6788d9f4de7a
|
||||
- name: github.com/tendermint/governmint
|
||||
version: 0494fad1424082b9d472608a002583bce3076a70
|
||||
subpackages:
|
||||
- gov
|
||||
- types
|
||||
version: 2f3b7aafe21c80b19b6ee3210ecb3e3d07c7a471
|
||||
- name: github.com/tendermint/log15
|
||||
version: 9545b249b3aacafa97f79e0838b02b274adc6f5f
|
||||
subpackages:
|
||||
- term
|
||||
- name: github.com/tendermint/merkleeyes
|
||||
version: 6d5fd62a5783fc87a3b6edcdbc9980ee140a414d
|
||||
version: db66769b34a950bb588919c94925724f21583925
|
||||
subpackages:
|
||||
- app
|
||||
- client
|
||||
- name: github.com/tendermint/tendermint
|
||||
version: 55b47bcb8e2369c49898930bf68bec2c3357409a
|
||||
version: 0aecfe2dae3269a9450b5d8b3bac8721a8dde7c7
|
||||
subpackages:
|
||||
- rpc/core/types
|
||||
- types
|
||||
- name: github.com/tendermint/tmsp
|
||||
version: fe96cfc56da22842c185bd84601b156f8ecee78a
|
||||
subpackages:
|
||||
- client
|
||||
- server
|
||||
- types
|
||||
- name: golang.org/x/crypto
|
||||
version: aa2481cbfe81d911eb62b642b7a6b5ec58bbea71
|
||||
subpackages:
|
||||
@ -124,7 +119,7 @@ imports:
|
||||
subpackages:
|
||||
- unix
|
||||
- name: google.golang.org/grpc
|
||||
version: 28707e14b1d2b2f5da81474dea2790d71e526987
|
||||
version: 50955793b0183f9de69bd78e2ec251cf20aab121
|
||||
subpackages:
|
||||
- codes
|
||||
- credentials
|
||||
@ -133,5 +128,7 @@ imports:
|
||||
- metadata
|
||||
- naming
|
||||
- peer
|
||||
- stats
|
||||
- tap
|
||||
- transport
|
||||
testImports: []
|
||||
|
||||
16
glide.yaml
16
glide.yaml
@ -3,26 +3,30 @@ import:
|
||||
- package: github.com/gorilla/websocket
|
||||
version: v1.1.0
|
||||
- package: github.com/tendermint/go-common
|
||||
version: develop
|
||||
- package: github.com/tendermint/go-crypto
|
||||
version: develop
|
||||
- package: github.com/tendermint/go-events
|
||||
version: develop
|
||||
- package: github.com/tendermint/go-logger
|
||||
version: develop
|
||||
- package: github.com/tendermint/go-rpc
|
||||
version: develop
|
||||
subpackages:
|
||||
- client
|
||||
- types
|
||||
- package: github.com/tendermint/go-wire
|
||||
- package: github.com/tendermint/governmint
|
||||
subpackages:
|
||||
- gov
|
||||
- types
|
||||
version: develop
|
||||
- package: github.com/tendermint/merkleeyes
|
||||
version: develop
|
||||
subpackages:
|
||||
- client
|
||||
- package: github.com/tendermint/tendermint
|
||||
version: ~0.7.4
|
||||
version: develop
|
||||
subpackages:
|
||||
- rpc/core/types
|
||||
- package: github.com/tendermint/tmsp
|
||||
- package: github.com/tendermint/abci
|
||||
version: develop
|
||||
subpackages:
|
||||
- server
|
||||
- types
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package vote
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/abci/types"
|
||||
"github.com/tendermint/basecoin/types"
|
||||
"github.com/tendermint/go-wire"
|
||||
tmsp "github.com/tendermint/tmsp/types"
|
||||
)
|
||||
|
||||
type Vote struct {
|
||||
@ -35,13 +35,13 @@ func (app Vote) SetOption(store types.KVStore, key string, value string) (log st
|
||||
}
|
||||
|
||||
//because no coins are being exchanged ctx is unused
|
||||
func (app Vote) RunTx(store types.KVStore, ctx types.CallContext, txBytes []byte) (res tmsp.Result) {
|
||||
func (app Vote) RunTx(store types.KVStore, ctx types.CallContext, txBytes []byte) (res abci.Result) {
|
||||
|
||||
// Decode tx
|
||||
var tx Tx
|
||||
err := wire.ReadBinaryBytes(txBytes, &tx)
|
||||
if err != nil {
|
||||
return tmsp.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
|
||||
return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
|
||||
}
|
||||
|
||||
//Read the ballotBox from the store
|
||||
@ -52,7 +52,7 @@ func (app Vote) RunTx(store types.KVStore, ctx types.CallContext, txBytes []byte
|
||||
if kvBytes != nil {
|
||||
err := wire.ReadBinaryBytes(kvBytes, &tempBB)
|
||||
if err != nil {
|
||||
return tmsp.ErrBaseEncodingError.AppendLog("Error decoding BallotBox: " + err.Error())
|
||||
return abci.ErrBaseEncodingError.AppendLog("Error decoding BallotBox: " + err.Error())
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -76,17 +76,17 @@ func (app Vote) RunTx(store types.KVStore, ctx types.CallContext, txBytes []byte
|
||||
issueBytes := wire.BinaryBytes(struct{ ballotBox }{tempBB})
|
||||
store.Set([]byte(app.bb.issue), issueBytes)
|
||||
|
||||
return tmsp.OK
|
||||
return abci.OK
|
||||
}
|
||||
|
||||
//unused
|
||||
func (app Vote) InitChain(store types.KVStore, vals []*tmsp.Validator) {
|
||||
func (app Vote) InitChain(store types.KVStore, vals []*abci.Validator) {
|
||||
}
|
||||
|
||||
func (app Vote) BeginBlock(store types.KVStore, height uint64) {
|
||||
}
|
||||
|
||||
func (app Vote) EndBlock(store types.KVStore, height uint64) []*tmsp.Validator {
|
||||
var diffs []*tmsp.Validator
|
||||
func (app Vote) EndBlock(store types.KVStore, height uint64) []*abci.Validator {
|
||||
var diffs []*abci.Validator
|
||||
return diffs
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ func TestVote(t *testing.T) {
|
||||
|
||||
// Write request
|
||||
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
|
||||
res = bcApp.AppendTx(txBytes)
|
||||
res = bcApp.DeliverTx(txBytes)
|
||||
fmt.Println(res)
|
||||
|
||||
if res.IsOK() {
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/abci/types"
|
||||
"github.com/tendermint/basecoin/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
"github.com/tendermint/go-events"
|
||||
tmsp "github.com/tendermint/tmsp/types"
|
||||
)
|
||||
|
||||
// If the tx is invalid, a TMSP error will be returned.
|
||||
func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp.Result {
|
||||
func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc events.Fireable) abci.Result {
|
||||
|
||||
// TODO: do something with fees
|
||||
fees := types.Coins{}
|
||||
@ -47,7 +47,7 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e
|
||||
}
|
||||
outTotal := sumOutputs(tx.Outputs)
|
||||
if !inTotal.IsEqual(outTotal.Plus(types.Coins{{"", tx.Fee}})) {
|
||||
return tmsp.ErrBaseInvalidOutput.AppendLog("Input total != output total + fees")
|
||||
return abci.ErrBaseInvalidOutput.AppendLog("Input total != output total + fees")
|
||||
}
|
||||
fees = fees.Plus(types.Coins{{"", tx.Fee}})
|
||||
|
||||
@ -71,7 +71,7 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e
|
||||
}
|
||||
*/
|
||||
|
||||
return tmsp.OK
|
||||
return abci.OK
|
||||
|
||||
case *types.AppTx:
|
||||
// Validate input, basic
|
||||
@ -83,7 +83,7 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e
|
||||
// Get input account
|
||||
inAcc := state.GetAccount(tx.Input.Address)
|
||||
if inAcc == nil {
|
||||
return tmsp.ErrBaseUnknownAddress
|
||||
return abci.ErrBaseUnknownAddress
|
||||
}
|
||||
if tx.Input.PubKey != nil {
|
||||
inAcc.PubKey = tx.Input.PubKey
|
||||
@ -98,13 +98,13 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e
|
||||
}
|
||||
if !tx.Input.Coins.IsGTE(types.Coins{{"", tx.Fee}}) {
|
||||
log.Info(Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address))
|
||||
return tmsp.ErrBaseInsufficientFunds
|
||||
return abci.ErrBaseInsufficientFunds
|
||||
}
|
||||
|
||||
// Validate call address
|
||||
plugin := pgz.GetByName(tx.Name)
|
||||
if plugin == nil {
|
||||
return tmsp.ErrBaseUnknownAddress.AppendLog(
|
||||
return abci.ErrBaseUnknownAddress.AppendLog(
|
||||
Fmt("Unrecognized plugin name%v", tx.Name))
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e
|
||||
// If this is a CheckTx, stop now.
|
||||
if isCheckTx {
|
||||
state.SetAccount(tx.Input.Address, inAcc)
|
||||
return tmsp.OK
|
||||
return abci.OK
|
||||
}
|
||||
|
||||
// Create inAcc checkpoint
|
||||
@ -153,7 +153,7 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e
|
||||
return res
|
||||
|
||||
default:
|
||||
return tmsp.ErrBaseEncodingError.SetLog("Unknown tx type")
|
||||
return abci.ErrBaseEncodingError.SetLog("Unknown tx type")
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,17 +162,17 @@ func ExecTx(state *State, pgz *types.Plugins, tx types.Tx, isCheckTx bool, evc e
|
||||
// The accounts from the TxInputs must either already have
|
||||
// crypto.PubKey.(type) != nil, (it must be known),
|
||||
// or it must be specified in the TxInput.
|
||||
func getInputs(state types.AccountGetter, ins []types.TxInput) (map[string]*types.Account, tmsp.Result) {
|
||||
func getInputs(state types.AccountGetter, ins []types.TxInput) (map[string]*types.Account, abci.Result) {
|
||||
accounts := map[string]*types.Account{}
|
||||
for _, in := range ins {
|
||||
// Account shouldn't be duplicated
|
||||
if _, ok := accounts[string(in.Address)]; ok {
|
||||
return nil, tmsp.ErrBaseDuplicateAddress
|
||||
return nil, abci.ErrBaseDuplicateAddress
|
||||
}
|
||||
|
||||
acc := state.GetAccount(in.Address)
|
||||
if acc == nil {
|
||||
return nil, tmsp.ErrBaseUnknownAddress
|
||||
return nil, abci.ErrBaseUnknownAddress
|
||||
}
|
||||
|
||||
if in.PubKey != nil {
|
||||
@ -180,10 +180,10 @@ func getInputs(state types.AccountGetter, ins []types.TxInput) (map[string]*type
|
||||
}
|
||||
accounts[string(in.Address)] = acc
|
||||
}
|
||||
return accounts, tmsp.OK
|
||||
return accounts, abci.OK
|
||||
}
|
||||
|
||||
func getOrMakeOutputs(state types.AccountGetter, accounts map[string]*types.Account, outs []types.TxOutput) (map[string]*types.Account, tmsp.Result) {
|
||||
func getOrMakeOutputs(state types.AccountGetter, accounts map[string]*types.Account, outs []types.TxOutput) (map[string]*types.Account, abci.Result) {
|
||||
if accounts == nil {
|
||||
accounts = make(map[string]*types.Account)
|
||||
}
|
||||
@ -191,7 +191,7 @@ func getOrMakeOutputs(state types.AccountGetter, accounts map[string]*types.Acco
|
||||
for _, out := range outs {
|
||||
// Account shouldn't be duplicated
|
||||
if _, ok := accounts[string(out.Address)]; ok {
|
||||
return nil, tmsp.ErrBaseDuplicateAddress
|
||||
return nil, abci.ErrBaseDuplicateAddress
|
||||
}
|
||||
acc := state.GetAccount(out.Address)
|
||||
// output account may be nil (new)
|
||||
@ -203,22 +203,22 @@ func getOrMakeOutputs(state types.AccountGetter, accounts map[string]*types.Acco
|
||||
}
|
||||
accounts[string(out.Address)] = acc
|
||||
}
|
||||
return accounts, tmsp.OK
|
||||
return accounts, abci.OK
|
||||
}
|
||||
|
||||
// Validate inputs basic structure
|
||||
func validateInputsBasic(ins []types.TxInput) (res tmsp.Result) {
|
||||
func validateInputsBasic(ins []types.TxInput) (res abci.Result) {
|
||||
for _, in := range ins {
|
||||
// Check TxInput basic
|
||||
if res := in.ValidateBasic(); res.IsErr() {
|
||||
return res
|
||||
}
|
||||
}
|
||||
return tmsp.OK
|
||||
return abci.OK
|
||||
}
|
||||
|
||||
// Validate inputs and compute total amount of coins
|
||||
func validateInputsAdvanced(accounts map[string]*types.Account, signBytes []byte, ins []types.TxInput) (total types.Coins, res tmsp.Result) {
|
||||
func validateInputsAdvanced(accounts map[string]*types.Account, signBytes []byte, ins []types.TxInput) (total types.Coins, res abci.Result) {
|
||||
for _, in := range ins {
|
||||
acc := accounts[string(in.Address)]
|
||||
if acc == nil {
|
||||
@ -231,34 +231,34 @@ func validateInputsAdvanced(accounts map[string]*types.Account, signBytes []byte
|
||||
// Good. Add amount to total
|
||||
total = total.Plus(in.Coins)
|
||||
}
|
||||
return total, tmsp.OK
|
||||
return total, abci.OK
|
||||
}
|
||||
|
||||
func validateInputAdvanced(acc *types.Account, signBytes []byte, in types.TxInput) (res tmsp.Result) {
|
||||
func validateInputAdvanced(acc *types.Account, signBytes []byte, in types.TxInput) (res abci.Result) {
|
||||
// Check sequence/coins
|
||||
seq, balance := acc.Sequence, acc.Balance
|
||||
if seq+1 != in.Sequence {
|
||||
return tmsp.ErrBaseInvalidSequence.AppendLog(Fmt("Got %v, expected %v. (acc.seq=%v)", in.Sequence, seq+1, acc.Sequence))
|
||||
return abci.ErrBaseInvalidSequence.AppendLog(Fmt("Got %v, expected %v. (acc.seq=%v)", in.Sequence, seq+1, acc.Sequence))
|
||||
}
|
||||
// Check amount
|
||||
if !balance.IsGTE(in.Coins) {
|
||||
return tmsp.ErrBaseInsufficientFunds
|
||||
return abci.ErrBaseInsufficientFunds
|
||||
}
|
||||
// Check signatures
|
||||
if !acc.PubKey.VerifyBytes(signBytes, in.Signature) {
|
||||
return tmsp.ErrBaseInvalidSignature.AppendLog(Fmt("SignBytes: %X", signBytes))
|
||||
return abci.ErrBaseInvalidSignature.AppendLog(Fmt("SignBytes: %X", signBytes))
|
||||
}
|
||||
return tmsp.OK
|
||||
return abci.OK
|
||||
}
|
||||
|
||||
func validateOutputsBasic(outs []types.TxOutput) (res tmsp.Result) {
|
||||
func validateOutputsBasic(outs []types.TxOutput) (res abci.Result) {
|
||||
for _, out := range outs {
|
||||
// Check TxOutput basic
|
||||
if res := out.ValidateBasic(); res.IsErr() {
|
||||
return res
|
||||
}
|
||||
}
|
||||
return tmsp.OK
|
||||
return abci.OK
|
||||
}
|
||||
|
||||
func sumOutputs(outs []types.TxOutput) (total types.Coins) {
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/abci/types"
|
||||
"github.com/tendermint/basecoin/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
"github.com/tendermint/go-wire"
|
||||
eyes "github.com/tendermint/merkleeyes/client"
|
||||
tmsp "github.com/tendermint/tmsp/types"
|
||||
)
|
||||
|
||||
// CONTRACT: State should be quick to copy.
|
||||
@ -77,7 +77,7 @@ func (s *State) CacheSync() {
|
||||
s.writeCache.Sync()
|
||||
}
|
||||
|
||||
func (s *State) Commit() tmsp.Result {
|
||||
func (s *State) Commit() abci.Result {
|
||||
s.readCache = make(map[string][]byte)
|
||||
return s.store.(*eyes.Client).CommitSync()
|
||||
}
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
tmsp "github.com/tendermint/tmsp/types"
|
||||
abci "github.com/tendermint/abci/types"
|
||||
)
|
||||
|
||||
type Plugin interface {
|
||||
SetOption(store KVStore, key string, value string) (log string)
|
||||
RunTx(store KVStore, ctx CallContext, txBytes []byte) (res tmsp.Result)
|
||||
InitChain(store KVStore, vals []*tmsp.Validator)
|
||||
RunTx(store KVStore, ctx CallContext, txBytes []byte) (res abci.Result)
|
||||
InitChain(store KVStore, vals []*abci.Validator)
|
||||
BeginBlock(store KVStore, height uint64)
|
||||
EndBlock(store KVStore, height uint64) []*tmsp.Validator
|
||||
EndBlock(store KVStore, height uint64) []*abci.Validator
|
||||
}
|
||||
|
||||
type NamedPlugin struct {
|
||||
|
||||
28
types/tx.go
28
types/tx.go
@ -4,10 +4,10 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
"github.com/tendermint/go-crypto"
|
||||
"github.com/tendermint/go-wire"
|
||||
tmsp "github.com/tendermint/tmsp/types"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -49,26 +49,26 @@ type TxInput struct {
|
||||
PubKey crypto.PubKey `json:"pub_key"` // Is present iff Sequence == 0
|
||||
}
|
||||
|
||||
func (txIn TxInput) ValidateBasic() tmsp.Result {
|
||||
func (txIn TxInput) ValidateBasic() abci.Result {
|
||||
if len(txIn.Address) != 20 {
|
||||
return tmsp.ErrBaseInvalidInput.AppendLog("Invalid address length")
|
||||
return abci.ErrBaseInvalidInput.AppendLog("Invalid address length")
|
||||
}
|
||||
if !txIn.Coins.IsValid() {
|
||||
return tmsp.ErrBaseInvalidInput.AppendLog(Fmt("Invalid coins %v", txIn.Coins))
|
||||
return abci.ErrBaseInvalidInput.AppendLog(Fmt("Invalid coins %v", txIn.Coins))
|
||||
}
|
||||
if txIn.Coins.IsZero() {
|
||||
return tmsp.ErrBaseInvalidInput.AppendLog("Coins cannot be zero")
|
||||
return abci.ErrBaseInvalidInput.AppendLog("Coins cannot be zero")
|
||||
}
|
||||
if txIn.Sequence <= 0 {
|
||||
return tmsp.ErrBaseInvalidInput.AppendLog("Sequence must be greater than 0")
|
||||
return abci.ErrBaseInvalidInput.AppendLog("Sequence must be greater than 0")
|
||||
}
|
||||
if txIn.Sequence == 1 && txIn.PubKey == nil {
|
||||
return tmsp.ErrBaseInvalidInput.AppendLog("PubKey must be present when Sequence == 1")
|
||||
return abci.ErrBaseInvalidInput.AppendLog("PubKey must be present when Sequence == 1")
|
||||
}
|
||||
if txIn.Sequence > 1 && txIn.PubKey != nil {
|
||||
return tmsp.ErrBaseInvalidInput.AppendLog("PubKey must be nil when Sequence > 1")
|
||||
return abci.ErrBaseInvalidInput.AppendLog("PubKey must be nil when Sequence > 1")
|
||||
}
|
||||
return tmsp.OK
|
||||
return abci.OK
|
||||
}
|
||||
|
||||
func (txIn TxInput) String() string {
|
||||
@ -82,17 +82,17 @@ type TxOutput struct {
|
||||
Coins Coins `json:"coins"` //
|
||||
}
|
||||
|
||||
func (txOut TxOutput) ValidateBasic() tmsp.Result {
|
||||
func (txOut TxOutput) ValidateBasic() abci.Result {
|
||||
if len(txOut.Address) != 20 {
|
||||
return tmsp.ErrBaseInvalidOutput.AppendLog("Invalid address length")
|
||||
return abci.ErrBaseInvalidOutput.AppendLog("Invalid address length")
|
||||
}
|
||||
if !txOut.Coins.IsValid() {
|
||||
return tmsp.ErrBaseInvalidOutput.AppendLog(Fmt("Invalid coins %v", txOut.Coins))
|
||||
return abci.ErrBaseInvalidOutput.AppendLog(Fmt("Invalid coins %v", txOut.Coins))
|
||||
}
|
||||
if txOut.Coins.IsZero() {
|
||||
return tmsp.ErrBaseInvalidOutput.AppendLog("Coins cannot be zero")
|
||||
return abci.ErrBaseInvalidOutput.AppendLog("Coins cannot be zero")
|
||||
}
|
||||
return tmsp.OK
|
||||
return abci.OK
|
||||
}
|
||||
|
||||
func (txOut TxOutput) String() string {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user