godprotocol 1.0.7991 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Executables/callables.js +131 -0
- package/Executables/executables.js +230 -0
- package/Executables/functions/adminstrator/adm_register.js +29 -0
- package/Executables/functions/adminstrator/native_components.js +10 -0
- package/Executables/functions/adminstrator/query_selectors.js +10 -0
- package/Executables/functions/adminstrator/render.js +24 -0
- package/Executables/functions/array_register.js +161 -0
- package/Executables/functions/assign.js +19 -0
- package/Executables/functions/display.js +55 -0
- package/Executables/functions/folder.js +95 -0
- package/Executables/functions/folder_register.js +87 -0
- package/Executables/functions/importcheck.js +13 -0
- package/Executables/functions/indices.js +56 -0
- package/Executables/functions/len.js +22 -0
- package/Executables/functions/methods/array.js +272 -0
- package/Executables/functions/methods/string.js +197 -0
- package/Executables/functions/methods/twain.js +148 -0
- package/Executables/functions/op.js +15 -0
- package/Executables/functions/price_register.js +30 -0
- package/Executables/functions/pricing.js +26 -0
- package/Executables/functions/servers/account.js +81 -0
- package/Executables/functions/servers/account_register.js +56 -0
- package/Executables/functions/servers/block.js +21 -0
- package/Executables/functions/servers/block_register.js +18 -0
- package/Executables/functions/servers/chain.js +42 -0
- package/Executables/functions/servers/chain_register.js +28 -0
- package/Executables/functions/set_error_catch.js +34 -0
- package/Executables/functions/string_register.js +130 -0
- package/Executables/functions/twain_register.js +56 -0
- package/Executables/functions/typecast.js +43 -0
- package/Executables/functions/utils.js +9 -0
- package/Executables/stack.js +53 -0
- package/Index.js +2 -7
- package/Loader_sequence/main.js +535 -119
- package/Loader_sequence/repository.js +33 -0
- package/Objects/Account.js +220 -54
- package/Objects/Block.js +46 -16
- package/Objects/Blockweb.js +14 -0
- package/Objects/Chain.js +163 -16
- package/Objects/Fee.js +33 -0
- package/Objects/Filesystem.js +100 -26
- package/Objects/Frame.js +10 -3
- package/Objects/Manager.js +272 -46
- package/Objects/Opcodes.js +60 -10
- package/Objects/Oracle.js +90 -5
- package/Objects/Protocol.js +5 -0
- package/Objects/Virtual_machine.js +145 -53
- package/Trinity.js +20 -0
- package/callables.js +172 -0
- package/framer.js +111 -52
- package/opcodes/add.js +6 -6
- package/opcodes/indices.js +82 -0
- package/opcodes/jmp.js +12 -11
- package/opcodes/std.js +7 -2
- package/opcodes.js +72 -14
- package/package.json +6 -5
- package/readme.md +1 -1
- package/starter_scripts/constants.seq +11 -0
- package/utils/create_server.js +34 -27
- package/utils/hash.js +2 -2
- package/utils/logger.js +79 -0
- package/utils/services.js +5 -3
- package/utils/type_coersion.js +3 -0
- package/utils/vm_utils.js +292 -0
- package/.babelrc +0 -3
- package/build/Account.js +0 -162
- package/build/Block.js +0 -65
- package/build/Blockweb.js +0 -36
- package/build/Chain.js +0 -119
- package/build/Explorer.js +0 -47
- package/build/Filesystem.js +0 -127
- package/build/Frame.js +0 -52
- package/build/Index.js +0 -15
- package/build/Manager.js +0 -99
- package/build/Opcodes.js +0 -39
- package/build/Oracle.js +0 -42
- package/build/Virtual_machine.js +0 -128
- package/build/add.js +0 -41
- package/build/create_server.js +0 -119
- package/build/framer.js +0 -57
- package/build/functions.js +0 -82
- package/build/hash.js +0 -14
- package/build/jmp.js +0 -19
- package/build/main.js +0 -283
- package/build/opcodes.js +0 -42
- package/build/privacy.js +0 -27
- package/build/services.js +0 -50
- package/build/std.js +0 -11
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import typecast from "../typecast";
|
|
2
|
+
|
|
3
|
+
const slice = (args, vm, options)=>{
|
|
4
|
+
let {str, start, end} = args;
|
|
5
|
+
|
|
6
|
+
if(start.__classifier__ !== vm.get_type_address('number')){
|
|
7
|
+
return {result:str}
|
|
8
|
+
}else start = vm.static_value(start)
|
|
9
|
+
|
|
10
|
+
if(!end || (end && end.__classifier__ !== vm.get_type_address('number'))){
|
|
11
|
+
end = {static_value: undefined}
|
|
12
|
+
}else end = vm.static_value(end)
|
|
13
|
+
|
|
14
|
+
vm.exec({executable:str.__print__, location:(result)=>{
|
|
15
|
+
let new_val = result.static_value.slice(start.static_value, end.static_value)
|
|
16
|
+
|
|
17
|
+
vm.air_object(new_val, options)
|
|
18
|
+
}})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const case_ = (args, vm, options)=>{
|
|
22
|
+
let {str, type} = args;
|
|
23
|
+
|
|
24
|
+
if(str.__classifier__ !== vm.get_type_address('string')){
|
|
25
|
+
return {result:null}
|
|
26
|
+
}
|
|
27
|
+
if (type.__classifier__ !== vm.get_type_address('number')){
|
|
28
|
+
return {result: str}
|
|
29
|
+
}else type = vm.static_value(type)
|
|
30
|
+
|
|
31
|
+
vm.exec({executable: str.__print__, location:(result)=>{
|
|
32
|
+
let new_val = result.static_value;
|
|
33
|
+
|
|
34
|
+
switch(type.static_value){
|
|
35
|
+
case 1:
|
|
36
|
+
new_val = new_val.toUpperCase()
|
|
37
|
+
break;
|
|
38
|
+
case 2:
|
|
39
|
+
new_val = new_val.toLowerCase()
|
|
40
|
+
break;
|
|
41
|
+
case 3:
|
|
42
|
+
let nv = new_val.split(' ')
|
|
43
|
+
new_val = ''
|
|
44
|
+
nv.map(n=>{
|
|
45
|
+
new_val = `${new_val} ${n[0].toUpperCase()}${n.slice(1).toLowerCase()}`
|
|
46
|
+
})
|
|
47
|
+
new_val = new_val.trim()
|
|
48
|
+
break;
|
|
49
|
+
default:;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
vm.air_object(new_val, options)
|
|
53
|
+
}})
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const concat_ = (str, other, index)=> {
|
|
58
|
+
if (index === undefined || index > str.length) {
|
|
59
|
+
index = str.length;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let start = str.slice(0, index);
|
|
63
|
+
let end = str.slice(index);
|
|
64
|
+
|
|
65
|
+
str = `${start}${other}${end}`;
|
|
66
|
+
return str;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const concat = (args, vm, options)=>{
|
|
70
|
+
let {str, other, index} = args;
|
|
71
|
+
|
|
72
|
+
if (other.__classifier__ !== vm.get_type_address('string')){
|
|
73
|
+
other = typecast({obj: vm.static_value(other), type: {static_value:'string'}})
|
|
74
|
+
}
|
|
75
|
+
if (!index || (index && index.__classifier__ !== vm.get_type_address('number')))
|
|
76
|
+
index = {static_value:undefined}
|
|
77
|
+
else index = vm.static_value(index)
|
|
78
|
+
|
|
79
|
+
vm.exec({executable: str.__print__, location: result=>{
|
|
80
|
+
let res = concat_(result.static_value, other.static_value, index.static_value)
|
|
81
|
+
vm.air_object(res, options)
|
|
82
|
+
}})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
const index = (args, vm, options)=>{
|
|
87
|
+
let {str, n} = args;
|
|
88
|
+
|
|
89
|
+
if (n.__classifier__ !== vm.get_type_address('number')){
|
|
90
|
+
return vm.air_object(null, options)
|
|
91
|
+
}else n = vm.static_value(n)
|
|
92
|
+
|
|
93
|
+
vm.exec({executable: str.__print__, location:result=>{
|
|
94
|
+
vm.air_object(result.static_value[n.static_value] || null, options)
|
|
95
|
+
}})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
const indexof = (args, vm, options)=>{
|
|
100
|
+
let {str, char} = args;
|
|
101
|
+
|
|
102
|
+
if (char.__classifier__ !== vm.get_type_address('string')){
|
|
103
|
+
return vm.air_object(-1, options)
|
|
104
|
+
}else char = vm.static_value(char)
|
|
105
|
+
|
|
106
|
+
vm.exec({executable: str.__print__, location: result=>{
|
|
107
|
+
vm.air_object(result.static_value.indexOf(char.static_value), options)
|
|
108
|
+
}})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
const includes = (args, vm, options)=>{
|
|
113
|
+
let {str, chars} = args;
|
|
114
|
+
|
|
115
|
+
if (chars.__classifier__ !== vm.get_type_address('string')){
|
|
116
|
+
return vm.air_object(false, options)
|
|
117
|
+
}else chars = vm.static_value(chars)
|
|
118
|
+
|
|
119
|
+
vm.exec({executable: str.__print__, location: result=>{
|
|
120
|
+
vm.air_object(result.static_value.includes(chars.static_value), options)
|
|
121
|
+
}})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const split = (args, vm, options)=>{
|
|
125
|
+
let {str, char} = args;
|
|
126
|
+
|
|
127
|
+
if (!char){
|
|
128
|
+
if (char.__classifier__ !== vm.get_type_address('string')){
|
|
129
|
+
return vm.air_object([str], {...options, flat:true})
|
|
130
|
+
}else char = vm.static_value(char)
|
|
131
|
+
}else char = {static_value: ' '}
|
|
132
|
+
|
|
133
|
+
vm.exec({executable: str.__print__, location: result=>{
|
|
134
|
+
vm.air_object(result.static_value.split(char.static_value), options)
|
|
135
|
+
}})
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const trim_start=(str, chars)=> {
|
|
140
|
+
let regex = new RegExp(`^[${chars}]+`, 'g');
|
|
141
|
+
return str.replace(regex, '');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const trim_end=(str, chars)=> {
|
|
145
|
+
let regex = new RegExp(`[${chars}]+$`, 'g');
|
|
146
|
+
return str.replace(regex, '');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const trimmer=(str, chars)=> {
|
|
150
|
+
return trim_start(trim_end(str, chars), chars);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const trim = (args, vm, options) =>{
|
|
154
|
+
let {str, char, type} = args;
|
|
155
|
+
|
|
156
|
+
if (!char || (char.__classifier__ !== vm.get_type_address('string'))){
|
|
157
|
+
char = {static_value: ' '}
|
|
158
|
+
}else char = vm.static_value(char)
|
|
159
|
+
|
|
160
|
+
if ( !type || (type.__classifier__ !== vm.get_type_address('number'))) type = {static_value: 0}
|
|
161
|
+
else type = vm.static_value(type)
|
|
162
|
+
|
|
163
|
+
vm.exec({executable: str.__print__, location: result=>{
|
|
164
|
+
let val = result.static_value
|
|
165
|
+
switch(type.static_value){
|
|
166
|
+
case 0:
|
|
167
|
+
val = trimmer(val, char.static_value)
|
|
168
|
+
break;
|
|
169
|
+
case 1:
|
|
170
|
+
val = trim_start(val, char.static_value)
|
|
171
|
+
break;
|
|
172
|
+
case 2:
|
|
173
|
+
val = trim_end(val, char.static_value)
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
vm.air_object(val, options)
|
|
177
|
+
}})
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const repeat = (args, vm, options)=>{
|
|
181
|
+
let {str,n } = args
|
|
182
|
+
|
|
183
|
+
if (!n){
|
|
184
|
+
return {result:str}
|
|
185
|
+
}
|
|
186
|
+
if (n.__classifier__ !== vm.get_type_address('number')){
|
|
187
|
+
return vm.air_object(null, options)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
n = vm.static_value(n)
|
|
191
|
+
|
|
192
|
+
vm.exec({executable: str.__print__, location: result => {
|
|
193
|
+
vm.air_object(result.static_value.repeat(n.static_value), options)
|
|
194
|
+
}})
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export {slice, index, indexof, concat, case_, split, trim, repeat, includes}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
let hash_for_twain = (str, vm) => {
|
|
2
|
+
let hash = vm.account.manager.oracle.hash;
|
|
3
|
+
let val = hash(str, "sha-1");
|
|
4
|
+
|
|
5
|
+
if (!isNaN(parseInt(val[0]))) val = `_${val.slice(0, -1)}`;
|
|
6
|
+
|
|
7
|
+
return val;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const get = (args, vm, options) => {
|
|
11
|
+
let { twain, prop } = args;
|
|
12
|
+
|
|
13
|
+
if (twain.__classifier__ !== vm.get_type_address("twain")) {
|
|
14
|
+
return vm.stderr({
|
|
15
|
+
name: "Type_error",
|
|
16
|
+
message: "Must be of type `twain`",
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let static_twain = vm.static_value(twain);
|
|
21
|
+
|
|
22
|
+
vm.exec({
|
|
23
|
+
executable: prop.__print__,
|
|
24
|
+
location: (prop_result) => {
|
|
25
|
+
prop_result = vm.static_value(prop_result);
|
|
26
|
+
|
|
27
|
+
let val = hash_for_twain(prop_result.static_value, vm);
|
|
28
|
+
|
|
29
|
+
let pair = static_twain.static_value[val];
|
|
30
|
+
if (!pair) vm.air_object(null, options);
|
|
31
|
+
else {
|
|
32
|
+
let value = vm.read_chain(pair[1], { tell_callable: true });
|
|
33
|
+
vm.write_chain(value.output, options.location, {
|
|
34
|
+
is_callable: value.callable,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const set = (args, vm, options) => {
|
|
42
|
+
let { twain, prop, value } = args;
|
|
43
|
+
|
|
44
|
+
if (twain.__classifier__ !== vm.get_type_address("twain")) {
|
|
45
|
+
return vm.stderr({
|
|
46
|
+
name: "Type_error",
|
|
47
|
+
message: "Must be of type `twain`",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let static_twain = vm.static_value(twain);
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
![
|
|
55
|
+
vm.get_type_address("number"),
|
|
56
|
+
vm.get_type_address("string"),
|
|
57
|
+
vm.get_type_address("boolean"),
|
|
58
|
+
vm.get_type_address("void"),
|
|
59
|
+
].includes(prop.__classifier__)
|
|
60
|
+
) {
|
|
61
|
+
return vm.stderr({
|
|
62
|
+
name: "Key_error",
|
|
63
|
+
message: "Key type is not hashable",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let prop_static = vm.static_value(prop);
|
|
68
|
+
let val = hash_for_twain(prop_static.static_value, vm);
|
|
69
|
+
|
|
70
|
+
static_twain.static_value[val] = [prop.__address__, value.__address__];
|
|
71
|
+
|
|
72
|
+
vm.write_chain(static_twain, static_twain.__address__);
|
|
73
|
+
|
|
74
|
+
vm.air_object(Object.keys(static_twain.static_value).length, options);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const entries = (args, vm, options) => {
|
|
78
|
+
let { twain } = args;
|
|
79
|
+
|
|
80
|
+
if (twain.__classifier__ !== vm.get_type_address("twain")) {
|
|
81
|
+
return vm.stderr({
|
|
82
|
+
name: "Type_error",
|
|
83
|
+
message: "Must be of type `twain`",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let static_twain = vm.static_value(twain);
|
|
88
|
+
let statics = [], rrays = [];
|
|
89
|
+
|
|
90
|
+
for (let s in static_twain.static_value) {
|
|
91
|
+
let addr = `${twain.__address__}/${s}`;
|
|
92
|
+
rrays.push(static_twain.static_value[s])
|
|
93
|
+
statics.push(addr);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let local_addresses = statics.map((s) => `${s}_object`);
|
|
97
|
+
|
|
98
|
+
local_addresses.map((l, i)=>{
|
|
99
|
+
vm.air_object(rrays[i], {...options, location:l})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
vm.air_object(local_addresses, options)
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const keys = (args, vm, options) => {
|
|
106
|
+
let { twain } = args;
|
|
107
|
+
|
|
108
|
+
if (twain.__classifier__ !== vm.get_type_address("twain")) {
|
|
109
|
+
return vm.stderr({
|
|
110
|
+
name: "Type_error",
|
|
111
|
+
message: "Must be of type `twain`",
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let static_twain = vm.static_value(twain);
|
|
116
|
+
let statics = [];
|
|
117
|
+
|
|
118
|
+
for (let s in static_twain.static_value) {
|
|
119
|
+
statics.push(static_twain.static_value[s][0]);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
vm.air_object(statics, options)
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const unset = (args, vm, options) => {
|
|
126
|
+
let {twain, prop} = args;
|
|
127
|
+
|
|
128
|
+
let prop_static = vm.static_value(prop)
|
|
129
|
+
let twain_static = vm.static_value(twain)
|
|
130
|
+
|
|
131
|
+
let hash = hash_for_twain(prop_static.static_value)
|
|
132
|
+
let has = twain_static.static_value.hasOwnProperty(hash)
|
|
133
|
+
if (!has){
|
|
134
|
+
return vm.air_object(null, options)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let value = twain_static.static_value[hash]
|
|
138
|
+
|
|
139
|
+
let value_obj = vm.read_chain(value[1], {tell_callable:true})
|
|
140
|
+
|
|
141
|
+
delete twain_static.static_value[hash]
|
|
142
|
+
|
|
143
|
+
vm.write_chain(twain_static, twain_static.__address__)
|
|
144
|
+
|
|
145
|
+
vm.write_chain(value_obj.output, options.location, {is_callable: value_obj.callable})
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export { get, set, entries, keys, unset };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const operation = (args, vm, options)=>{
|
|
2
|
+
let {op} = options
|
|
3
|
+
let {left, right }= args;
|
|
4
|
+
|
|
5
|
+
vm.exec({executable: left.__print__, location: (result1)=>{
|
|
6
|
+
if(right){
|
|
7
|
+
vm.exec({executable: right.__print__, location: (result2)=>{
|
|
8
|
+
vm.air_object(vm.run_opcode([result1, result2], op), options)
|
|
9
|
+
}})
|
|
10
|
+
}else vm.air_object(vm.run_opcode([result1], op), options)
|
|
11
|
+
}})
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default operation
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { price } from "./pricing"
|
|
2
|
+
|
|
3
|
+
const price_register = (account)=>{
|
|
4
|
+
let add_callable = account.vm.add_callable
|
|
5
|
+
|
|
6
|
+
add_callable('price_', {
|
|
7
|
+
callable: price,
|
|
8
|
+
config: {
|
|
9
|
+
parameters: [
|
|
10
|
+
{name: 'commodity', position:0},
|
|
11
|
+
{name: 'purpose', position:1},
|
|
12
|
+
{name: 'fee', position:2},
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
add_callable('pay_', {
|
|
18
|
+
callable: price,
|
|
19
|
+
config: {
|
|
20
|
+
parameters: [
|
|
21
|
+
{name: 'payer', position:0},
|
|
22
|
+
{name: 'purpose', position:1},
|
|
23
|
+
{name: 'fee', position:2},
|
|
24
|
+
{name: 'payee', position:3},
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default price_register
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const price = (args, vm, options)=>{
|
|
2
|
+
let {commodity, purpose, validator, fee} = args;
|
|
3
|
+
|
|
4
|
+
let addr = commodity.__address__
|
|
5
|
+
let chain = vm.handle_chain(addr)
|
|
6
|
+
chain.set_fee({purpose, validator, fee})
|
|
7
|
+
|
|
8
|
+
return {result: commodity}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const pay = (args, vm, options) =>{
|
|
12
|
+
let {payer, purpose, fee, payee, callback} = args;
|
|
13
|
+
|
|
14
|
+
let chain = vm.handle_chain(payee.__address__)
|
|
15
|
+
let pass = chain.pay(purpose, fee, payer, (pass)=>{
|
|
16
|
+
pass = vm.display(pass)
|
|
17
|
+
if(pass.static_value !== true) return vm.air_object(null, options)
|
|
18
|
+
|
|
19
|
+
vm.exec({executable: callback, location: options.location, arguments: {argc:1, argv:[{position:0, static_value: pass.payload}]}})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return {result: pass}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export {price, pay}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const connect = (args, vm, options)=>{
|
|
2
|
+
let {name, meta} = args;
|
|
3
|
+
|
|
4
|
+
if (name.__classifier__ !== vm.get_type_address('string')){
|
|
5
|
+
return vm.stderr({name:'Type_error', message: 'Account name must be a string'})
|
|
6
|
+
}
|
|
7
|
+
if (meta.__classifier__ !== vm.get_type_address('twain')){
|
|
8
|
+
return vm.stderr({name:'Type_error', message: 'Account name must be a twain'})
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
name = vm.display(name)
|
|
12
|
+
meta = vm.display(meta)
|
|
13
|
+
|
|
14
|
+
let result = vm.account.manager.add_account(name, {...meta, string:true})
|
|
15
|
+
|
|
16
|
+
vm.air_object(result, options)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const load = (args, vm, options)=>{
|
|
20
|
+
let {account, payload} = args;
|
|
21
|
+
|
|
22
|
+
if (account.__classifier__ !== vm.get_type_address('account')){
|
|
23
|
+
return vm.stderr({name:'Type_error', message: 'account must be an Account instance'})
|
|
24
|
+
}
|
|
25
|
+
if (payload.__classifier__ !== vm.get_type_address('twain')){
|
|
26
|
+
return vm.stderr({name:'Type_error', message: 'Payload must be a twain'})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
account = vm.display(account, )
|
|
30
|
+
payload = vm.display(payload, )
|
|
31
|
+
|
|
32
|
+
vm.account.manager.endpoint('load', payload, (response)=>{
|
|
33
|
+
vm.air_object(response, options)
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const run = (args, vm, options)=>{
|
|
38
|
+
let {account, payload} = args;
|
|
39
|
+
|
|
40
|
+
if (account.__classifier__ !== vm.get_type_address('account')){
|
|
41
|
+
return vm.stderr({name:'Type_error', message: 'account must be an Account instance'})
|
|
42
|
+
}
|
|
43
|
+
if (payload.__classifier__ !== vm.get_type_address('twain')){
|
|
44
|
+
return vm.stderr({name:'Type_error', message: 'Payload must be a twain'})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
account = vm.display(account)
|
|
48
|
+
payload = vm.display(payload)
|
|
49
|
+
|
|
50
|
+
vm.account.manager.endpoint('run', payload, (response)=>{
|
|
51
|
+
vm.air_object(response, options)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const parse = (args, vm, options)=>{
|
|
56
|
+
let {account, payload} = args;
|
|
57
|
+
|
|
58
|
+
if (account.__classifier__ !== vm.get_type_address('account')){
|
|
59
|
+
return vm.stderr({name:'Type_error', message: 'account must be an Account instance'})
|
|
60
|
+
}
|
|
61
|
+
if (payload.__classifier__ !== vm.get_type_address('twain')){
|
|
62
|
+
return vm.stderr({name:'Type_error', message: 'Payload must be a twain'})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
account = vm.display(account)
|
|
66
|
+
payload = vm.display(payload)
|
|
67
|
+
|
|
68
|
+
vm.account.manager.endpoint('parse', payload, (response)=>{
|
|
69
|
+
vm.air_object(response, options)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const servers = (args, vm, options) => {
|
|
74
|
+
let {account} = args;
|
|
75
|
+
account = vm.display(account, (res)=>{
|
|
76
|
+
let acc = vm.account.manager.get_account(res.name);
|
|
77
|
+
vm.air_object(acc.get_servers(), options)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export {run, load, servers, parse, connect}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { connect, load, parse, run, servers } from "godprotocol/Executables/functions/servers/account";
|
|
2
|
+
|
|
3
|
+
const account_register = (account)=>{
|
|
4
|
+
let add_callable = account.vm.add_callable;
|
|
5
|
+
|
|
6
|
+
add_callable('connect_', {
|
|
7
|
+
callable: connect,
|
|
8
|
+
config: {
|
|
9
|
+
parameters: [
|
|
10
|
+
{name:'name', position:0},
|
|
11
|
+
{name:'meta', position:1},
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
add_callable('load_', {
|
|
17
|
+
callable: load,
|
|
18
|
+
config: {
|
|
19
|
+
parameters: [
|
|
20
|
+
{name:'account', position:0},
|
|
21
|
+
{name:'payload', position:1},
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
add_callable('parse_', {
|
|
27
|
+
callable: parse,
|
|
28
|
+
config: {
|
|
29
|
+
parameters: [
|
|
30
|
+
{name:'account', position:0},
|
|
31
|
+
{name:'payload', position:1},
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
add_callable('run_', {
|
|
37
|
+
callable: run,
|
|
38
|
+
config: {
|
|
39
|
+
parameters: [
|
|
40
|
+
{name:'account', position:0},
|
|
41
|
+
{name:'payload', position:1},
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
add_callable('servers_', {
|
|
47
|
+
callable: servers,
|
|
48
|
+
config: {
|
|
49
|
+
parameters: [
|
|
50
|
+
{name:'account', position:0}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default account_register;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const get_block = (args, vm, options) =>{
|
|
2
|
+
let {hash, chain} = args;
|
|
3
|
+
|
|
4
|
+
if (hash.__classifier__ !== vm.get_type_address('string')){
|
|
5
|
+
return vm.stderr({name:"Type_error", message:"Hash must be of type string"})
|
|
6
|
+
}
|
|
7
|
+
if (chain.__classifier__ !== vm.get_type_address('chain')){
|
|
8
|
+
return vm.stderr({name:"Type_error", message:"chain must be of instance `Chain`"})
|
|
9
|
+
}
|
|
10
|
+
hash = vm.display(hash, true)
|
|
11
|
+
|
|
12
|
+
vm.display(chain, res=>{
|
|
13
|
+
let chain = vm.account.manager.web.get(res.physical_address)
|
|
14
|
+
let blk = chain.explore(JSON.stringify({blocks: hash}))
|
|
15
|
+
blk = blk && blk.stringify()
|
|
16
|
+
|
|
17
|
+
vm.air_object(blk, options)
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {get_block}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { get_block } from "./block";
|
|
2
|
+
|
|
3
|
+
const block_register = (account)=>{
|
|
4
|
+
let add_callable = account.vm.add_callable;
|
|
5
|
+
|
|
6
|
+
add_callable('get_block_', {
|
|
7
|
+
callable: get_block,
|
|
8
|
+
config: {
|
|
9
|
+
parameters: [
|
|
10
|
+
{name:'hash', position:0},
|
|
11
|
+
{name:'chain', position:1},
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export default block_register
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const get_chain = (args, vm, options) =>{
|
|
2
|
+
let {physical_address, account} = args;
|
|
3
|
+
|
|
4
|
+
if (account.__classifier__ !== vm.get_type_address('account')){
|
|
5
|
+
return vm.stderr({name:'Type_error', message: 'account must be an Account instance'})
|
|
6
|
+
}
|
|
7
|
+
if (physical_address.__classifier__ !== vm.get_type_address('string')){
|
|
8
|
+
return vm.stderr({name:'Type_error', message: 'physical_address must be a string'})
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
physical_address = vm.display(physical_address)
|
|
12
|
+
|
|
13
|
+
vm.display(account, res=>{
|
|
14
|
+
let acc = vm.account.manager.get_account(res.name)
|
|
15
|
+
|
|
16
|
+
let addr = acc.resolve_address(physical_address)
|
|
17
|
+
let chain = vm.account.manager.web.get(addr)
|
|
18
|
+
|
|
19
|
+
vm.air_object(chain && chain.stringify(), options)
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const explore = (args, vm, options)=>{
|
|
24
|
+
let {chain, query} = args;
|
|
25
|
+
|
|
26
|
+
if (![vm.get_type_address('string'), vm.get_type_address('twain')].includes(query.__classifier__)){
|
|
27
|
+
return vm.stderr({name:"Type_error", message: "query must be of type string | twain"})
|
|
28
|
+
}
|
|
29
|
+
query = vm.display(query, true)
|
|
30
|
+
if(typeof query !== 'string')query = JSON.stringify(query)
|
|
31
|
+
|
|
32
|
+
vm.display(chain, res=>{
|
|
33
|
+
let chn = vm.account.manager.web.get(res.physical_address)
|
|
34
|
+
if (!chn)return vm.stderr({name: 'Chain_error', message: `${res.physical_address} not set.`})
|
|
35
|
+
|
|
36
|
+
let blk = chn.explore(query)
|
|
37
|
+
|
|
38
|
+
vm.air_object(blk && blk.stringify(), options)
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {get_chain, explore}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { explore, get_chain } from "./chain";
|
|
2
|
+
|
|
3
|
+
const chain_register = (account)=>{
|
|
4
|
+
let add_callable = account.vm.add_callable;
|
|
5
|
+
|
|
6
|
+
add_callable('get_block_', {
|
|
7
|
+
callable: get_chain,
|
|
8
|
+
config: {
|
|
9
|
+
parameters: [
|
|
10
|
+
{name:'physical_address', position:0},
|
|
11
|
+
{name:'account', position:1},
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
add_callable('explore_', {
|
|
17
|
+
callable: explore,
|
|
18
|
+
config: {
|
|
19
|
+
parameters: [
|
|
20
|
+
{name:'chain', position:0},
|
|
21
|
+
{name:'query', position:1},
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export default chain_register
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const set_error_catch = (args, vm)=>{
|
|
2
|
+
// console.log(args)
|
|
3
|
+
let {object, metadata} = args
|
|
4
|
+
|
|
5
|
+
let inst = vm.track.sequence[vm.track.pointer +6]
|
|
6
|
+
inst = parseInt(inst.split(' ')[1])
|
|
7
|
+
|
|
8
|
+
for (let o=0; o< object.length; o++){
|
|
9
|
+
let obj_addr = object[o]
|
|
10
|
+
let obj, statc;
|
|
11
|
+
if (obj_addr === '*'){
|
|
12
|
+
obj = obj_addr
|
|
13
|
+
}else{
|
|
14
|
+
obj = vm.read_chain(obj_addr)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (obj !== '*'){
|
|
18
|
+
let name = vm.read_chain(obj.name_id)
|
|
19
|
+
|
|
20
|
+
statc = vm.static_value(name)
|
|
21
|
+
if(statc.static_value == null){
|
|
22
|
+
return this.stderr(`Invalid argument to an Error object`)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
vm.push_int(statc? statc.static_value: obj, {object: obj, metadata, catch_pointer: inst})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
vm.track.pointer += 17
|
|
30
|
+
|
|
31
|
+
vm.pop_context()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default set_error_catch
|