mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-02 21:53:08 +00:00
18 lines
518 B
Nim
18 lines
518 B
Nim
import pkg/contractabi/selector
|
|
import ./basics
|
|
|
|
type SolidityError* = object of EthersError
|
|
|
|
{.push raises:[].}
|
|
|
|
template errors*(types) {.pragma.}
|
|
|
|
func decode*[E: SolidityError](_: type E, data: seq[byte]): ?!(ref E) =
|
|
const name = $E
|
|
const selector = selector(name, typeof(()))
|
|
if data.len < 4:
|
|
return failure "unable to decode " & name & ": signature too short"
|
|
if selector.toArray[0..<4] != data[0..<4]:
|
|
return failure "unable to decode " & name & ": signature doesn't match"
|
|
success (ref E)()
|