mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
core: rename *block.Base.GetHashableData to GetSignedPart()
This allow to use `Block` as a Verifiable item. When tx is provided, it is set as an interop's script container. Otherwise, block is set.
This commit is contained in:
parent
a92872931c
commit
82b230f19f
5 changed files with 15 additions and 8 deletions
|
@ -20,7 +20,7 @@ var _ block.Block = (*neoBlock)(nil)
|
|||
|
||||
// Sign implements block.Block interface.
|
||||
func (n *neoBlock) Sign(key crypto.PrivateKey) error {
|
||||
data := n.Base.GetHashableData()
|
||||
data := n.Base.GetSignedPart()
|
||||
sig, err := key.Sign(data[:])
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -33,7 +33,7 @@ func (n *neoBlock) Sign(key crypto.PrivateKey) error {
|
|||
|
||||
// Verify implements block.Block interface.
|
||||
func (n *neoBlock) Verify(key crypto.PublicKey, sign []byte) error {
|
||||
data := n.Base.GetHashableData()
|
||||
data := n.Base.GetSignedPart()
|
||||
return key.Verify(data, sign)
|
||||
}
|
||||
|
||||
|
|
|
@ -90,8 +90,8 @@ func (b *Base) EncodeBinary(bw *io.BinWriter) {
|
|||
b.Script.EncodeBinary(bw)
|
||||
}
|
||||
|
||||
// GetHashableData returns serialized hashable data of the block.
|
||||
func (b *Base) GetHashableData() []byte {
|
||||
// GetSignedPart returns serialized hashable data of the block.
|
||||
func (b *Base) GetSignedPart() []byte {
|
||||
buf := io.NewBufBinWriter()
|
||||
// No error can occure while encoding hashable fields.
|
||||
b.encodeHashableFields(buf.BinWriter)
|
||||
|
@ -106,7 +106,7 @@ func (b *Base) GetHashableData() []byte {
|
|||
// Since MerkleRoot already contains the hash value of all transactions,
|
||||
// the modification of transaction will influence the hash value of the block.
|
||||
func (b *Base) createHash() {
|
||||
bb := b.GetHashableData()
|
||||
bb := b.GetSignedPart()
|
||||
b.verificationHash = hash.Sha256(bb)
|
||||
b.hash = hash.Sha256(b.verificationHash.BytesBE())
|
||||
}
|
||||
|
|
|
@ -2057,5 +2057,12 @@ func (bc *Blockchain) secondsPerBlock() int {
|
|||
}
|
||||
|
||||
func (bc *Blockchain) newInteropContext(trigger trigger.Type, d dao.DAO, block *block.Block, tx *transaction.Transaction) *interop.Context {
|
||||
return interop.NewContext(trigger, bc, d, block, tx, bc.log)
|
||||
ic := interop.NewContext(trigger, bc, d, block, tx, bc.log)
|
||||
switch {
|
||||
case tx != nil:
|
||||
ic.Container = tx
|
||||
case block != nil:
|
||||
ic.Container = block
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ func newBlock(cfg config.ProtocolConfiguration, index uint32, prev util.Uint256,
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
b := b.GetHashableData()
|
||||
b := b.GetSignedPart()
|
||||
sig := pKey.Sign(b)
|
||||
if len(sig) != 64 {
|
||||
panic("wrong signature length")
|
||||
|
|
|
@ -246,7 +246,7 @@ func txGetHash(ic *interop.Context, v *vm.VM) error {
|
|||
// engineGetScriptContainer returns transaction that contains the script being
|
||||
// run.
|
||||
func engineGetScriptContainer(ic *interop.Context, v *vm.VM) error {
|
||||
v.Estack().PushVal(vm.NewInteropItem(ic.Tx))
|
||||
v.Estack().PushVal(vm.NewInteropItem(ic.Container))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue