-
Notifications
You must be signed in to change notification settings - Fork 0
/
rustBase.js
108 lines (52 loc) · 2.08 KB
/
rustBase.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import {TextEncoder} from 'util'
let wasm, WASM_VECTOR_LEN = 0, cachedUint8Memory0 = new Uint8Array(), cachedTextEncoder = new TextEncoder('utf-8')
let getUint8Memory0 = () => {
if (cachedUint8Memory0.byteLength === 0) cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer)
return cachedUint8Memory0
},
encodeString = () => {
if(typeof cachedTextEncoder.encodeInto === 'function'){
return (arg,view) => cachedTextEncoder.encodeInto(arg, view)
}else{
return (arg,view) => {
const buf = cachedTextEncoder.encode(arg)
view.set(buf)
return {
read: arg.length,
written: buf.length
}
}
}
},
passStringToWasm0=(arg, malloc, realloc) => {
if (realloc === undefined) {
let buf = cachedTextEncoder.encode(arg),
ptr = malloc(buf.length)
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf)
WASM_VECTOR_LEN = buf.length
return ptr
}
let len = arg.length,
ptr = malloc(len),
mem = getUint8Memory0(),
offset = 0
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset)
if (code > 0x7F) break
mem[ptr + offset] = code
}
if (offset !== len) {
if (offset !== 0) arg = arg.slice(offset)
ptr = realloc(ptr, len, len = offset + arg.length * 3)
let view = getUint8Memory0().subarray(ptr + offset, ptr + len), ret = encodeString(arg, view)
offset += ret.written
}
WASM_VECTOR_LEN = offset
return ptr
}
export default (contractInstance,serializedContractStateChunk,functionName) => {
wasm=contractInstance
const ptr0 = passStringToWasm0(serializedContractStateChunk, contractInstance.__wbindgen_malloc, contractInstance.__wbindgen_realloc)
const len0 = WASM_VECTOR_LEN
return contractInstance[functionName](ptr0, len0)
}