-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheip1962.go_direct
62 lines (53 loc) · 1.55 KB
/
eip1962.go_direct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package eip1962
/*
// #cgo CFLAGS: -std=c++17
#cgo LDFLAGS: -lc++ -lstdc++ -O3
#cgo CXXFLAGS: -std=c++17
// #cgo CXXFLAGS: -I./include/
#include "./src/api.cpp"
#include "./src/common.cpp"
#include "./src/repr.cpp"
#include "./src/wrapper.h"
#include "./src/wrapper.cpp"
// extern int run(const char *i, uint32_t i_len, char *o, uint32_t *o_len, char *err, uint32_t *char_len);
// extern int meter_gas(const char *i, uint32_t i_len, uint64_t *gas);
*/
import "C"
import (
"errors"
"math/big"
"unsafe"
)
const maxOutputLen = 256 * 3 * 2
var (
ErrInvalidMsgLen = errors.New("invalid message length, need 32 bytes")
)
// Call calls the C++ implementation of the EIP
func Call(data []byte) ([]byte, error) {
if len(msg) == 0 {
return nil, ErrInvalidMsgLen
}
ilen := len(data)
output_bytes = make([]byte, maxOutputLen)
olen := uint32(0)
errStringBytes := make([]byte, maxOutputLen)
errStringLen := uint32(0)
var (
inputdata = (*C.uchar)(unsafe.Pointer(&data[0]))
inputlen = (C.uint32_t)(ilen)
outputdata = (*C.uchar)(unsafe.Pointer(&output_bytes[0]))
outputlen = (*C.uint32_t)(unsafe.Pointer(&olen))
errdata = (*C.uchar)(unsafe.Pointer(&errStringBytes[0]))
errlen = (*C.uint32_t)(unsafe.Pointer(&errStringLen))
)
result := C.run(inputdata, inputlen, outputdata, outputlen, errdata, errlen)
if result == 0 {
// parse error string
return nil, ErrSignFailed
}
return output_bytes[:olen], nil
}
// EstimateGas calls C++ implementation for a gas estimte
func EstimateGas(data []byte) (big.Int, error) {
return big.NewInt(1000000), nil
}