core/tx: remove one layer of indirection for scripts and inouts

It reduces heap pressure a little for these elements as we don't have to
allocate/free them individually. And they're directly tied to transactions or
block, not being shared or anything like that, so it makes little sense for
them to be pointer-based. It only makes building transactions a little easier,
but that's obviously a minor usecase.
This commit is contained in:
Roman Khimov 2019-12-09 17:14:10 +03:00
parent b542a5e7a0
commit 7e371588a7
16 changed files with 81 additions and 78 deletions

View file

@ -258,7 +258,7 @@ func (s *service) verifyBlock(b block.Block) bool {
func (s *service) processBlock(b block.Block) { func (s *service) processBlock(b block.Block) {
bb := &b.(*neoBlock).Block bb := &b.(*neoBlock).Block
bb.Script = s.getBlockWitness(bb) bb.Script = *(s.getBlockWitness(bb))
if err := s.Chain.AddBlock(bb); err != nil { if err := s.Chain.AddBlock(bb); err != nil {
s.log.Warnf("error on add block: %v", err) s.log.Warnf("error on add block: %v", err)

View file

@ -339,10 +339,10 @@ func newMinerTx(nonce uint32) *transaction.Transaction {
Data: &transaction.MinerTX{ Data: &transaction.MinerTX{
Nonce: rand.Uint32(), Nonce: rand.Uint32(),
}, },
Attributes: []*transaction.Attribute{}, Attributes: []transaction.Attribute{},
Inputs: []*transaction.Input{}, Inputs: []transaction.Input{},
Outputs: []*transaction.Output{}, Outputs: []transaction.Output{},
Scripts: []*transaction.Witness{}, Scripts: []transaction.Witness{},
Trimmed: false, Trimmed: false,
} }
} }

View file

@ -91,7 +91,6 @@ func NewBlockFromTrimmedBytes(b []byte) (*Block, error) {
var padding uint8 var padding uint8
br.ReadLE(&padding) br.ReadLE(&padding)
block.Script = &transaction.Witness{}
block.Script.DecodeBinary(br) block.Script.DecodeBinary(br)
lenTX := br.ReadVarUint() lenTX := br.ReadVarUint()

View file

@ -38,7 +38,7 @@ type BlockBase struct {
_ uint8 _ uint8
// Script used to validate the block // Script used to validate the block
Script *transaction.Witness `json:"script"` Script transaction.Witness `json:"script"`
// Hash of this block, created when binary encoded (double SHA256). // Hash of this block, created when binary encoded (double SHA256).
hash util.Uint256 hash util.Uint256
@ -80,7 +80,6 @@ func (b *BlockBase) DecodeBinary(br *io.BinReader) {
return return
} }
b.Script = &transaction.Witness{}
b.Script.DecodeBinary(br) b.Script.DecodeBinary(br)
} }

View file

@ -87,7 +87,7 @@ func newDumbBlock() *Block {
Index: 1, Index: 1,
ConsensusData: 1111, ConsensusData: 1111,
NextConsensus: hash.Hash160([]byte("a")), NextConsensus: hash.Hash160([]byte("a")),
Script: &transaction.Witness{ Script: transaction.Witness{
VerificationScript: []byte{0x51}, // PUSH1 VerificationScript: []byte{0x51}, // PUSH1
InvocationScript: []byte{0x61}, // NOP InvocationScript: []byte{0x61}, // NOP
}, },

View file

@ -945,7 +945,7 @@ func (bc *Blockchain) References(t *transaction.Transaction) map[transaction.Inp
tx = nil tx = nil
} else if tx != nil { } else if tx != nil {
for _, in := range inputs { for _, in := range inputs {
references[*in] = tx.Outputs[in.PrevIndex] references[*in] = &tx.Outputs[in.PrevIndex]
} }
} else { } else {
references = nil references = nil
@ -1243,8 +1243,9 @@ func (bc *Blockchain) GetValidators(txes ...*transaction.Transaction) ([]*keys.P
// group inputs by the same previous hash and iterate through inputs // group inputs by the same previous hash and iterate through inputs
group := make(map[util.Uint256][]*transaction.Input) group := make(map[util.Uint256][]*transaction.Input)
for _, input := range tx.Inputs { for i := range tx.Inputs {
group[input.PrevHash] = append(group[input.PrevHash], input) hash := tx.Inputs[i].PrevHash
group[hash] = append(group[hash], &tx.Inputs[i])
} }
for hash, inputs := range group { for hash, inputs := range group {
@ -1360,7 +1361,7 @@ func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([
} }
hashes := make(map[util.Uint160]bool) hashes := make(map[util.Uint160]bool)
for _, i := range t.Inputs { for _, i := range t.Inputs {
h := references[*i].ScriptHash h := references[i].ScriptHash
if _, ok := hashes[h]; !ok { if _, ok := hashes[h]; !ok {
hashes[h] = true hashes[h] = true
} }
@ -1486,7 +1487,7 @@ func (bc *Blockchain) verifyTxWitnesses(t *transaction.Transaction, block *Block
sort.Slice(witnesses, func(i, j int) bool { return witnesses[i].ScriptHash().Less(witnesses[j].ScriptHash()) }) sort.Slice(witnesses, func(i, j int) bool { return witnesses[i].ScriptHash().Less(witnesses[j].ScriptHash()) })
interopCtx := newInteropContext(trigger.Verification, bc, bc.store, block, t) interopCtx := newInteropContext(trigger.Verification, bc, bc.store, block, t)
for i := 0; i < len(hashes); i++ { for i := 0; i < len(hashes); i++ {
err := bc.verifyHashAgainstScript(hashes[i], witnesses[i], t.VerificationHash(), interopCtx) err := bc.verifyHashAgainstScript(hashes[i], &witnesses[i], t.VerificationHash(), interopCtx)
if err != nil { if err != nil {
numStr := fmt.Sprintf("witness #%d", i) numStr := fmt.Sprintf("witness #%d", i)
return errors.Wrap(err, numStr) return errors.Wrap(err, numStr)
@ -1505,7 +1506,7 @@ func (bc *Blockchain) verifyBlockWitnesses(block *Block, prevHeader *Header) err
hash = prevHeader.NextConsensus hash = prevHeader.NextConsensus
} }
interopCtx := newInteropContext(trigger.Verification, bc, bc.store, nil, nil) interopCtx := newInteropContext(trigger.Verification, bc, bc.store, nil, nil)
return bc.verifyHashAgainstScript(hash, block.Script, block.VerificationHash(), interopCtx) return bc.verifyHashAgainstScript(hash, &block.Script, block.VerificationHash(), interopCtx)
} }
func hashAndIndexToBytes(h util.Uint256, index uint32) []byte { func hashAndIndexToBytes(h util.Uint256, index uint32) []byte {

View file

@ -20,7 +20,7 @@ func TestHeaderEncodeDecode(t *testing.T) {
Index: 3445, Index: 3445,
ConsensusData: 394949, ConsensusData: 394949,
NextConsensus: util.Uint160{}, NextConsensus: util.Uint160{},
Script: &transaction.Witness{ Script: transaction.Witness{
InvocationScript: []byte{0x10}, InvocationScript: []byte{0x10},
VerificationScript: []byte{0x11}, VerificationScript: []byte{0x11},
}, },

View file

@ -55,7 +55,7 @@ func newBlock(index uint32, txs ...*transaction.Transaction) *Block {
vlen-(vlen-1)/3, vlen-(vlen-1)/3,
validators, validators,
) )
witness := &transaction.Witness{ witness := transaction.Witness{
VerificationScript: valScript, VerificationScript: valScript,
} }
b := &Block{ b := &Block{

View file

@ -89,8 +89,8 @@ func (ic *interopContext) txGetAttributes(v *vm.VM) error {
return errors.New("too many attributes") return errors.New("too many attributes")
} }
attrs := make([]vm.StackItem, 0, len(tx.Attributes)) attrs := make([]vm.StackItem, 0, len(tx.Attributes))
for _, attr := range tx.Attributes { for i := range tx.Attributes {
attrs = append(attrs, vm.NewInteropItem(attr)) attrs = append(attrs, vm.NewInteropItem(&tx.Attributes[i]))
} }
v.Estack().PushVal(attrs) v.Estack().PushVal(attrs)
return nil return nil
@ -107,8 +107,8 @@ func (ic *interopContext) txGetInputs(v *vm.VM) error {
return errors.New("too many inputs") return errors.New("too many inputs")
} }
inputs := make([]vm.StackItem, 0, len(tx.Inputs)) inputs := make([]vm.StackItem, 0, len(tx.Inputs))
for _, input := range tx.Inputs { for i := range tx.Inputs {
inputs = append(inputs, vm.NewInteropItem(input)) inputs = append(inputs, vm.NewInteropItem(&tx.Inputs[i]))
} }
v.Estack().PushVal(inputs) v.Estack().PushVal(inputs)
return nil return nil
@ -125,8 +125,8 @@ func (ic *interopContext) txGetOutputs(v *vm.VM) error {
return errors.New("too many outputs") return errors.New("too many outputs")
} }
outputs := make([]vm.StackItem, 0, len(tx.Outputs)) outputs := make([]vm.StackItem, 0, len(tx.Outputs))
for _, output := range tx.Outputs { for i := range tx.Outputs {
outputs = append(outputs, vm.NewInteropItem(output)) outputs = append(outputs, vm.NewInteropItem(&tx.Outputs[i]))
} }
v.Estack().PushVal(outputs) v.Estack().PushVal(outputs)
return nil return nil
@ -146,7 +146,7 @@ func (ic *interopContext) txGetReferences(v *vm.VM) error {
stackrefs := make([]vm.StackItem, 0, len(refs)) stackrefs := make([]vm.StackItem, 0, len(refs))
for _, k := range tx.Inputs { for _, k := range tx.Inputs {
tio := txInOut{*k, *refs[*k]} tio := txInOut{k, *refs[k]}
stackrefs = append(stackrefs, vm.NewInteropItem(tio)) stackrefs = append(stackrefs, vm.NewInteropItem(tio))
} }
v.Estack().PushVal(stackrefs) v.Estack().PushVal(stackrefs)
@ -190,8 +190,8 @@ func (ic *interopContext) txGetWitnesses(v *vm.VM) error {
return errors.New("too many outputs") return errors.New("too many outputs")
} }
scripts := make([]vm.StackItem, 0, len(tx.Scripts)) scripts := make([]vm.StackItem, 0, len(tx.Scripts))
for _, script := range tx.Scripts { for i := range tx.Scripts {
scripts = append(scripts, vm.NewInteropItem(script)) scripts = append(scripts, vm.NewInteropItem(&tx.Scripts[i]))
} }
v.Estack().PushVal(scripts) v.Estack().PushVal(scripts)
return nil return nil

View file

@ -92,7 +92,7 @@ func TestTxGetInputs(t *testing.T) {
err := context.txGetInputs(v) err := context.txGetInputs(v)
require.NoError(t, err) require.NoError(t, err)
value := v.Estack().Pop().Value().([]vm.StackItem) value := v.Estack().Pop().Value().([]vm.StackItem)
require.Equal(t, tx.Inputs[0], value[0].Value().(*transaction.Input)) require.Equal(t, tx.Inputs[0], *value[0].Value().(*transaction.Input))
} }
func TestTxGetOutputs(t *testing.T) { func TestTxGetOutputs(t *testing.T) {
@ -101,7 +101,7 @@ func TestTxGetOutputs(t *testing.T) {
err := context.txGetOutputs(v) err := context.txGetOutputs(v)
require.NoError(t, err) require.NoError(t, err)
value := v.Estack().Pop().Value().([]vm.StackItem) value := v.Estack().Pop().Value().([]vm.StackItem)
require.Equal(t, tx.Outputs[0], value[0].Value().(*transaction.Output)) require.Equal(t, tx.Outputs[0], *value[0].Value().(*transaction.Output))
} }
func TestTxGetType(t *testing.T) { func TestTxGetType(t *testing.T) {
@ -115,16 +115,16 @@ func TestTxGetType(t *testing.T) {
func TestPopInputFromVM(t *testing.T) { func TestPopInputFromVM(t *testing.T) {
v, tx, _ := createVMAndTX(t) v, tx, _ := createVMAndTX(t)
v.Estack().PushVal(vm.NewInteropItem(tx.Inputs[0])) v.Estack().PushVal(vm.NewInteropItem(&tx.Inputs[0]))
input, err := popInputFromVM(v) input, err := popInputFromVM(v)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, tx.Inputs[0], input) require.Equal(t, tx.Inputs[0], *input)
} }
func TestInputGetHash(t *testing.T) { func TestInputGetHash(t *testing.T) {
v, tx, context := createVMAndTX(t) v, tx, context := createVMAndTX(t)
v.Estack().PushVal(vm.NewInteropItem(tx.Inputs[0])) v.Estack().PushVal(vm.NewInteropItem(&tx.Inputs[0]))
err := context.inputGetHash(v) err := context.inputGetHash(v)
require.NoError(t, err) require.NoError(t, err)
@ -134,7 +134,7 @@ func TestInputGetHash(t *testing.T) {
func TestInputGetIndex(t *testing.T) { func TestInputGetIndex(t *testing.T) {
v, tx, context := createVMAndTX(t) v, tx, context := createVMAndTX(t)
v.Estack().PushVal(vm.NewInteropItem(tx.Inputs[0])) v.Estack().PushVal(vm.NewInteropItem(&tx.Inputs[0]))
err := context.inputGetIndex(v) err := context.inputGetIndex(v)
require.NoError(t, err) require.NoError(t, err)
@ -144,16 +144,16 @@ func TestInputGetIndex(t *testing.T) {
func TestPopOutputFromVM(t *testing.T) { func TestPopOutputFromVM(t *testing.T) {
v, tx, _ := createVMAndTX(t) v, tx, _ := createVMAndTX(t)
v.Estack().PushVal(vm.NewInteropItem(tx.Outputs[0])) v.Estack().PushVal(vm.NewInteropItem(&tx.Outputs[0]))
output, err := popOutputFromVM(v) output, err := popOutputFromVM(v)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, tx.Outputs[0], output) require.Equal(t, tx.Outputs[0], *output)
} }
func TestOutputGetAssetID(t *testing.T) { func TestOutputGetAssetID(t *testing.T) {
v, tx, context := createVMAndTX(t) v, tx, context := createVMAndTX(t)
v.Estack().PushVal(vm.NewInteropItem(tx.Outputs[0])) v.Estack().PushVal(vm.NewInteropItem(&tx.Outputs[0]))
err := context.outputGetAssetID(v) err := context.outputGetAssetID(v)
require.NoError(t, err) require.NoError(t, err)
@ -163,7 +163,7 @@ func TestOutputGetAssetID(t *testing.T) {
func TestOutputGetScriptHash(t *testing.T) { func TestOutputGetScriptHash(t *testing.T) {
v, tx, context := createVMAndTX(t) v, tx, context := createVMAndTX(t)
v.Estack().PushVal(vm.NewInteropItem(tx.Outputs[0])) v.Estack().PushVal(vm.NewInteropItem(&tx.Outputs[0]))
err := context.outputGetScriptHash(v) err := context.outputGetScriptHash(v)
require.NoError(t, err) require.NoError(t, err)
@ -173,7 +173,7 @@ func TestOutputGetScriptHash(t *testing.T) {
func TestOutputGetValue(t *testing.T) { func TestOutputGetValue(t *testing.T) {
v, tx, context := createVMAndTX(t) v, tx, context := createVMAndTX(t)
v.Estack().PushVal(vm.NewInteropItem(tx.Outputs[0])) v.Estack().PushVal(vm.NewInteropItem(&tx.Outputs[0]))
err := context.outputGetValue(v) err := context.outputGetValue(v)
require.NoError(t, err) require.NoError(t, err)
@ -183,7 +183,7 @@ func TestOutputGetValue(t *testing.T) {
func TestAttrGetData(t *testing.T) { func TestAttrGetData(t *testing.T) {
v, tx, context := createVMAndTX(t) v, tx, context := createVMAndTX(t)
v.Estack().PushVal(vm.NewInteropItem(tx.Attributes[0])) v.Estack().PushVal(vm.NewInteropItem(&tx.Attributes[0]))
err := context.attrGetData(v) err := context.attrGetData(v)
require.NoError(t, err) require.NoError(t, err)
@ -193,7 +193,7 @@ func TestAttrGetData(t *testing.T) {
func TestAttrGetUsage(t *testing.T) { func TestAttrGetUsage(t *testing.T) {
v, tx, context := createVMAndTX(t) v, tx, context := createVMAndTX(t)
v.Estack().PushVal(vm.NewInteropItem(tx.Attributes[0])) v.Estack().PushVal(vm.NewInteropItem(&tx.Attributes[0]))
err := context.attrGetUsage(v) err := context.attrGetUsage(v)
require.NoError(t, err) require.NoError(t, err)
@ -397,17 +397,17 @@ func createVMAndTX(t *testing.T) (*vm.VM, *transaction.Transaction, *interopCont
tx := newMinerTX() tx := newMinerTX()
bytes := make([]byte, 1) bytes := make([]byte, 1)
attributes := append(tx.Attributes, &transaction.Attribute{ attributes := append(tx.Attributes, transaction.Attribute{
Usage: transaction.Description, Usage: transaction.Description,
Data: bytes, Data: bytes,
}) })
inputs := append(tx.Inputs, &transaction.Input{ inputs := append(tx.Inputs, transaction.Input{
PrevHash: randomUint256(), PrevHash: randomUint256(),
PrevIndex: 1, PrevIndex: 1,
}) })
outputs := append(tx.Outputs, &transaction.Output{ outputs := append(tx.Outputs, transaction.Output{
AssetID: randomUint256(), AssetID: randomUint256(),
Amount: 10, Amount: 10,
ScriptHash: randomUint160(), ScriptHash: randomUint160(),

View file

@ -288,7 +288,9 @@ func (mp MemPool) Verify(tx *transaction.Transaction) bool {
inputs := make([]*transaction.Input, 0) inputs := make([]*transaction.Input, 0)
for _, item := range mp.GetVerifiedTransactions() { for _, item := range mp.GetVerifiedTransactions() {
if tx.Hash().Equals(item.Hash()) { if tx.Hash().Equals(item.Hash()) {
inputs = append(inputs, item.Inputs...) for i := range item.Inputs {
inputs = append(inputs, &item.Inputs[i])
}
} }
} }

View file

@ -26,10 +26,10 @@ func NewInvocationTX(script []byte, gas util.Fixed8) *Transaction {
Gas: gas, Gas: gas,
Version: 1, Version: 1,
}, },
Attributes: []*Attribute{}, Attributes: []Attribute{},
Inputs: []*Input{}, Inputs: []Input{},
Outputs: []*Output{}, Outputs: []Output{},
Scripts: []*Witness{}, Scripts: []Witness{},
} }
} }

View file

@ -27,18 +27,18 @@ type Transaction struct {
Data TXer `json:"-"` Data TXer `json:"-"`
// Transaction attributes. // Transaction attributes.
Attributes []*Attribute `json:"attributes"` Attributes []Attribute `json:"attributes"`
// The inputs of the transaction. // The inputs of the transaction.
Inputs []*Input `json:"vin"` Inputs []Input `json:"vin"`
// The outputs of the transaction. // The outputs of the transaction.
Outputs []*Output `json:"vout"` Outputs []Output `json:"vout"`
// The scripts that comes with this transaction. // The scripts that comes with this transaction.
// Scripts exist out of the verification script // Scripts exist out of the verification script
// and invocation script. // and invocation script.
Scripts []*Witness `json:"scripts"` Scripts []Witness `json:"scripts"`
// Hash of the transaction (double SHA256). // Hash of the transaction (double SHA256).
hash util.Uint256 hash util.Uint256
@ -82,12 +82,12 @@ func (t *Transaction) VerificationHash() util.Uint256 {
// AddOutput adds the given output to the transaction outputs. // AddOutput adds the given output to the transaction outputs.
func (t *Transaction) AddOutput(out *Output) { func (t *Transaction) AddOutput(out *Output) {
t.Outputs = append(t.Outputs, out) t.Outputs = append(t.Outputs, *out)
} }
// AddInput adds the given input to the transaction inputs. // AddInput adds the given input to the transaction inputs.
func (t *Transaction) AddInput(in *Input) { func (t *Transaction) AddInput(in *Input) {
t.Inputs = append(t.Inputs, in) t.Inputs = append(t.Inputs, *in)
} }
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
@ -187,8 +187,9 @@ func (t *Transaction) createHash() error {
// GroupInputsByPrevHash groups all TX inputs by their previous hash. // GroupInputsByPrevHash groups all TX inputs by their previous hash.
func (t *Transaction) GroupInputsByPrevHash() map[util.Uint256][]*Input { func (t *Transaction) GroupInputsByPrevHash() map[util.Uint256][]*Input {
m := make(map[util.Uint256][]*Input) m := make(map[util.Uint256][]*Input)
for _, in := range t.Inputs { for i := range t.Inputs {
m[in.PrevHash] = append(m[in.PrevHash], in) hash := t.Inputs[i].PrevHash
m[hash] = append(m[hash], &t.Inputs[i])
} }
return m return m
} }
@ -196,8 +197,9 @@ func (t *Transaction) GroupInputsByPrevHash() map[util.Uint256][]*Input {
// GroupOutputByAssetID groups all TX outputs by their assetID. // GroupOutputByAssetID groups all TX outputs by their assetID.
func (t Transaction) GroupOutputByAssetID() map[util.Uint256][]*Output { func (t Transaction) GroupOutputByAssetID() map[util.Uint256][]*Output {
m := make(map[util.Uint256][]*Output) m := make(map[util.Uint256][]*Output)
for _, out := range t.Outputs { for i := range t.Outputs {
m[out.AssetID] = append(m[out.AssetID], out) hash := t.Outputs[i].AssetID
m[hash] = append(m[hash], &t.Outputs[i])
} }
return m return m
} }

View file

@ -31,7 +31,7 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*Block, error) {
Index: 0, Index: 0,
ConsensusData: 2083236893, ConsensusData: 2083236893,
NextConsensus: nextConsensus, NextConsensus: nextConsensus,
Script: &transaction.Witness{ Script: transaction.Witness{
InvocationScript: []byte{}, InvocationScript: []byte{},
VerificationScript: []byte{byte(opcode.PUSHT)}, VerificationScript: []byte{byte(opcode.PUSHT)},
}, },
@ -56,25 +56,25 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*Block, error) {
Data: &transaction.MinerTX{ Data: &transaction.MinerTX{
Nonce: 2083236893, Nonce: 2083236893,
}, },
Attributes: []*transaction.Attribute{}, Attributes: []transaction.Attribute{},
Inputs: []*transaction.Input{}, Inputs: []transaction.Input{},
Outputs: []*transaction.Output{}, Outputs: []transaction.Output{},
Scripts: []*transaction.Witness{}, Scripts: []transaction.Witness{},
}, },
governingTX, governingTX,
utilityTX, utilityTX,
{ {
Type: transaction.IssueType, Type: transaction.IssueType,
Data: &transaction.IssueTX{}, // no fields. Data: &transaction.IssueTX{}, // no fields.
Inputs: []*transaction.Input{}, Inputs: []transaction.Input{},
Outputs: []*transaction.Output{ Outputs: []transaction.Output{
{ {
AssetID: governingTX.Hash(), AssetID: governingTX.Hash(),
Amount: governingTX.Data.(*transaction.RegisterTX).Amount, Amount: governingTX.Data.(*transaction.RegisterTX).Amount,
ScriptHash: scriptOut, ScriptHash: scriptOut,
}, },
}, },
Scripts: []*transaction.Witness{ Scripts: []transaction.Witness{
{ {
InvocationScript: []byte{}, InvocationScript: []byte{},
VerificationScript: []byte{byte(opcode.PUSHT)}, VerificationScript: []byte{byte(opcode.PUSHT)},
@ -105,10 +105,10 @@ func governingTokenTX() *transaction.Transaction {
tx := &transaction.Transaction{ tx := &transaction.Transaction{
Type: transaction.RegisterType, Type: transaction.RegisterType,
Data: registerTX, Data: registerTX,
Attributes: []*transaction.Attribute{}, Attributes: []transaction.Attribute{},
Inputs: []*transaction.Input{}, Inputs: []transaction.Input{},
Outputs: []*transaction.Output{}, Outputs: []transaction.Output{},
Scripts: []*transaction.Witness{}, Scripts: []transaction.Witness{},
} }
return tx return tx
@ -127,10 +127,10 @@ func utilityTokenTX() *transaction.Transaction {
tx := &transaction.Transaction{ tx := &transaction.Transaction{
Type: transaction.RegisterType, Type: transaction.RegisterType,
Data: registerTX, Data: registerTX,
Attributes: []*transaction.Attribute{}, Attributes: []transaction.Attribute{},
Inputs: []*transaction.Input{}, Inputs: []transaction.Input{},
Outputs: []*transaction.Output{}, Outputs: []transaction.Output{},
Scripts: []*transaction.Witness{}, Scripts: []transaction.Witness{},
} }
return tx return tx

View file

@ -16,7 +16,7 @@ func TestHeadersEncodeDecode(t *testing.T) {
BlockBase: core.BlockBase{ BlockBase: core.BlockBase{
Version: 0, Version: 0,
Index: 1, Index: 1,
Script: &transaction.Witness{ Script: transaction.Witness{
InvocationScript: []byte{0x0}, InvocationScript: []byte{0x0},
VerificationScript: []byte{0x1}, VerificationScript: []byte{0x1},
}, },
@ -25,7 +25,7 @@ func TestHeadersEncodeDecode(t *testing.T) {
BlockBase: core.BlockBase{ BlockBase: core.BlockBase{
Version: 0, Version: 0,
Index: 2, Index: 2,
Script: &transaction.Witness{ Script: transaction.Witness{
InvocationScript: []byte{0x0}, InvocationScript: []byte{0x0},
VerificationScript: []byte{0x1}, VerificationScript: []byte{0x1},
}, },
@ -34,7 +34,7 @@ func TestHeadersEncodeDecode(t *testing.T) {
BlockBase: core.BlockBase{ BlockBase: core.BlockBase{
Version: 0, Version: 0,
Index: 3, Index: 3,
Script: &transaction.Witness{ Script: transaction.Witness{
InvocationScript: []byte{0x0}, InvocationScript: []byte{0x0},
VerificationScript: []byte{0x1}, VerificationScript: []byte{0x1},
}, },

View file

@ -39,7 +39,7 @@ func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transac
return nil, errs.Wrapf(err, "Failed to take script hash from address: %v", address) return nil, errs.Wrapf(err, "Failed to take script hash from address: %v", address)
} }
tx.Attributes = append(tx.Attributes, tx.Attributes = append(tx.Attributes,
&transaction.Attribute{ transaction.Attribute{
Usage: transaction.Script, Usage: transaction.Script,
Data: fromAddressHash.BytesBE(), Data: fromAddressHash.BytesBE(),
}) })
@ -87,7 +87,7 @@ func SignTx(tx *transaction.Transaction, wif *keys.WIF) error {
return errs.Wrap(err, "failed to create invocation script") return errs.Wrap(err, "failed to create invocation script")
} }
witness.VerificationScript = wif.PrivateKey.PublicKey().GetVerificationScript() witness.VerificationScript = wif.PrivateKey.PublicKey().GetVerificationScript()
tx.Scripts = append(tx.Scripts, &witness) tx.Scripts = append(tx.Scripts, witness)
tx.Hash() tx.Hash()
return nil return nil