forked from TrueCloudLab/neoneo-go
core: refactor initVerificationVM
It needs only VM and function to get contract state. Also exposed this method and extended Blockchainer. These changes are needed for the next commit.
This commit is contained in:
parent
f7d74190f5
commit
1261dd5306
3 changed files with 10 additions and 5 deletions
|
@ -80,6 +80,11 @@ func (chain *FakeChain) IsTxStillRelevant(t *transaction.Transaction, txpool *me
|
|||
panic("TODO")
|
||||
}
|
||||
|
||||
// InitVerificationVM initializes VM for witness check.
|
||||
func (chain *FakeChain) InitVerificationVM(v *vm.VM, getContract func(util.Uint160) (*state.Contract, error), hash util.Uint160, witness *transaction.Witness) error {
|
||||
panic("TODO")
|
||||
}
|
||||
|
||||
// IsExtensibleAllowed implements Blockchainer interface.
|
||||
func (*FakeChain) IsExtensibleAllowed(uint160 util.Uint160) bool {
|
||||
return true
|
||||
|
|
|
@ -1655,9 +1655,8 @@ var (
|
|||
ErrInvalidVerificationContract = errors.New("verification contract is missing `verify` method")
|
||||
)
|
||||
|
||||
// initVerificationVM initializes VM for witness check.
|
||||
func (bc *Blockchain) initVerificationVM(ic *interop.Context, hash util.Uint160, witness *transaction.Witness) error {
|
||||
v := ic.VM
|
||||
// InitVerificationVM initializes VM for witness check.
|
||||
func (bc *Blockchain) InitVerificationVM(v *vm.VM, getContract func(util.Uint160) (*state.Contract, error), hash util.Uint160, witness *transaction.Witness) error {
|
||||
if len(witness.VerificationScript) != 0 {
|
||||
if witness.ScriptHash() != hash {
|
||||
return ErrWitnessHashMismatch
|
||||
|
@ -1671,7 +1670,7 @@ func (bc *Blockchain) initVerificationVM(ic *interop.Context, hash util.Uint160,
|
|||
}
|
||||
v.LoadScriptWithFlags(witness.VerificationScript, callflag.ReadOnly)
|
||||
} else {
|
||||
cs, err := ic.GetContract(hash)
|
||||
cs, err := getContract(hash)
|
||||
if err != nil {
|
||||
return ErrUnknownVerificationContract
|
||||
}
|
||||
|
@ -1717,7 +1716,7 @@ func (bc *Blockchain) verifyHashAgainstScript(hash util.Uint160, witness *transa
|
|||
vm.SetPriceGetter(interopCtx.GetPrice)
|
||||
vm.LoadToken = contract.LoadToken(interopCtx)
|
||||
vm.GasLimit = gas
|
||||
if err := bc.initVerificationVM(interopCtx, hash, witness); err != nil {
|
||||
if err := bc.InitVerificationVM(vm, interopCtx.GetContract, hash, witness); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
err := vm.Run()
|
||||
|
|
|
@ -25,6 +25,7 @@ type Blockchainer interface {
|
|||
AddBlock(*block.Block) error
|
||||
CalculateClaimable(h util.Uint160, endHeight uint32) (*big.Int, error)
|
||||
Close()
|
||||
InitVerificationVM(v *vm.VM, getContract func(util.Uint160) (*state.Contract, error), hash util.Uint160, witness *transaction.Witness) error
|
||||
IsTxStillRelevant(t *transaction.Transaction, txpool *mempool.Pool, isPartialTx bool) bool
|
||||
HeaderHeight() uint32
|
||||
GetBlock(hash util.Uint256) (*block.Block, error)
|
||||
|
|
Loading…
Reference in a new issue