Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Bastian Müller <bastian@axiomzen.co>
  • Loading branch information
ramtinms and turbolent committed Nov 27, 2020
1 parent e7705fe commit c52c297
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,9 @@ func (r *interpreterRuntime) parseAndCheckProgram(
sema.WithValidTopLevelDeclarationsHandler(validTopLevelDeclarations),
sema.WithLocationHandler(func(identifiers []Identifier, location Location) (res []ResolvedLocation) {
var err error
res, err = runtimeInterface.ResolveLocation(identifiers, location)
wrapPanic(func() {
res, err = runtimeInterface.ResolveLocation(identifiers, location)
})
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -794,7 +796,10 @@ func (r *interpreterRuntime) meteringInterpreterOptions(runtimeInterface Interfa
return
}

err := runtimeInterface.SetComputationUsed(used)
var err error
wrapPanic(func() {
err = runtimeInterface.SetComputationUsed(used)
})
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -1339,7 +1344,7 @@ func (r *interpreterRuntime) getCurrentBlockHeight(runtimeInterface Interface) (
currentBlockHeight, er = runtimeInterface.GetCurrentBlockHeight()
})
if er != nil {
err = newError(er)
return 0, newError(er)
}
return
}
Expand Down Expand Up @@ -1368,7 +1373,11 @@ func (r *interpreterRuntime) getBlockAtHeight(height uint64, runtimeInterface In

func (r *interpreterRuntime) newGetCurrentBlockFunction(runtimeInterface Interface) interpreter.HostFunction {
return func(invocation interpreter.Invocation) trampoline.Trampoline {
height, err := r.getCurrentBlockHeight(runtimeInterface)
var height uint64
var err error
wrapPanic(func() {
height, err = r.getCurrentBlockHeight(runtimeInterface)
})
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/stdlib/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func newCryptoContractVerifySignatureFunction(signatureVerifier CryptoSignatureV
hashAlgorithm,
)
if err != nil {
panic(fmt.Errorf("VerifySignature: failed to verify the signature: %w", err))
panic(err)
}

return trampoline.Done{Result: interpreter.BoolValue(isValid)}
Expand Down Expand Up @@ -158,7 +158,7 @@ func newCryptoContractHashFunction(hasher CryptoHasher) interpreter.FunctionValu

digest, err := hasher.Hash(data, hashAlgorithm)
if err != nil {
panic(fmt.Errorf("hash: hashing failed: %w", err))
panic(err)

}

Expand Down

0 comments on commit c52c297

Please sign in to comment.