Commit returns tmsp.Result; Move errors to tmsp/errors.go
This commit is contained in:
parent
4810acbd9d
commit
ed9dd875a7
36
app/app.go
36
app/app.go
|
@ -59,58 +59,58 @@ func (app *Basecoin) SetOption(key string, value string) (log string) {
|
||||||
// TMSP::AppendTx
|
// TMSP::AppendTx
|
||||||
func (app *Basecoin) AppendTx(txBytes []byte) (res tmsp.Result) {
|
func (app *Basecoin) AppendTx(txBytes []byte) (res tmsp.Result) {
|
||||||
if len(txBytes) > maxTxSize {
|
if len(txBytes) > maxTxSize {
|
||||||
return types.ErrEncodingError.AppendLog("Tx size exceeds maximum")
|
return tmsp.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
|
||||||
}
|
}
|
||||||
// Decode tx
|
// Decode tx
|
||||||
var tx types.Tx
|
var tx types.Tx
|
||||||
err := wire.ReadBinaryBytes(txBytes, &tx)
|
err := wire.ReadBinaryBytes(txBytes, &tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ErrEncodingError.AppendLog("Error decoding tx: " + err.Error())
|
return tmsp.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
|
||||||
}
|
}
|
||||||
// Validate and exec tx
|
// Validate and exec tx
|
||||||
res = state.ExecTx(app.state, tx, false, nil)
|
res = state.ExecTx(app.state, tx, false, nil)
|
||||||
if !res.IsOK() {
|
if res.IsErr() {
|
||||||
return res.PrependLog("Error in AppendTx")
|
return res.PrependLog("Error in AppendTx")
|
||||||
}
|
}
|
||||||
return types.ResultOK
|
return tmsp.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
// TMSP::CheckTx
|
// TMSP::CheckTx
|
||||||
func (app *Basecoin) CheckTx(txBytes []byte) (res tmsp.Result) {
|
func (app *Basecoin) CheckTx(txBytes []byte) (res tmsp.Result) {
|
||||||
if len(txBytes) > maxTxSize {
|
if len(txBytes) > maxTxSize {
|
||||||
return types.ErrEncodingError.AppendLog("Tx size exceeds maximum")
|
return tmsp.ErrBaseEncodingError.AppendLog("Tx size exceeds maximum")
|
||||||
}
|
}
|
||||||
// Decode tx
|
// Decode tx
|
||||||
var tx types.Tx
|
var tx types.Tx
|
||||||
err := wire.ReadBinaryBytes(txBytes, &tx)
|
err := wire.ReadBinaryBytes(txBytes, &tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ErrEncodingError.AppendLog("Error decoding tx: " + err.Error())
|
return tmsp.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
|
||||||
}
|
}
|
||||||
// Validate tx
|
// Validate tx
|
||||||
res = state.ExecTx(app.state, tx, true, nil)
|
res = state.ExecTx(app.state, tx, true, nil)
|
||||||
if !res.IsOK() {
|
if res.IsErr() {
|
||||||
return res.PrependLog("Error in CheckTx")
|
return res.PrependLog("Error in CheckTx")
|
||||||
}
|
}
|
||||||
return types.ResultOK
|
return tmsp.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
// TMSP::Query
|
// TMSP::Query
|
||||||
func (app *Basecoin) Query(query []byte) (res tmsp.Result) {
|
func (app *Basecoin) Query(query []byte) (res tmsp.Result) {
|
||||||
return types.ResultOK
|
return tmsp.OK
|
||||||
value, err := app.eyesCli.GetSync(query)
|
res = app.eyesCli.GetSync(query)
|
||||||
if err != nil {
|
if res.IsErr() {
|
||||||
panic("Error making query: " + err.Error())
|
return res.PrependLog("Error querying eyesCli")
|
||||||
}
|
}
|
||||||
return types.ResultOK.SetData(value).SetLog("Success")
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// TMSP::Commit
|
// TMSP::Commit
|
||||||
func (app *Basecoin) Commit() (hash []byte, log string) {
|
func (app *Basecoin) Commit() (res tmsp.Result) {
|
||||||
hash, log, err := app.eyesCli.CommitSync()
|
res = app.eyesCli.CommitSync()
|
||||||
if err != nil {
|
if res.IsErr() {
|
||||||
panic("Error getting hash: " + err.Error())
|
panic("Error getting hash: " + res.Error())
|
||||||
}
|
}
|
||||||
return hash, "Success"
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// TMSP::InitChain
|
// TMSP::InitChain
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/tendermint/basecoin/tests"
|
||||||
|
"github.com/tendermint/go-wire"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
PrivKey: 019F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A0867D3B5EAF0C0BF6B5A602D359DAECC86A7A74053490EC37AE08E71360587C870
|
||||||
|
PubKey: 0167D3B5EAF0C0BF6B5A602D359DAECC86A7A74053490EC37AE08E71360587C870
|
||||||
|
Address: D9B727742AA29FA638DC63D70813C976014C4CE0
|
||||||
|
*/
|
||||||
|
func main() {
|
||||||
|
tAcc := tests.PrivAccountFromSecret("test")
|
||||||
|
fmt.Println("PrivKey:", fmt.Sprintf("%X", tAcc.PrivKey.Bytes()))
|
||||||
|
fmt.Println("PubKey:", fmt.Sprintf("%X", tAcc.Account.PubKey.Bytes()))
|
||||||
|
fmt.Println("Address:", fmt.Sprintf("%X", tAcc.Account.PubKey.Address()))
|
||||||
|
fmt.Println(string(wire.JSONBytesPretty(tAcc)))
|
||||||
|
}
|
|
@ -21,28 +21,28 @@ func ExecTx(state *State, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp
|
||||||
case *types.SendTx:
|
case *types.SendTx:
|
||||||
// First, get inputs
|
// First, get inputs
|
||||||
accounts, res := getInputs(state, tx.Inputs)
|
accounts, res := getInputs(state, tx.Inputs)
|
||||||
if !res.IsOK() {
|
if res.IsErr() {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then, get or make outputs.
|
// Then, get or make outputs.
|
||||||
accounts, res = getOrMakeOutputs(state, accounts, tx.Outputs)
|
accounts, res = getOrMakeOutputs(state, accounts, tx.Outputs)
|
||||||
if !res.IsOK() {
|
if res.IsErr() {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate inputs and outputs
|
// Validate inputs and outputs
|
||||||
signBytes := tx.SignBytes(state.GetChainID())
|
signBytes := tx.SignBytes(state.GetChainID())
|
||||||
inTotal, res := validateInputs(state, accounts, signBytes, tx.Inputs)
|
inTotal, res := validateInputs(state, accounts, signBytes, tx.Inputs)
|
||||||
if !res.IsOK() {
|
if res.IsErr() {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
outTotal, res := validateOutputs(tx.Outputs)
|
outTotal, res := validateOutputs(tx.Outputs)
|
||||||
if !res.IsOK() {
|
if res.IsErr() {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
if outTotal > inTotal {
|
if outTotal > inTotal {
|
||||||
return types.ErrInsufficientFunds
|
return tmsp.ErrBaseInsufficientFunds
|
||||||
}
|
}
|
||||||
fee := inTotal - outTotal
|
fee := inTotal - outTotal
|
||||||
fees += fee
|
fees += fee
|
||||||
|
@ -67,38 +67,38 @@ func ExecTx(state *State, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return types.ResultOK
|
return tmsp.OK
|
||||||
|
|
||||||
case *types.CallTx:
|
case *types.CallTx:
|
||||||
// First, get input account
|
// First, get input account
|
||||||
inAcc := state.GetAccount(tx.Input.Address)
|
inAcc := state.GetAccount(tx.Input.Address)
|
||||||
if inAcc == nil {
|
if inAcc == nil {
|
||||||
log.Info(Fmt("Can't find in account %X", tx.Input.Address))
|
log.Info(Fmt("Can't find in account %X", tx.Input.Address))
|
||||||
return types.ErrInvalidAddress
|
return tmsp.ErrBaseInvalidAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate input
|
// Validate input
|
||||||
// pubKey should be present in either "inAcc" or "tx.Input"
|
// pubKey should be present in either "inAcc" or "tx.Input"
|
||||||
if res := checkInputPubKey(tx.Input.Address, inAcc, tx.Input); !res.IsOK() {
|
if res := checkInputPubKey(tx.Input.Address, inAcc, tx.Input); res.IsErr() {
|
||||||
log.Info(Fmt("Can't find pubkey for %X", tx.Input.Address))
|
log.Info(Fmt("Can't find pubkey for %X", tx.Input.Address))
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
signBytes := tx.SignBytes(state.GetChainID())
|
signBytes := tx.SignBytes(state.GetChainID())
|
||||||
res := validateInput(state, inAcc, signBytes, tx.Input)
|
res := validateInput(state, inAcc, signBytes, tx.Input)
|
||||||
if !res.IsOK() {
|
if res.IsErr() {
|
||||||
log.Info(Fmt("validateInput failed on %X: %v", tx.Input.Address, res))
|
log.Info(Fmt("validateInput failed on %X: %v", tx.Input.Address, res))
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
if tx.Input.Amount < tx.Fee {
|
if tx.Input.Amount < tx.Fee {
|
||||||
log.Info(Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address))
|
log.Info(Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address))
|
||||||
return types.ErrInsufficientFunds
|
return tmsp.ErrBaseInsufficientFunds
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate call address
|
// Validate call address
|
||||||
if strings.HasPrefix(string(tx.Address), "gov/") {
|
if strings.HasPrefix(string(tx.Address), "gov/") {
|
||||||
// This is a gov call.
|
// This is a gov call.
|
||||||
} else {
|
} else {
|
||||||
return types.ErrInvalidAddress.AppendLog(Fmt("Unrecognized address %X", tx.Address))
|
return tmsp.ErrBaseInvalidAddress.AppendLog(Fmt("Unrecognized address %X", tx.Address))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Good!
|
// Good!
|
||||||
|
@ -121,7 +121,7 @@ func ExecTx(state *State, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp
|
||||||
/*
|
/*
|
||||||
if evc != nil {
|
if evc != nil {
|
||||||
exception := ""
|
exception := ""
|
||||||
if !res.IsOK() {
|
if res.IsErr() {
|
||||||
exception = res.Error()
|
exception = res.Error()
|
||||||
}
|
}
|
||||||
evc.FireEvent(types.EventStringAccInput(tx.Input.Address), types.EventDataTx{tx, ret, exception})
|
evc.FireEvent(types.EventStringAccInput(tx.Input.Address), types.EventDataTx{tx, ret, exception})
|
||||||
|
@ -130,10 +130,10 @@ func ExecTx(state *State, tx types.Tx, isCheckTx bool, evc events.Fireable) tmsp
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return types.ResultOK
|
return tmsp.OK
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return types.ErrEncodingError.SetLog("Unknown tx type")
|
return tmsp.ErrBaseEncodingError.SetLog("Unknown tx type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,19 +148,19 @@ func getInputs(state types.AccountGetter, ins []types.TxInput) (map[string]*type
|
||||||
for _, in := range ins {
|
for _, in := range ins {
|
||||||
// Account shouldn't be duplicated
|
// Account shouldn't be duplicated
|
||||||
if _, ok := accounts[string(in.Address)]; ok {
|
if _, ok := accounts[string(in.Address)]; ok {
|
||||||
return nil, types.ErrDuplicateAddress
|
return nil, tmsp.ErrBaseDuplicateAddress
|
||||||
}
|
}
|
||||||
acc := state.GetAccount(in.Address)
|
acc := state.GetAccount(in.Address)
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
return nil, types.ErrInvalidAddress
|
return nil, tmsp.ErrBaseInvalidAddress
|
||||||
}
|
}
|
||||||
// PubKey should be present in either "account" or "in"
|
// PubKey should be present in either "account" or "in"
|
||||||
if res := checkInputPubKey(in.Address, acc, in); !res.IsOK() {
|
if res := checkInputPubKey(in.Address, acc, in); res.IsErr() {
|
||||||
return nil, res
|
return nil, res
|
||||||
}
|
}
|
||||||
accounts[string(in.Address)] = acc
|
accounts[string(in.Address)] = acc
|
||||||
}
|
}
|
||||||
return accounts, types.ResultOK
|
return accounts, tmsp.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, tmsp.Result) {
|
||||||
|
@ -171,7 +171,7 @@ func getOrMakeOutputs(state types.AccountGetter, accounts map[string]*types.Acco
|
||||||
for _, out := range outs {
|
for _, out := range outs {
|
||||||
// Account shouldn't be duplicated
|
// Account shouldn't be duplicated
|
||||||
if _, ok := accounts[string(out.Address)]; ok {
|
if _, ok := accounts[string(out.Address)]; ok {
|
||||||
return nil, types.ErrDuplicateAddress
|
return nil, tmsp.ErrBaseDuplicateAddress
|
||||||
}
|
}
|
||||||
acc := state.GetAccount(out.Address)
|
acc := state.GetAccount(out.Address)
|
||||||
// output account may be nil (new)
|
// output account may be nil (new)
|
||||||
|
@ -184,7 +184,7 @@ func getOrMakeOutputs(state types.AccountGetter, accounts map[string]*types.Acco
|
||||||
}
|
}
|
||||||
accounts[string(out.Address)] = acc
|
accounts[string(out.Address)] = acc
|
||||||
}
|
}
|
||||||
return accounts, types.ResultOK
|
return accounts, tmsp.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input must not have a redundant PubKey (i.e. Account already has PubKey).
|
// Input must not have a redundant PubKey (i.e. Account already has PubKey).
|
||||||
|
@ -192,18 +192,18 @@ func getOrMakeOutputs(state types.AccountGetter, accounts map[string]*types.Acco
|
||||||
func checkInputPubKey(address []byte, acc *types.Account, in types.TxInput) tmsp.Result {
|
func checkInputPubKey(address []byte, acc *types.Account, in types.TxInput) tmsp.Result {
|
||||||
if acc.PubKey == nil {
|
if acc.PubKey == nil {
|
||||||
if in.PubKey == nil {
|
if in.PubKey == nil {
|
||||||
return types.ErrUnknownPubKey
|
return tmsp.ErrBaseUnknownPubKey
|
||||||
}
|
}
|
||||||
if !bytes.Equal(in.PubKey.Address(), address) {
|
if !bytes.Equal(in.PubKey.Address(), address) {
|
||||||
return types.ErrInvalidPubKey
|
return tmsp.ErrBaseInvalidPubKey
|
||||||
}
|
}
|
||||||
acc.PubKey = in.PubKey
|
acc.PubKey = in.PubKey
|
||||||
} else {
|
} else {
|
||||||
if in.PubKey != nil {
|
if in.PubKey != nil {
|
||||||
return types.ErrInvalidPubKey
|
return tmsp.ErrBaseInvalidPubKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return types.ResultOK
|
return tmsp.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate inputs and compute total amount
|
// Validate inputs and compute total amount
|
||||||
|
@ -215,46 +215,46 @@ func validateInputs(state *State, accounts map[string]*types.Account, signBytes
|
||||||
PanicSanity("validateInputs() expects account in accounts")
|
PanicSanity("validateInputs() expects account in accounts")
|
||||||
}
|
}
|
||||||
res = validateInput(state, acc, signBytes, in)
|
res = validateInput(state, acc, signBytes, in)
|
||||||
if !res.IsOK() {
|
if res.IsErr() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Good. Add amount to total
|
// Good. Add amount to total
|
||||||
total += in.Amount
|
total += in.Amount
|
||||||
}
|
}
|
||||||
return total, types.ResultOK
|
return total, tmsp.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateInput(state *State, acc *types.Account, signBytes []byte, in types.TxInput) (res tmsp.Result) {
|
func validateInput(state *State, acc *types.Account, signBytes []byte, in types.TxInput) (res tmsp.Result) {
|
||||||
// Check TxInput basic
|
// Check TxInput basic
|
||||||
if res := in.ValidateBasic(); !res.IsOK() {
|
if res := in.ValidateBasic(); res.IsErr() {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
// Check sequence/balance
|
// Check sequence/balance
|
||||||
seq, balance := state.GetCheckAccount(in.Address, acc.Sequence, acc.Balance)
|
seq, balance := state.GetCheckAccount(in.Address, acc.Sequence, acc.Balance)
|
||||||
if seq+1 != in.Sequence {
|
if seq+1 != in.Sequence {
|
||||||
return types.ErrInvalidSequence.AppendLog(Fmt("Got %v, expected %v. (acc.seq=%v)", in.Sequence, seq+1, acc.Sequence))
|
return tmsp.ErrBaseInvalidSequence.AppendLog(Fmt("Got %v, expected %v. (acc.seq=%v)", in.Sequence, seq+1, acc.Sequence))
|
||||||
}
|
}
|
||||||
// Check amount
|
// Check amount
|
||||||
if balance < in.Amount {
|
if balance < in.Amount {
|
||||||
return types.ErrInsufficientFunds
|
return tmsp.ErrBaseInsufficientFunds
|
||||||
}
|
}
|
||||||
// Check signatures
|
// Check signatures
|
||||||
if !acc.PubKey.VerifyBytes(signBytes, in.Signature) {
|
if !acc.PubKey.VerifyBytes(signBytes, in.Signature) {
|
||||||
return types.ErrInvalidSignature
|
return tmsp.ErrBaseInvalidSignature
|
||||||
}
|
}
|
||||||
return types.ResultOK
|
return tmsp.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateOutputs(outs []types.TxOutput) (total int64, res tmsp.Result) {
|
func validateOutputs(outs []types.TxOutput) (total int64, res tmsp.Result) {
|
||||||
for _, out := range outs {
|
for _, out := range outs {
|
||||||
// Check TxOutput basic
|
// Check TxOutput basic
|
||||||
if res := out.ValidateBasic(); !res.IsOK() {
|
if res := out.ValidateBasic(); res.IsErr() {
|
||||||
return 0, res
|
return 0, res
|
||||||
}
|
}
|
||||||
// Good. Add amount to total
|
// Good. Add amount to total
|
||||||
total += out.Amount
|
total += out.Amount
|
||||||
}
|
}
|
||||||
return total, types.ResultOK
|
return total, tmsp.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
func adjustByInputs(state *State, accounts map[string]*types.Account, ins []types.TxInput, isCheckTx bool) {
|
func adjustByInputs(state *State, accounts map[string]*types.Account, ins []types.TxInput, isCheckTx bool) {
|
||||||
|
|
|
@ -64,15 +64,15 @@ func (s *State) ResetCacheState() {
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
func (s *State) GetAccount(addr []byte) *types.Account {
|
func (s *State) GetAccount(addr []byte) *types.Account {
|
||||||
accBytes, err := s.eyesCli.GetSync(addr)
|
res := s.eyesCli.GetSync(addr)
|
||||||
if err != nil {
|
if res.IsErr() {
|
||||||
panic("Error loading account: " + err.Error())
|
panic("Error loading account: " + res.Error())
|
||||||
}
|
}
|
||||||
if len(accBytes) == 0 {
|
if len(res.Data) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var acc types.Account
|
var acc types.Account
|
||||||
err = wire.ReadBinaryBytes(accBytes, &acc)
|
err := wire.ReadBinaryBytes(res.Data, &acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Error reading account: " + err.Error())
|
panic("Error reading account: " + err.Error())
|
||||||
}
|
}
|
||||||
|
@ -81,8 +81,8 @@ func (s *State) GetAccount(addr []byte) *types.Account {
|
||||||
|
|
||||||
func (s *State) SetAccount(acc *types.Account) {
|
func (s *State) SetAccount(acc *types.Account) {
|
||||||
accBytes := wire.BinaryBytes(acc)
|
accBytes := wire.BinaryBytes(acc)
|
||||||
err := s.eyesCli.SetSync(acc.PubKey.Address(), accBytes)
|
res := s.eyesCli.SetSync(acc.PubKey.Address(), accBytes)
|
||||||
if err != nil {
|
if res.IsErr() {
|
||||||
panic("Error storing account: " + err.Error())
|
panic("Error storing account: " + res.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
tmsp "github.com/tendermint/tmsp/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrInternalError = tmsp.NewError(tmsp.CodeType_InternalError, "Internal error")
|
|
||||||
ErrDuplicateAddress = tmsp.NewError(tmsp.CodeType_BaseDuplicateAddress, "Error duplicate address")
|
|
||||||
ErrEncodingError = tmsp.NewError(tmsp.CodeType_BaseEncodingError, "Error encoding error")
|
|
||||||
ErrInsufficientFees = tmsp.NewError(tmsp.CodeType_BaseInsufficientFees, "Error insufficient fees")
|
|
||||||
ErrInsufficientFunds = tmsp.NewError(tmsp.CodeType_BaseInsufficientFunds, "Error insufficient funds")
|
|
||||||
ErrInsufficientGasPrice = tmsp.NewError(tmsp.CodeType_BaseInsufficientGasPrice, "Error insufficient gas price")
|
|
||||||
ErrInvalidAddress = tmsp.NewError(tmsp.CodeType_BaseInvalidAddress, "Error invalid address")
|
|
||||||
ErrInvalidAmount = tmsp.NewError(tmsp.CodeType_BaseInvalidAmount, "Error invalid amount")
|
|
||||||
ErrInvalidPubKey = tmsp.NewError(tmsp.CodeType_BaseInvalidPubKey, "Error invalid pubkey")
|
|
||||||
ErrInvalidSequence = tmsp.NewError(tmsp.CodeType_BaseInvalidSequence, "Error invalid sequence")
|
|
||||||
ErrInvalidSignature = tmsp.NewError(tmsp.CodeType_BaseInvalidSignature, "Error invalid signature")
|
|
||||||
ErrUnknownPubKey = tmsp.NewError(tmsp.CodeType_BaseUnknownPubKey, "Error unknown pubkey")
|
|
||||||
|
|
||||||
ResultOK = tmsp.NewResultOK(nil, "")
|
|
||||||
)
|
|
12
types/tx.go
12
types/tx.go
|
@ -48,12 +48,12 @@ type TxInput struct {
|
||||||
|
|
||||||
func (txIn TxInput) ValidateBasic() tmsp.Result {
|
func (txIn TxInput) ValidateBasic() tmsp.Result {
|
||||||
if len(txIn.Address) != 20 {
|
if len(txIn.Address) != 20 {
|
||||||
return ErrInvalidAddress
|
return tmsp.ErrBaseInvalidAddress
|
||||||
}
|
}
|
||||||
if txIn.Amount == 0 {
|
if txIn.Amount == 0 {
|
||||||
return ErrInvalidAmount
|
return tmsp.ErrBaseInvalidAmount
|
||||||
}
|
}
|
||||||
return ResultOK
|
return tmsp.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
func (txIn TxInput) SignBytes() []byte {
|
func (txIn TxInput) SignBytes() []byte {
|
||||||
|
@ -74,12 +74,12 @@ type TxOutput struct {
|
||||||
|
|
||||||
func (txOut TxOutput) ValidateBasic() tmsp.Result {
|
func (txOut TxOutput) ValidateBasic() tmsp.Result {
|
||||||
if len(txOut.Address) != 20 {
|
if len(txOut.Address) != 20 {
|
||||||
return ErrInvalidAddress
|
return tmsp.ErrBaseInvalidAddress
|
||||||
}
|
}
|
||||||
if txOut.Amount == 0 {
|
if txOut.Amount == 0 {
|
||||||
return ErrInvalidAmount
|
return tmsp.ErrBaseInvalidAmount
|
||||||
}
|
}
|
||||||
return ResultOK
|
return tmsp.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
func (txOut TxOutput) SignBytes() []byte {
|
func (txOut TxOutput) SignBytes() []byte {
|
||||||
|
|
Loading…
Reference in New Issue