-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathfvm.go
94 lines (82 loc) · 2.91 KB
/
fvm.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package cgo
/*
#cgo LDFLAGS: -L${SRCDIR}/..
#cgo pkg-config: ${SRCDIR}/../filcrypto.pc
#include "../filcrypto.h"
#include <stdlib.h>
*/
import "C"
func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, tracing, flushAllBlocks bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
resp := (*resultFvmMachine)(C.create_fvm_machine(
(C.FvmRegisteredVersion_t)(fvmVersion),
C.uint64_t(chainEpoch),
C.uint64_t(chainTimestamp),
C.uint64_t(chainId),
C.uint64_t(baseFeeHi),
C.uint64_t(baseFeeLo),
C.uint64_t(baseCircSupplyHi),
C.uint64_t(baseCircSupplyLo),
C.uint32_t(networkVersion),
(C.slice_ref_uint8_t)(stateRoot),
C.bool(tracing),
C.bool(flushAllBlocks),
C.uint64_t(blockstoreId),
C.uint64_t(externsId),
))
// take out the pointer from the result to ensure it doesn't get freed
executor := (*FvmMachine)(resp.value)
resp.value = nil
defer resp.destroy()
if err := CheckErr(resp); err != nil {
return nil, err
}
return executor, nil
}
func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, actorRedirect SliceRefUint8, tracing, flushAllBlocks bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
resp := (*resultFvmMachine)(C.create_fvm_debug_machine(
(C.FvmRegisteredVersion_t)(fvmVersion),
C.uint64_t(chainEpoch),
C.uint64_t(chainTimestamp),
C.uint64_t(chainId),
C.uint64_t(baseFeeHi),
C.uint64_t(baseFeeLo),
C.uint64_t(baseCircSupplyHi),
C.uint64_t(baseCircSupplyLo),
C.uint32_t(networkVersion),
(C.slice_ref_uint8_t)(stateRoot),
(C.slice_ref_uint8_t)(actorRedirect),
C.bool(tracing),
C.bool(flushAllBlocks),
C.uint64_t(blockstoreId),
C.uint64_t(externsId),
))
// take out the pointer from the result to ensure it doesn't get freed
executor := (*FvmMachine)(resp.value)
resp.value = nil
defer resp.destroy()
if err := CheckErr(resp); err != nil {
return nil, err
}
return executor, nil
}
func FvmMachineExecuteMessage(executor *FvmMachine, message SliceRefUint8, chainLen, applyKind uint64) (FvmMachineExecuteResponseGo, error) {
resp := (*resultFvmMachineExecuteResponse)(C.fvm_machine_execute_message(
(*C.InnerFvmMachine_t)(executor),
(C.slice_ref_uint8_t)(message),
C.uint64_t(chainLen),
C.uint64_t(applyKind),
))
defer resp.destroy()
if err := CheckErr(resp); err != nil {
return FvmMachineExecuteResponseGo{}, err
}
return (FvmMachineExecuteResponse)(resp.value).copy(), nil
}
func FvmMachineFlush(executor *FvmMachine) ([]byte, error) {
resp := (*resultSliceBoxedUint8)(C.fvm_machine_flush((*C.InnerFvmMachine_t)(executor)))
defer resp.destroy()
if err := CheckErr(resp); err != nil {
return nil, err
}
return (SliceBoxedUint8)(resp.value).copy(), nil
}