// UtxoToInputs convert an utxo to the txinput
func UtxoToInputs(signer *signers.Signer, u *UTXO) (*legacy.TxInput, *txbuilder.SigningInstruction, error) {
- txInput := legacy.NewSpendInput(nil, u.SourceID, u.AssetID, u.Amount, u.SourcePos, u.ControlProgram, u.RefDataHash)
+ txInput := legacy.NewSpendInput(nil, u.SourceID, u.AssetID, u.Amount, u.SourcePos, u.ControlProgram)
sigInst := &txbuilder.SigningInstruction{}
if signer == nil {
return txInput, sigInst, nil
SourcePos uint64
ControlProgram []byte
- RefDataHash bc.Hash
AccountID string
Address string
Program string `json:"program"`
SourceID string `json:"source_id"`
SourcePos uint64 `json:"source_pos"`
- RefDataHash string `json:"ref_data"`
ValidHeight uint64 `json:"valid_height"`
}
tmpUTXO.Amount = utxo.Amount
tmpUTXO.SourcePos = utxo.SourcePos
tmpUTXO.Program = fmt.Sprintf("%x", utxo.ControlProgram)
- tmpUTXO.RefDataHash = utxo.RefDataHash.String()
tmpUTXO.ControlProgramIndex = utxo.ControlProgramIndex
tmpUTXO.Address = utxo.Address
tmpUTXO.ValidHeight = utxo.ValidHeight
type testAction bc.AssetAmount
func (t testAction) Build(ctx context.Context, b *TemplateBuilder) error {
- in := legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), *t.AssetId, t.Amount, 0, nil, bc.Hash{})
+ in := legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), *t.AssetId, t.Amount, 0, nil)
tplIn := &SigningInstruction{}
err := b.AddInput(in, tplIn)
want := &Template{
Transaction: legacy.NewTx(legacy.TxData{
Version: 1,
- SerializedSize: 396,
+ SerializedSize: 332,
Inputs: []*legacy.TxInput{
- legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), assetID1, 5, 0, nil, bc.Hash{}),
+ legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), assetID1, 5, 0, nil),
},
Outputs: []*legacy.TxOutput{
legacy.NewTxOutput(assetID2, 6, []byte("dest")),
want error
}{{
tx: &legacy.TxData{
- Inputs: []*legacy.TxInput{legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil, bc.Hash{})},
+ Inputs: []*legacy.TxInput{legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil)},
},
want: ErrBlankCheck,
}, {
tx: &legacy.TxData{
- Inputs: []*legacy.TxInput{legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil, bc.Hash{})},
+ Inputs: []*legacy.TxInput{legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil)},
Outputs: []*legacy.TxOutput{legacy.NewTxOutput(bc.AssetID{}, 3, nil)},
},
want: ErrBlankCheck,
}, {
tx: &legacy.TxData{
Inputs: []*legacy.TxInput{
- legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil, bc.Hash{}),
- legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.NewAssetID([32]byte{1}), 5, 0, nil, bc.Hash{}),
+ legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil),
+ legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.NewAssetID([32]byte{1}), 5, 0, nil),
},
Outputs: []*legacy.TxOutput{legacy.NewTxOutput(bc.AssetID{}, 5, nil)},
},
want: ErrBlankCheck,
}, {
tx: &legacy.TxData{
- Inputs: []*legacy.TxInput{legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil, bc.Hash{})},
+ Inputs: []*legacy.TxInput{legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil)},
Outputs: []*legacy.TxOutput{
legacy.NewTxOutput(bc.AssetID{}, math.MaxInt64, nil),
legacy.NewTxOutput(bc.AssetID{}, 7, nil),
}, {
tx: &legacy.TxData{
Inputs: []*legacy.TxInput{
- legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil, bc.Hash{}),
- legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, math.MaxInt64, 0, nil, bc.Hash{}),
+ legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil),
+ legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, math.MaxInt64, 0, nil),
},
},
want: ErrBadAmount,
}, {
tx: &legacy.TxData{
- Inputs: []*legacy.TxInput{legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil, bc.Hash{})},
+ Inputs: []*legacy.TxInput{legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil)},
Outputs: []*legacy.TxOutput{legacy.NewTxOutput(bc.AssetID{}, 5, nil)},
},
want: nil,
want: nil,
}, {
tx: &legacy.TxData{
- Inputs: []*legacy.TxInput{legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil, bc.Hash{})},
+ Inputs: []*legacy.TxInput{legacy.NewSpendInput(nil, bc.NewHash([32]byte{0xff}), bc.AssetID{}, 5, 0, nil)},
Outputs: []*legacy.TxOutput{legacy.NewTxOutput(bc.NewAssetID([32]byte{1}), 5, nil)},
},
want: nil,
func (si *SpendInput) IsIssuance() bool { return false }
func (si *SpendInput) IsCoinbase() bool { return false }
-func NewSpendInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount uint64, sourcePos uint64, controlProgram []byte, outRefDataHash bc.Hash) *TxInput {
+func NewSpendInput(arguments [][]byte, sourceID bc.Hash, assetID bc.AssetID, amount uint64, sourcePos uint64, controlProgram []byte) *TxInput {
const (
vmver = 1
assetver = 1
SourcePosition: sourcePos,
VMVersion: vmver,
ControlProgram: controlProgram,
- RefDataHash: outRefDataHash,
}
return &TxInput{
AssetVersion: assetver,
SourcePosition uint64
VMVersion uint64
ControlProgram []byte
- RefDataHash bc.Hash
}
func (sc *SpendCommitment) writeExtensibleString(w io.Writer, suffix []byte, assetVersion uint64) error {
if err != nil {
return errors.Wrap(err, "writing control program")
}
- _, err = sc.RefDataHash.WriteTo(w)
- if err != nil {
- return errors.Wrap(err, "writing reference data hash")
- }
}
if len(suffix) > 0 {
_, err = w.Write(suffix)
if err != nil {
return errors.Wrap(err, "reading control program")
}
- _, err = sc.RefDataHash.ReadFrom(r)
- if err != nil {
- return errors.Wrap(err, "reading reference data hash")
- }
return nil
}
return nil
{
tx: NewTx(TxData{
Version: 1,
- SerializedSize: uint64(206),
+ SerializedSize: uint64(174),
Inputs: []*TxInput{
- NewSpendInput(nil, mustDecodeHash("dd385f6fe25d91d8c1bd0fa58951ad56b0c5229dcc01f61d9f9e8b9eb92d3292"), bc.AssetID{}, 1000000000000, 1, []byte{1}, bc.Hash{}),
+ NewSpendInput(nil, mustDecodeHash("dd385f6fe25d91d8c1bd0fa58951ad56b0c5229dcc01f61d9f9e8b9eb92d3292"), bc.AssetID{}, 1000000000000, 1, []byte{1}),
},
Outputs: []*TxOutput{
NewTxOutput(assetID, 600000000000, []byte{1}),
NewTxOutput(assetID, 400000000000, []byte{2}),
},
}),
- hex: ("0701000001016c016add385f6fe25d91d8c1bd0fa58951ad56b0c5229dcc01f61d9f9e8b9eb92d3292000000000000000000000000000000000000000000000000000000000000000080a094a58d1d0101010100000000000000000000000000000000000000000000000000000000000000000100020129fa48ca4e0150f83fbf26cf83211d136313cde98601a667d999ab9cc27b723d4680e0a596bb11010101000129fa48ca4e0150f83fbf26cf83211d136313cde98601a667d999ab9cc27b723d4680c0ee8ed20b01010200"), // output 1, output witness
+ hex: ("0701000001014c014add385f6fe25d91d8c1bd0fa58951ad56b0c5229dcc01f61d9f9e8b9eb92d3292000000000000000000000000000000000000000000000000000000000000000080a094a58d1d010101010100020129fa48ca4e0150f83fbf26cf83211d136313cde98601a667d999ab9cc27b723d4680e0a596bb11010101000129fa48ca4e0150f83fbf26cf83211d136313cde98601a667d999ab9cc27b723d4680c0ee8ed20b01010200"), // output 1, output witness
hash: mustDecodeHash("828b56bb1946e8fe04e4dffd6b856d3a5ded4c96d05464d3d2ceb470c1620bc4"),
},
}
}, {
tx: &TxData{
Inputs: []*TxInput{
- NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil, bc.Hash{}),
+ NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil),
NewIssuanceInput(nil, 0, bc.Hash{}, nil, nil, nil),
},
},
}, {
tx: &TxData{
Inputs: []*TxInput{
- NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil, bc.Hash{}),
+ NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil),
},
},
want: false,
func BenchmarkTxWriteToTrue200(b *testing.B) {
tx := &Tx{}
for i := 0; i < 200; i++ {
- tx.Inputs = append(tx.Inputs, NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil, bc.Hash{}))
+ tx.Inputs = append(tx.Inputs, NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil))
tx.Outputs = append(tx.Outputs, NewTxOutput(bc.AssetID{}, 0, nil))
}
for i := 0; i < b.N; i++ {
func BenchmarkTxWriteToFalse200(b *testing.B) {
tx := &Tx{}
for i := 0; i < 200; i++ {
- tx.Inputs = append(tx.Inputs, NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil, bc.Hash{}))
+ tx.Inputs = append(tx.Inputs, NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil))
tx.Outputs = append(tx.Outputs, NewTxOutput(bc.AssetID{}, 0, nil))
}
for i := 0; i < b.N; i++ {
}
func BenchmarkTxInputWriteToTrue(b *testing.B) {
- input := NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil, bc.Hash{})
+ input := NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil)
ew := errors.NewWriter(ioutil.Discard)
for i := 0; i < b.N; i++ {
input.writeTo(ew, 0)
}
func BenchmarkTxInputWriteToFalse(b *testing.B) {
- input := NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil, bc.Hash{})
+ input := NewSpendInput(nil, bc.Hash{}, bc.AssetID{}, 0, 0, nil)
ew := errors.NewWriter(ioutil.Discard)
for i := 0; i < b.N; i++ {
input.writeTo(ew, serRequired)
Version: 1,
SerializedSize: 66,
Inputs: []*TxInput{
- NewSpendInput(nil, mustDecodeHash("dd385f6fe25d91d8c1bd0fa58951ad56b0c5229dcc01f61d9f9e8b9eb92d3292"), assetID, 1000000000000, 1, []byte{1}, bc.Hash{}),
- NewSpendInput(nil, bc.NewHash([32]byte{0x11}), assetID, 1, 1, []byte{2}, bc.Hash{}),
+ NewSpendInput(nil, mustDecodeHash("dd385f6fe25d91d8c1bd0fa58951ad56b0c5229dcc01f61d9f9e8b9eb92d3292"), assetID, 1000000000000, 1, []byte{1}),
+ NewSpendInput(nil, bc.NewHash([32]byte{0x11}), assetID, 1, 1, []byte{2}),
},
Outputs: []*TxOutput{
NewTxOutput(assetID, 600000000000, []byte{1}),
"github.com/bytom/testutil"
)
-const dirPath = "pseudohsm/testdata/pseudo"
-
func init() {
spew.Config.DisableMethods = true
}
result.txInputs = []*legacy.TxInput{
legacy.NewIssuanceInput([]byte{3}, 10, result.initialBlockID, result.issuanceProg.Code, result.issuanceArgs, result.assetDef),
- legacy.NewSpendInput(args1, *newHash(5), result.assetID, 20, 0, cp1, *newHash(6)),
- legacy.NewSpendInput(args2, *newHash(8), result.assetID, 40, 0, cp2, *newHash(9)),
+ legacy.NewSpendInput(args1, *newHash(5), result.assetID, 20, 0, cp1),
+ legacy.NewSpendInput(args2, *newHash(8), result.assetID, 40, 0, cp2),
}
}
func mockGasTxInput() *legacy.TxInput {
cp, _ := vmutil.DefaultCoinbaseProgram()
- return legacy.NewSpendInput([][]byte{}, *newHash(8), *consensus.BTMAssetID, 100000000, 0, cp, *newHash(9))
+ return legacy.NewSpendInput([][]byte{}, *newHash(8), *consensus.BTMAssetID, 100000000, 0, cp)
}
// Like errors.Root, but also unwraps vm.Error objects.
package validation
import (
- "encoding/hex"
"fmt"
"testing"
func TestCheckOutput(t *testing.T) {
tx := legacy.NewTx(legacy.TxData{
Inputs: []*legacy.TxInput{
- legacy.NewSpendInput(nil, bc.Hash{}, bc.NewAssetID([32]byte{1}), 5, 1, []byte("spendprog"), bc.Hash{}),
+ legacy.NewSpendInput(nil, bc.Hash{}, bc.NewAssetID([32]byte{1}), 5, 1, []byte("spendprog")),
legacy.NewIssuanceInput(nil, 6, bc.Hash{}, []byte("issueprog"), nil, nil),
},
Outputs: []*legacy.TxOutput{
})
}
}
-
-func mustDecodeHex(h string) []byte {
- bits, err := hex.DecodeString(h)
- if err != nil {
- panic(err)
- }
- return bits
-}