From ddc244332d97bce5f6314fd62adccb885ca70aff Mon Sep 17 00:00:00 2001 From: wz Date: Thu, 20 Jun 2019 16:48:58 +0800 Subject: [PATCH] Test crossin (#213) * fix crossin * fix review --- blockchain/txbuilder/actions.go | 10 +++++----- blockchain/txbuilder/finalize.go | 18 ++++++++++++++++-- protocol/txpool.go | 5 +++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/blockchain/txbuilder/actions.go b/blockchain/txbuilder/actions.go index 1ca9379b..e7320f5c 100644 --- a/blockchain/txbuilder/actions.go +++ b/blockchain/txbuilder/actions.go @@ -262,11 +262,11 @@ func DecodeCrossInAction(data []byte) (Action, error) { type crossInAction struct { bc.AssetAmount - SourceID bc.Hash `json:"source_id"` - SourcePos uint64 `json:"source_pos"` - VMVersion uint64 `json:"vm_version"` - RawDefinitionByte []byte `json:"raw_definition_byte"` - IssuanceProgram []byte `json:"issuance_program"` + SourceID bc.Hash `json:"source_id"` + SourcePos uint64 `json:"source_pos"` + VMVersion uint64 `json:"vm_version"` + RawDefinitionByte json.HexBytes `json:"raw_definition_byte"` + IssuanceProgram json.HexBytes `json:"issuance_program"` } func (a *crossInAction) Build(ctx context.Context, builder *TemplateBuilder) error { diff --git a/blockchain/txbuilder/finalize.go b/blockchain/txbuilder/finalize.go index b9e85bb7..f7015485 100644 --- a/blockchain/txbuilder/finalize.go +++ b/blockchain/txbuilder/finalize.go @@ -39,8 +39,8 @@ func FinalizeTx(ctx context.Context, c *protocol.Chain, tx *types.Tx) error { return err } - if len(tx.GasInputIDs) == 0 { - return ErrNoGasInput + if err := checkGasInputIDs(tx); err != nil { + return err } // This part is use for prevent tx size is 0 @@ -151,3 +151,17 @@ func CalculateTxFee(tx *types.Tx) (fee uint64) { fee = totalInputBTM - totalOutputBTM return } + +func checkGasInputIDs(tx *types.Tx) error { + for _, inp := range tx.Inputs { + switch inp.InputType() { + case types.CrossChainInputType: + return nil + } + } + + if len(tx.GasInputIDs) == 0 { + return ErrNoGasInput + } + return nil +} diff --git a/protocol/txpool.go b/protocol/txpool.go index 957ab6af..32d3f6df 100644 --- a/protocol/txpool.go +++ b/protocol/txpool.go @@ -194,10 +194,15 @@ func (tp *TxPool) HaveTransaction(txHash *bc.Hash) bool { func isTransactionNoBtmInput(tx *types.Tx) bool { for _, input := range tx.TxData.Inputs { + switch input.InputType() { + case types.CrossChainInputType: + return false + } if input.AssetID() == *consensus.BTMAssetID { return false } } + return true } -- 2.11.0