godprotocol 1.1.31 → 1.2.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/Datatypes/arr.js +559 -254
- package/Datatypes/bool.js +8 -5
- package/Datatypes/callable.js +1 -1
- package/Datatypes/cls.js +193 -24
- package/Datatypes/conf.js +2 -2
- package/Datatypes/err.js +25 -0
- package/Datatypes/func.js +89 -13
- package/Datatypes/functions/storage.js +572 -12
- package/Datatypes/functions/wallet.js +49 -0
- package/Datatypes/instance.js +87 -122
- package/Datatypes/num.js +192 -153
- package/Datatypes/str.js +188 -122
- package/Datatypes/twa.js +346 -71
- package/Datatypes/voi.js +9 -4
- package/Index.js +1 -1
- package/Instances/account.js +0 -0
- package/Instances/event.js +0 -0
- package/Instances/fold.js +103 -0
- package/Instances/folder_queries.js +46 -0
- package/Instances/response.js +31 -0
- package/Objects/Account.js +160 -110
- package/Objects/Blockweb.js +6 -11
- package/Objects/Callable.js +223 -188
- package/Objects/Chain.js +127 -142
- package/Objects/Datatypes.js +114 -588
- package/Objects/Manager.js +349 -39
- package/Objects/Oracle.js +283 -210
- package/Objects/Repository.js +12 -33
- package/Objects/Trinity.js +9 -7
- package/Objects/Utils.js +8 -8
- package/Objects/Virtual_machine.js +320 -320
- package/README.md +0 -0
- package/callables/functions/assert.js +10 -0
- package/callables/functions/display.js +2 -3
- package/callables/functions/env.js +5 -0
- package/callables/functions/event.js +14 -0
- package/callables/functions/exit.js +3 -2
- package/callables/functions/folder.js +15 -0
- package/callables/functions/get_uid.js +6 -0
- package/callables/functions/hash.js +7 -0
- package/callables/functions/import_.js +62 -0
- package/callables/functions/local.js +9 -0
- package/callables/functions/net.js +33 -18
- package/callables/functions/parse.js +35 -0
- package/callables/functions/query.js +12 -0
- package/callables/functions/render.js +9 -13
- package/callables/functions/servers.js +10 -0
- package/callables/functions/spawn.js +7 -0
- package/callables/functions/store.js +75 -0
- package/callables/functions/super_.js +24 -0
- package/callables/functions/typeof.js +32 -0
- package/callables/functions/wait.js +9 -0
- package/callables/register.js +193 -8
- package/html/create.js +110 -0
- package/html/index.js +114 -0
- package/html/load.js +165 -0
- package/html/parse.js +171 -0
- package/html/run.js +151 -0
- package/html/util.js +5 -0
- package/package.json +5 -3
- package/repos/fs.js +114 -0
- package/repos/github.js +73 -0
- package/repos/ram.js +47 -0
- package/utils/create_server.js +66 -26
- package/utils/hash.js +3 -2
- package/utils/ops.js +2 -0
- package/utils/oracle_handlers.js +7 -0
- package/utils/services.js +18 -51
- package/utils/socket_server.js +36 -0
- package/utils/vm_utils.js +271 -59
- package/callables/functions/assign.js +0 -6
package/README.md
ADDED
|
Binary file
|
|
@@ -6,12 +6,11 @@ const display = async (args) => {
|
|
|
6
6
|
let lit= new Array()
|
|
7
7
|
for(let d =0; d < data.length; d++){
|
|
8
8
|
let tum = data[d]
|
|
9
|
-
|
|
9
|
+
let v = tum && await tum.literal()
|
|
10
|
+
lit.push(v)
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
console.log(...lit)
|
|
13
|
-
|
|
14
|
-
return 0
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
export default display;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const listen = async(args_, vm)=>{
|
|
2
|
+
let {name, handler} = args_
|
|
3
|
+
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const emit = async(args_, vm)=>{
|
|
7
|
+
let {name, args, key} = args_
|
|
8
|
+
|
|
9
|
+
let res = await vm.account.emit(await name.literal(), args.to_address(), await key.literal())
|
|
10
|
+
|
|
11
|
+
return res;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {listen, emit}
|
|
@@ -2,9 +2,10 @@ const quit = async(args, vm)=>{
|
|
|
2
2
|
let {code} = args;
|
|
3
3
|
if (code) code = await code.literal()
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
let msg = `Program exit with code:${code ||0}`
|
|
6
|
+
console.log(msg)
|
|
6
7
|
|
|
7
|
-
return {
|
|
8
|
+
return await vm.throw_error({type: 'KeyBoardInterrupt', message: msg})
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export default quit
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const folder = async(args, {vm, chain})=>{
|
|
2
|
+
let {name, options} = args
|
|
3
|
+
name = await name.literal()
|
|
4
|
+
options = options && await options.literal()
|
|
5
|
+
let {physical_address, manager} = vm.account;
|
|
6
|
+
|
|
7
|
+
let fold = await manager.gds.folder(`${physical_address}/${name}`, {...options, repos: physical_address})
|
|
8
|
+
|
|
9
|
+
fold = await vm.folder(fold)
|
|
10
|
+
let acc_fold = await chain.write(fold, {raw: true})
|
|
11
|
+
|
|
12
|
+
return acc_fold
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default folder
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const import_ = async(args, {vm, chain, thread})=>{
|
|
2
|
+
let {address, identifiers} = args, account = vm.account;
|
|
3
|
+
address = await address.literal()
|
|
4
|
+
identifiers = identifiers && await identifiers.literal()
|
|
5
|
+
|
|
6
|
+
console.log(address, identifiers)
|
|
7
|
+
if (address.startsWith('@/'))
|
|
8
|
+
address = address.slice(2)
|
|
9
|
+
|
|
10
|
+
let res = await account.run({
|
|
11
|
+
address,
|
|
12
|
+
thread:{_id: thread._id, pointer: thread.pointer}
|
|
13
|
+
, callback: async(res)=>{
|
|
14
|
+
|
|
15
|
+
let id = Array.isArray(identifiers) ? [...identifiers] : [identifiers]
|
|
16
|
+
|
|
17
|
+
let twa = {}
|
|
18
|
+
for (let i=0; i< id.length; i++){
|
|
19
|
+
let iden = id[i]
|
|
20
|
+
for (let r=res.length-1; r>=0; r--){
|
|
21
|
+
let obj = res[r]
|
|
22
|
+
if (!obj) continue;
|
|
23
|
+
if (obj.type === 'address'){
|
|
24
|
+
if (obj.identifier === iden){
|
|
25
|
+
twa[iden] = obj;
|
|
26
|
+
}
|
|
27
|
+
}else if (obj.type === 'function'){
|
|
28
|
+
if (obj.address.endsWith(`/${iden}`)){
|
|
29
|
+
twa[iden] = obj
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (twa[iden]) break;
|
|
33
|
+
}
|
|
34
|
+
if (!twa[iden]) {
|
|
35
|
+
thread.results[thread.pointer-1] = await vm.throw_error({
|
|
36
|
+
type:"ImportError",
|
|
37
|
+
message: `No export - ${iden}`
|
|
38
|
+
})
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let result = twa[id[0]]
|
|
43
|
+
if (Array.isArray(identifiers)){
|
|
44
|
+
let actual_twain = {type:'twain', value: {}, location: await vm.gen_location()}
|
|
45
|
+
for (let prop in twa){
|
|
46
|
+
let res = await vm.instantiate({
|
|
47
|
+
type: 'string',
|
|
48
|
+
value: prop,
|
|
49
|
+
location: await vm.gen_location()
|
|
50
|
+
}, {chain})
|
|
51
|
+
|
|
52
|
+
actual_twain.value[await vm.hash(prop, 'sha1')] = [res, twa[prop]]
|
|
53
|
+
}
|
|
54
|
+
result = await vm.instantiate(actual_twain, {chain})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
thread.results[thread.pointer-1] = result
|
|
58
|
+
}})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
export default import_
|
|
@@ -1,26 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { gen_random_int } from "generalised-datastore/utils/functions.js";
|
|
2
|
+
import { post_request } from "../../utils/services.js";
|
|
2
3
|
|
|
3
|
-
const net = async(args, vm,
|
|
4
|
-
let {
|
|
5
|
-
let {server, path, payload, callback} = args;
|
|
6
|
-
|
|
7
|
-
server = await server.literal()
|
|
8
|
-
path = await path.literal()
|
|
9
|
-
if (!path.startsWith('/')) path = `/${path}`
|
|
4
|
+
const net = async(args, {vm, chain, call_config, thread})=>{
|
|
5
|
+
let {server, path, account, payload} = args;
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
thread.status = 'waiting'
|
|
8
|
+
path = await path.literal()
|
|
9
|
+
payload = await payload.literal()
|
|
10
|
+
let serv = server && [await server.literal()];
|
|
11
|
+
account = account ? await account.literal() : vm.account.name
|
|
12
|
+
if (!serv){
|
|
13
|
+
serv = await vm.account.manager.oracle.get_servers(`Accounts/${account}`)
|
|
14
|
+
}
|
|
12
15
|
|
|
13
|
-
let
|
|
14
|
-
|
|
16
|
+
let s = gen_random_int(serv.length-1)
|
|
17
|
+
let servr = serv[s]
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
post_request({
|
|
20
|
+
options: {
|
|
21
|
+
hostname: servr.hostname,
|
|
22
|
+
port: servr.port,
|
|
23
|
+
path: `/${path}`,
|
|
24
|
+
method: payload.header.method.toUpperCase(),
|
|
25
|
+
headers: {
|
|
26
|
+
...payload.header
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
data: payload.body && JSON.stringify(payload.body)
|
|
30
|
+
}).then(async res=>{
|
|
31
|
+
let adr = await vm.parse_aircode(res, {chain})
|
|
32
|
+
thread.results[thread.pointer-1] = adr;
|
|
33
|
+
thread.status = 'active'
|
|
34
|
+
}).catch(e=>{
|
|
35
|
+
console.log(e)
|
|
36
|
+
})
|
|
22
37
|
|
|
23
|
-
return
|
|
38
|
+
return;
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const parse = async(args, {vm})=>{
|
|
2
|
+
let {address, options} = args;
|
|
3
|
+
|
|
4
|
+
address = await address.literal()
|
|
5
|
+
options = await options.literal()
|
|
6
|
+
|
|
7
|
+
let mgr = vm.account.manager
|
|
8
|
+
let account = await mgr.get_account(options.account || vm.account.name)
|
|
9
|
+
|
|
10
|
+
let full_address = `${account.physical_address}/${address}`
|
|
11
|
+
let folder = await mgr.ds.folder(full_address)
|
|
12
|
+
let conf_folder = await folder.folder('.configs')
|
|
13
|
+
|
|
14
|
+
let config_query = options.config_query || {}
|
|
15
|
+
let query = options.query || {}
|
|
16
|
+
let conf = await conf_folder.readone(config_query.query, config_query.options), result;
|
|
17
|
+
|
|
18
|
+
if (['class', 'function'].includes(conf.type)){
|
|
19
|
+
result = {
|
|
20
|
+
type: 'function',
|
|
21
|
+
address: conf.address,
|
|
22
|
+
_id: conf._id
|
|
23
|
+
}
|
|
24
|
+
} else if(conf.type === 'instance'){
|
|
25
|
+
|
|
26
|
+
} else if (conf.type === 'module'){
|
|
27
|
+
|
|
28
|
+
}else if (conf.type === 'variable') {
|
|
29
|
+
result = await folder.readone(query.query, query.options)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return result
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default parse;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const query = async(args, {vm, thread}) => {
|
|
2
|
+
let {object, filter} = args;
|
|
3
|
+
|
|
4
|
+
object = await object.literal()
|
|
5
|
+
filter = await filter.literal()
|
|
6
|
+
|
|
7
|
+
let res = await vm.account.chain.folder().pass(object, filter)
|
|
8
|
+
|
|
9
|
+
return res;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default query
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
const render = async (args, { vm, config, chain }) => {
|
|
2
|
-
let { object } = args;
|
|
3
|
-
|
|
4
|
-
let res = await object.get("render");
|
|
5
|
-
if (!res) return null;
|
|
1
|
+
const render = async (args, { vm, config, uid, chain }) => {
|
|
2
|
+
let { object, query_selector, parent } = args;
|
|
6
3
|
|
|
4
|
+
let res = await object.get('__render__')
|
|
7
5
|
let result = await vm.execute(
|
|
8
6
|
{
|
|
9
7
|
type: "call",
|
|
10
|
-
identifier:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
object: object.value.path,
|
|
14
|
-
},
|
|
15
|
-
arguments: [],
|
|
16
|
-
location: config.location,
|
|
8
|
+
identifier: res,
|
|
9
|
+
arguments: parent ? [{ type: "address", value: parent.path }] : [],
|
|
10
|
+
location: config.location || `${chain.physical_address}/_render`,
|
|
17
11
|
},
|
|
18
|
-
{ chain }
|
|
12
|
+
{ chain, uid: object.config.uid }
|
|
19
13
|
);
|
|
20
14
|
|
|
15
|
+
console.log(result)
|
|
16
|
+
await object.set_("__config__", result);
|
|
21
17
|
return result;
|
|
22
18
|
};
|
|
23
19
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const addresses = new Object()
|
|
2
|
+
|
|
3
|
+
const retrieve = async(args, {vm, chain})=>{
|
|
4
|
+
let {address, _id} = args;
|
|
5
|
+
|
|
6
|
+
address = await address.literal()
|
|
7
|
+
_id = _id && await _id.literal()
|
|
8
|
+
|
|
9
|
+
let res = await vm.account.parse({address, _id, retrieve: true})
|
|
10
|
+
|
|
11
|
+
return res;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const store = async(args, {vm, chain, thread})=>{
|
|
15
|
+
if (!addresses) addresses = new Object()
|
|
16
|
+
let {object} = args;
|
|
17
|
+
|
|
18
|
+
let config = object.config, data, address = config.location;
|
|
19
|
+
let id = `${address}-${config._id}`
|
|
20
|
+
|
|
21
|
+
let exists = addresses[id]
|
|
22
|
+
|
|
23
|
+
if(exists){
|
|
24
|
+
if (exists.updated >= config.updated){
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
addresses[id] = {...config}
|
|
29
|
+
|
|
30
|
+
switch(config.type){
|
|
31
|
+
case 'instance':
|
|
32
|
+
if (config.methods.__store__){
|
|
33
|
+
let spli = vm._split_datapath(config.methods.__store__)
|
|
34
|
+
await object.run({identifier: {value: spli[0], _id: spli[1]}, arguments:[]}, {chain, thread})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
break;
|
|
38
|
+
case 'string':
|
|
39
|
+
address = config.location
|
|
40
|
+
break;
|
|
41
|
+
case 'number':
|
|
42
|
+
address = config.location
|
|
43
|
+
break;
|
|
44
|
+
case 'array':
|
|
45
|
+
data = await object.store({store, thread})
|
|
46
|
+
break;
|
|
47
|
+
case 'twain':
|
|
48
|
+
data = await object.store({store, thread})
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
console.log(config, "DFAULT")
|
|
52
|
+
data = await object.to_address()
|
|
53
|
+
console.log(data)
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if(!address)return;
|
|
58
|
+
|
|
59
|
+
let ds = vm.account.manager.ds
|
|
60
|
+
let folder = await ds.folder(address, {account: vm.account.physical_address})
|
|
61
|
+
let res = await folder.write(data || config, {replace: true})
|
|
62
|
+
|
|
63
|
+
if (config.type === 'instance'){
|
|
64
|
+
let class_account = config.cls.split('/').slice(0,2).join('/')
|
|
65
|
+
let class_folder_account = await (await ds.folder(config.cls)).folder(`${vm.account.physical_address}`, {account: class_account})
|
|
66
|
+
await class_folder_account.write({
|
|
67
|
+
_id: config._id,
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return data || config
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default store;
|
|
75
|
+
export {retrieve}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const super_ = async(args, {vm, call_config, thread, chain})=>{
|
|
2
|
+
let {object} = args
|
|
3
|
+
|
|
4
|
+
if (object.config.inherited.includes(call_config.cls)){
|
|
5
|
+
console.warn('Cyclic inheritance, truncating now!', call_config.cls)
|
|
6
|
+
return;
|
|
7
|
+
}else {
|
|
8
|
+
console.log(call_config.cls)
|
|
9
|
+
object.config.inherited.push(call_config.cls)
|
|
10
|
+
await (await vm.account.manager.ds.folder(object.config.location)).write(object.config, {replace: true})
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let cls = await vm.variable(call_config.cls, {chain, obj: true})
|
|
14
|
+
|
|
15
|
+
let args_ = []
|
|
16
|
+
for (let a in args.args){
|
|
17
|
+
if (a=='object') continue
|
|
18
|
+
args_.push(await args.args[a].to_address())
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
await cls.run_init({vm, args: args_, ins: await object.to_address(), thread})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default super_
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const type_of = (args, {vm})=>{
|
|
2
|
+
let {object} = args;
|
|
3
|
+
|
|
4
|
+
return object.type
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const instance_of = async(args, {vm})=>{
|
|
8
|
+
let {object} = args;
|
|
9
|
+
|
|
10
|
+
let result;
|
|
11
|
+
if (vm.datatypes.includes(object.type)){
|
|
12
|
+
result = {
|
|
13
|
+
type: 'address',
|
|
14
|
+
value: object.type,
|
|
15
|
+
_id: object.type,
|
|
16
|
+
config: true
|
|
17
|
+
}
|
|
18
|
+
}else if(['class', 'function'].includes(object.type)){
|
|
19
|
+
result = await vm.voided()
|
|
20
|
+
}else if (object.type === 'instance'){
|
|
21
|
+
result = {
|
|
22
|
+
type: 'function',
|
|
23
|
+
address: object.config.cls,
|
|
24
|
+
_id: object.config.cls_id,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default type_of
|
|
32
|
+
export {instance_of}
|