@ar.io/sdk 2.3.0-alpha.8 → 2.3.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/README.md +29 -4
- package/bundles/web.bundle.min.js +34 -34
- package/lib/cjs/utils/ao.js +39 -9
- package/lib/cjs/version.js +1 -1
- package/lib/esm/utils/ao.js +39 -9
- package/lib/esm/version.js +1 -1
- package/lib/types/utils/ao.d.ts +7 -2
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/utils/ao.js
CHANGED
|
@@ -22,16 +22,17 @@ const zod_1 = require("zod");
|
|
|
22
22
|
const arweave_js_1 = require("../common/arweave.js");
|
|
23
23
|
const index_js_1 = require("../common/index.js");
|
|
24
24
|
const constants_js_1 = require("../constants.js");
|
|
25
|
-
async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), scheduler = constants_js_1.DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = constants_js_1.ANT_REGISTRY_ID, }) {
|
|
25
|
+
async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), scheduler = constants_js_1.DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = constants_js_1.ANT_REGISTRY_ID, logger = index_js_1.Logger.default, arweave = arweave_js_1.defaultArweave, }) {
|
|
26
26
|
const registryClient = index_js_1.ANTRegistry.init({
|
|
27
27
|
process: new index_js_1.AOProcess({
|
|
28
28
|
processId: antRegistryId,
|
|
29
29
|
ao,
|
|
30
|
+
logger,
|
|
30
31
|
}),
|
|
31
32
|
signer: signer,
|
|
32
33
|
});
|
|
33
34
|
//TODO: cache locally and only fetch if not cached
|
|
34
|
-
const luaString = (await
|
|
35
|
+
const luaString = (await arweave.transactions.getData(luaCodeTxId, {
|
|
35
36
|
decode: true,
|
|
36
37
|
string: true,
|
|
37
38
|
}));
|
|
@@ -49,8 +50,9 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
49
50
|
const aosClient = new index_js_1.AOProcess({
|
|
50
51
|
processId,
|
|
51
52
|
ao,
|
|
53
|
+
logger,
|
|
52
54
|
});
|
|
53
|
-
await aosClient.send({
|
|
55
|
+
const { id: evalId } = await aosClient.send({
|
|
54
56
|
tags: [
|
|
55
57
|
{ name: 'Action', value: 'Eval' },
|
|
56
58
|
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
@@ -59,8 +61,15 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
59
61
|
data: luaString,
|
|
60
62
|
signer,
|
|
61
63
|
});
|
|
64
|
+
logger.info(`Spawned ANT`, {
|
|
65
|
+
processId,
|
|
66
|
+
module,
|
|
67
|
+
scheduler,
|
|
68
|
+
luaCodeTxId,
|
|
69
|
+
evalId,
|
|
70
|
+
});
|
|
62
71
|
if (state) {
|
|
63
|
-
await aosClient.send({
|
|
72
|
+
const { id: initializeMsgId } = await aosClient.send({
|
|
64
73
|
tags: [
|
|
65
74
|
{ name: 'Action', value: 'Initialize-State' },
|
|
66
75
|
...(stateContractTxId !== undefined
|
|
@@ -70,22 +79,38 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
70
79
|
data: JSON.stringify(state),
|
|
71
80
|
signer,
|
|
72
81
|
});
|
|
82
|
+
logger.info(`Initialized ANT`, {
|
|
83
|
+
processId,
|
|
84
|
+
module,
|
|
85
|
+
scheduler,
|
|
86
|
+
initializeMsgId,
|
|
87
|
+
});
|
|
73
88
|
}
|
|
74
|
-
await registryClient.register({
|
|
89
|
+
const { id: antRegistrationMsgId } = await registryClient.register({
|
|
90
|
+
processId,
|
|
91
|
+
});
|
|
92
|
+
logger.info(`Registered ANT to ANT Registry`, {
|
|
93
|
+
processId,
|
|
94
|
+
module,
|
|
95
|
+
scheduler,
|
|
96
|
+
antRegistrationMsgId,
|
|
97
|
+
antRegistryId,
|
|
98
|
+
});
|
|
75
99
|
return processId;
|
|
76
100
|
}
|
|
77
101
|
exports.spawnANT = spawnANT;
|
|
78
|
-
async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), }) {
|
|
102
|
+
async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), logger = index_js_1.Logger.default, arweave = arweave_js_1.defaultArweave, }) {
|
|
79
103
|
const aosClient = new index_js_1.AOProcess({
|
|
80
104
|
processId,
|
|
81
105
|
ao,
|
|
106
|
+
logger,
|
|
82
107
|
});
|
|
83
108
|
//TODO: cache locally and only fetch if not cached
|
|
84
|
-
const luaString = (await
|
|
109
|
+
const luaString = (await arweave.transactions.getData(luaCodeTxId, {
|
|
85
110
|
decode: true,
|
|
86
111
|
string: true,
|
|
87
112
|
}));
|
|
88
|
-
const { id } = await aosClient.send({
|
|
113
|
+
const { id: evolveMsgId } = await aosClient.send({
|
|
89
114
|
tags: [
|
|
90
115
|
{ name: 'Action', value: 'Eval' },
|
|
91
116
|
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
@@ -94,7 +119,12 @@ async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_L
|
|
|
94
119
|
data: luaString,
|
|
95
120
|
signer,
|
|
96
121
|
});
|
|
97
|
-
|
|
122
|
+
logger.info(`Evolved ANT`, {
|
|
123
|
+
processId,
|
|
124
|
+
luaCodeTxId,
|
|
125
|
+
evalMsgId: evolveMsgId,
|
|
126
|
+
});
|
|
127
|
+
return evolveMsgId;
|
|
98
128
|
}
|
|
99
129
|
exports.evolveANT = evolveANT;
|
|
100
130
|
function isAoSigner(value) {
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/utils/ao.js
CHANGED
|
@@ -19,16 +19,17 @@ import { z } from 'zod';
|
|
|
19
19
|
import { defaultArweave } from '../common/arweave.js';
|
|
20
20
|
import { ANTRegistry, AOProcess, Logger } from '../common/index.js';
|
|
21
21
|
import { ANT_LUA_ID, ANT_REGISTRY_ID, AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js';
|
|
22
|
-
export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = ANT_LUA_ID, ao = connect(), scheduler = DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = ANT_REGISTRY_ID, }) {
|
|
22
|
+
export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = ANT_LUA_ID, ao = connect(), scheduler = DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = ANT_REGISTRY_ID, logger = Logger.default, arweave = defaultArweave, }) {
|
|
23
23
|
const registryClient = ANTRegistry.init({
|
|
24
24
|
process: new AOProcess({
|
|
25
25
|
processId: antRegistryId,
|
|
26
26
|
ao,
|
|
27
|
+
logger,
|
|
27
28
|
}),
|
|
28
29
|
signer: signer,
|
|
29
30
|
});
|
|
30
31
|
//TODO: cache locally and only fetch if not cached
|
|
31
|
-
const luaString = (await
|
|
32
|
+
const luaString = (await arweave.transactions.getData(luaCodeTxId, {
|
|
32
33
|
decode: true,
|
|
33
34
|
string: true,
|
|
34
35
|
}));
|
|
@@ -46,8 +47,9 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
|
|
|
46
47
|
const aosClient = new AOProcess({
|
|
47
48
|
processId,
|
|
48
49
|
ao,
|
|
50
|
+
logger,
|
|
49
51
|
});
|
|
50
|
-
await aosClient.send({
|
|
52
|
+
const { id: evalId } = await aosClient.send({
|
|
51
53
|
tags: [
|
|
52
54
|
{ name: 'Action', value: 'Eval' },
|
|
53
55
|
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
@@ -56,8 +58,15 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
|
|
|
56
58
|
data: luaString,
|
|
57
59
|
signer,
|
|
58
60
|
});
|
|
61
|
+
logger.info(`Spawned ANT`, {
|
|
62
|
+
processId,
|
|
63
|
+
module,
|
|
64
|
+
scheduler,
|
|
65
|
+
luaCodeTxId,
|
|
66
|
+
evalId,
|
|
67
|
+
});
|
|
59
68
|
if (state) {
|
|
60
|
-
await aosClient.send({
|
|
69
|
+
const { id: initializeMsgId } = await aosClient.send({
|
|
61
70
|
tags: [
|
|
62
71
|
{ name: 'Action', value: 'Initialize-State' },
|
|
63
72
|
...(stateContractTxId !== undefined
|
|
@@ -67,21 +76,37 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
|
|
|
67
76
|
data: JSON.stringify(state),
|
|
68
77
|
signer,
|
|
69
78
|
});
|
|
79
|
+
logger.info(`Initialized ANT`, {
|
|
80
|
+
processId,
|
|
81
|
+
module,
|
|
82
|
+
scheduler,
|
|
83
|
+
initializeMsgId,
|
|
84
|
+
});
|
|
70
85
|
}
|
|
71
|
-
await registryClient.register({
|
|
86
|
+
const { id: antRegistrationMsgId } = await registryClient.register({
|
|
87
|
+
processId,
|
|
88
|
+
});
|
|
89
|
+
logger.info(`Registered ANT to ANT Registry`, {
|
|
90
|
+
processId,
|
|
91
|
+
module,
|
|
92
|
+
scheduler,
|
|
93
|
+
antRegistrationMsgId,
|
|
94
|
+
antRegistryId,
|
|
95
|
+
});
|
|
72
96
|
return processId;
|
|
73
97
|
}
|
|
74
|
-
export async function evolveANT({ signer, processId, luaCodeTxId = ANT_LUA_ID, ao = connect(), }) {
|
|
98
|
+
export async function evolveANT({ signer, processId, luaCodeTxId = ANT_LUA_ID, ao = connect(), logger = Logger.default, arweave = defaultArweave, }) {
|
|
75
99
|
const aosClient = new AOProcess({
|
|
76
100
|
processId,
|
|
77
101
|
ao,
|
|
102
|
+
logger,
|
|
78
103
|
});
|
|
79
104
|
//TODO: cache locally and only fetch if not cached
|
|
80
|
-
const luaString = (await
|
|
105
|
+
const luaString = (await arweave.transactions.getData(luaCodeTxId, {
|
|
81
106
|
decode: true,
|
|
82
107
|
string: true,
|
|
83
108
|
}));
|
|
84
|
-
const { id } = await aosClient.send({
|
|
109
|
+
const { id: evolveMsgId } = await aosClient.send({
|
|
85
110
|
tags: [
|
|
86
111
|
{ name: 'Action', value: 'Eval' },
|
|
87
112
|
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
@@ -90,7 +115,12 @@ export async function evolveANT({ signer, processId, luaCodeTxId = ANT_LUA_ID, a
|
|
|
90
115
|
data: luaString,
|
|
91
116
|
signer,
|
|
92
117
|
});
|
|
93
|
-
|
|
118
|
+
logger.info(`Evolved ANT`, {
|
|
119
|
+
processId,
|
|
120
|
+
luaCodeTxId,
|
|
121
|
+
evalMsgId: evolveMsgId,
|
|
122
|
+
});
|
|
123
|
+
return evolveMsgId;
|
|
94
124
|
}
|
|
95
125
|
export function isAoSigner(value) {
|
|
96
126
|
const TagSchema = z.object({
|
package/lib/esm/version.js
CHANGED
package/lib/types/utils/ao.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import Arweave from 'arweave';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { Logger } from '../common/index.js';
|
|
3
4
|
import { AoANTRecord, AoANTState, AoClient, AoSigner, ContractSigner, WalletAddress } from '../types.js';
|
|
4
|
-
export declare function spawnANT({ signer, module, luaCodeTxId, ao, scheduler, state, stateContractTxId, antRegistryId, }: {
|
|
5
|
+
export declare function spawnANT({ signer, module, luaCodeTxId, ao, scheduler, state, stateContractTxId, antRegistryId, logger, arweave, }: {
|
|
5
6
|
signer: AoSigner;
|
|
6
7
|
module?: string;
|
|
7
8
|
luaCodeTxId?: string;
|
|
@@ -17,12 +18,16 @@ export declare function spawnANT({ signer, module, luaCodeTxId, ao, scheduler, s
|
|
|
17
18
|
};
|
|
18
19
|
stateContractTxId?: string;
|
|
19
20
|
antRegistryId?: string;
|
|
21
|
+
logger?: Logger;
|
|
22
|
+
arweave?: Arweave;
|
|
20
23
|
}): Promise<string>;
|
|
21
|
-
export declare function evolveANT({ signer, processId, luaCodeTxId, ao, }: {
|
|
24
|
+
export declare function evolveANT({ signer, processId, luaCodeTxId, ao, logger, arweave, }: {
|
|
22
25
|
signer: AoSigner;
|
|
23
26
|
processId: string;
|
|
24
27
|
luaCodeTxId?: string;
|
|
25
28
|
ao?: AoClient;
|
|
29
|
+
logger?: Logger;
|
|
30
|
+
arweave?: Arweave;
|
|
26
31
|
}): Promise<string>;
|
|
27
32
|
export declare function isAoSigner(value: unknown): value is AoSigner;
|
|
28
33
|
export declare function createAoSigner(signer: ContractSigner): AoSigner;
|
package/lib/types/version.d.ts
CHANGED