-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPARSE_CALL.sql
35 lines (32 loc) · 924 Bytes
/
PARSE_CALL.sql
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
CREATE OR REPLACE FUNCTION `abi_functions`.PARSE_CALL(abi STRING, dat STRING) RETURNS ARRAY<STRUCT<arg STRING, val STRING>> LANGUAGE js AS """
abi = JSON.parse(abi);
var interface_instance = new ethers.utils.Interface(abi);
txargs = [];
txtypes = [];
res = [];
// try-catch - input may be malformed.
try {
var pt = interface_instance.parseTransaction({data: dat});
frag = "";
abi.forEach(function(x){
if (x.name == pt.name) {
frag = x;
}
});
txvals = pt.args;
//txtypes[pt.name]
frag.inputs.forEach(function(x) {
txargs.push(x.name);
txtypes.push(x.type);
});
for (i = 0; i < txvals.length; i++) {
val = txvals[i];
if (txtypes[i] == 'address') {
val = val.toLowerCase();
}
res.push({arg:txargs[i],val:val});
}
} catch(e) {}
return res;
"""
OPTIONS(library="gs://blockchain-etl-bigquery/ethers.js");