forked from TrueCloudLab/neoneo-go
core: implement (*Transaction).GetSignedPart()
Marshalling it and taking all but last byte violates incapsulation and is just wrong in case transaction already contains any witnesses.
This commit is contained in:
parent
95d9f36c98
commit
72d72296c3
2 changed files with 11 additions and 10 deletions
|
@ -197,6 +197,16 @@ func (t Transaction) GroupOutputByAssetID() map[util.Uint256][]*Output {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSignedPart returns a part of the transaction which must be signed.
|
||||||
|
func (t *Transaction) GetSignedPart() []byte {
|
||||||
|
buf := io.NewBufBinWriter()
|
||||||
|
t.encodeHashableFields(buf.BinWriter)
|
||||||
|
if buf.Err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return buf.Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
// Bytes converts the transaction to []byte
|
// Bytes converts the transaction to []byte
|
||||||
func (t *Transaction) Bytes() []byte {
|
func (t *Transaction) Bytes() []byte {
|
||||||
buf := io.NewBufBinWriter()
|
buf := io.NewBufBinWriter()
|
||||||
|
|
|
@ -94,16 +94,7 @@ func SignTx(tx *transaction.Transaction, wif *keys.WIF) error {
|
||||||
|
|
||||||
// GetInvocationScript returns NEO VM script containing transaction signature.
|
// GetInvocationScript returns NEO VM script containing transaction signature.
|
||||||
func GetInvocationScript(tx *transaction.Transaction, wif *keys.WIF) ([]byte, error) {
|
func GetInvocationScript(tx *transaction.Transaction, wif *keys.WIF) ([]byte, error) {
|
||||||
var (
|
signature := wif.PrivateKey.Sign(tx.GetSignedPart())
|
||||||
buf = io.NewBufBinWriter()
|
|
||||||
signature []byte
|
|
||||||
)
|
|
||||||
tx.EncodeBinary(buf.BinWriter)
|
|
||||||
if buf.Err != nil {
|
|
||||||
return nil, errs.Wrap(buf.Err, "Failed to encode transaction to binary")
|
|
||||||
}
|
|
||||||
data := buf.Bytes()
|
|
||||||
signature = wif.PrivateKey.Sign(data[:(len(data) - 1)])
|
|
||||||
return append([]byte{byte(opcode.PUSHBYTES64)}, signature...), nil
|
return append([]byte{byte(opcode.PUSHBYTES64)}, signature...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue