@ar.io/sdk 1.2.0-alpha.7 → 1.2.0-alpha.8
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/bundles/web.bundle.min.js +69 -69
- package/lib/cjs/common/contracts/ao-process.js +79 -53
- package/lib/cjs/constants.js +4 -1
- package/lib/cjs/utils/ao.js +62 -0
- package/lib/cjs/utils/index.js +1 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/contracts/ao-process.js +79 -53
- package/lib/esm/constants.js +3 -0
- package/lib/esm/utils/ao.js +58 -0
- package/lib/esm/utils/index.js +1 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/common/contracts/ao-process.d.ts +6 -10
- package/lib/types/common.d.ts +10 -0
- package/lib/types/constants.d.ts +3 -0
- package/lib/types/utils/ao.d.ts +11 -0
- package/lib/types/utils/index.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -20,23 +20,19 @@ exports.AOProcess = void 0;
|
|
|
20
20
|
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
21
21
|
const arbundles_1 = require("arbundles");
|
|
22
22
|
const version_js_1 = require("../../version.js");
|
|
23
|
+
const error_js_1 = require("../error.js");
|
|
23
24
|
const logger_js_1 = require("../logger.js");
|
|
24
25
|
class AOProcess {
|
|
25
26
|
logger;
|
|
26
27
|
processId;
|
|
27
28
|
ao;
|
|
28
|
-
constructor({ processId,
|
|
29
|
+
constructor({ processId, ao = (0, aoconnect_1.connect)(), logger = new logger_js_1.DefaultLogger({ level: 'info' }), }) {
|
|
29
30
|
this.processId = processId;
|
|
30
31
|
this.logger = logger;
|
|
31
|
-
this.ao =
|
|
32
|
-
MU_URL: connectionConfig?.MU_URL,
|
|
33
|
-
CU_URL: connectionConfig?.CU_URL,
|
|
34
|
-
GATEWAY_URL: connectionConfig?.GATEWAY_URL,
|
|
35
|
-
GRAPHQL_URL: connectionConfig?.GRAPHQL_URL,
|
|
36
|
-
});
|
|
32
|
+
this.ao = ao;
|
|
37
33
|
}
|
|
38
34
|
// TODO: could abstract into our own interface that constructs different signers
|
|
39
|
-
async createAoSigner(signer) {
|
|
35
|
+
static async createAoSigner(signer) {
|
|
40
36
|
// ensure appropriate permissions are granted with injected signers.
|
|
41
37
|
if (signer.publicKey === undefined && 'setPublicKey' in signer) {
|
|
42
38
|
await signer.setPublicKey();
|
|
@@ -91,52 +87,82 @@ class AOProcess {
|
|
|
91
87
|
}
|
|
92
88
|
throw lastError;
|
|
93
89
|
}
|
|
94
|
-
async send({ tags, data, signer, }) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
90
|
+
async send({ tags, data, signer, retries = 3, }) {
|
|
91
|
+
// main purpose of retries is to handle network errors/new process delays
|
|
92
|
+
let attempts = 0;
|
|
93
|
+
let lastError;
|
|
94
|
+
while (attempts < retries) {
|
|
95
|
+
try {
|
|
96
|
+
this.logger.debug(`Evaluating send interaction on contract`, {
|
|
97
|
+
tags,
|
|
98
|
+
data,
|
|
99
|
+
processId: this.processId,
|
|
100
|
+
});
|
|
101
|
+
// TODO: do a read as a dry run to check if the process supports the action
|
|
102
|
+
const messageId = await this.ao.message({
|
|
103
|
+
process: this.processId,
|
|
104
|
+
// TODO: any other default tags we want to add?
|
|
105
|
+
tags: [...tags, { name: 'AR-IO-SDK', value: version_js_1.version }],
|
|
106
|
+
data: typeof data !== 'string' ? JSON.stringify(data) : data,
|
|
107
|
+
signer: await AOProcess.createAoSigner(signer),
|
|
108
|
+
});
|
|
109
|
+
this.logger.debug(`Sent message to process`, {
|
|
110
|
+
messageId,
|
|
111
|
+
processId: this.processId,
|
|
112
|
+
});
|
|
113
|
+
// check the result of the send interaction
|
|
114
|
+
const output = await this.ao.result({
|
|
115
|
+
message: messageId,
|
|
116
|
+
process: this.processId,
|
|
117
|
+
});
|
|
118
|
+
this.logger.debug('Message result', {
|
|
119
|
+
output,
|
|
120
|
+
messageId,
|
|
121
|
+
processId: this.processId,
|
|
122
|
+
});
|
|
123
|
+
// check if there are any Messages in the output
|
|
124
|
+
if (output.Messages?.length === 0 || output.Messages === undefined) {
|
|
125
|
+
return { id: messageId };
|
|
126
|
+
}
|
|
127
|
+
const tagsOutput = output.Messages[0].Tags;
|
|
128
|
+
const error = tagsOutput.find((tag) => tag.name === 'Error');
|
|
129
|
+
// if there's an Error tag, throw an error related to it
|
|
130
|
+
if (error) {
|
|
131
|
+
const result = output.Messages[0].Data;
|
|
132
|
+
throw new error_js_1.WriteInteractionError(`${error.Value}: ${result}`);
|
|
133
|
+
}
|
|
134
|
+
const resultData = JSON.parse(output.Messages[0].Data);
|
|
135
|
+
this.logger.debug('Message result data', {
|
|
136
|
+
resultData,
|
|
137
|
+
messageId,
|
|
138
|
+
processId: this.processId,
|
|
139
|
+
});
|
|
140
|
+
return { id: messageId, result: resultData };
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
this.logger.error('Error sending message to process', {
|
|
144
|
+
error: error.message,
|
|
145
|
+
processId: this.processId,
|
|
146
|
+
tags,
|
|
147
|
+
});
|
|
148
|
+
// throw on write interaction errors. No point retrying wr ite interactions, waste of gas.
|
|
149
|
+
if (error.message.includes('500')) {
|
|
150
|
+
this.logger.debug('Retrying send interaction', {
|
|
151
|
+
attempts,
|
|
152
|
+
retries,
|
|
153
|
+
error: error.message,
|
|
154
|
+
processId: this.processId,
|
|
155
|
+
});
|
|
156
|
+
// exponential backoff
|
|
157
|
+
await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
|
|
158
|
+
attempts++;
|
|
159
|
+
lastError = error;
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
132
164
|
}
|
|
133
|
-
|
|
134
|
-
this.logger.debug('Message result data', {
|
|
135
|
-
resultData,
|
|
136
|
-
messageId,
|
|
137
|
-
processId: this.processId,
|
|
138
|
-
});
|
|
139
|
-
return { id: messageId, result: resultData };
|
|
165
|
+
throw lastError;
|
|
140
166
|
}
|
|
141
167
|
}
|
|
142
168
|
exports.AOProcess = AOProcess;
|
package/lib/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MIO_PER_IO = exports.ioDevnetProcessId = exports.ARNS_DEVNET_REGISTRY_TX = exports.ARNS_TESTNET_REGISTRY_TX = exports.SORT_KEY_REGEX = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
|
|
3
|
+
exports.DEFAULT_SCHEDULER_ID = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MIO_PER_IO = exports.ioDevnetProcessId = exports.ARNS_DEVNET_REGISTRY_TX = exports.ARNS_TESTNET_REGISTRY_TX = exports.SORT_KEY_REGEX = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -26,3 +26,6 @@ exports.ARNS_TESTNET_REGISTRY_TX = process.env.ARNS_REGISTRY_TX ?? 'bLAgYxAdX2Ry
|
|
|
26
26
|
exports.ARNS_DEVNET_REGISTRY_TX = '_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8';
|
|
27
27
|
exports.ioDevnetProcessId = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc';
|
|
28
28
|
exports.MIO_PER_IO = 1_000_000;
|
|
29
|
+
exports.AOS_MODULE_ID = '9afQ1PLf2mrshqCTZEzzJTR2gWaC9zNPnYgYEqg1Pt4';
|
|
30
|
+
exports.ANT_LUA_ID = 'obPBMsBWmG5q2qODj3y-zdKiuhZaJC_nuBaQRvORKkU';
|
|
31
|
+
exports.DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.spawnANT = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Affero General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
21
|
+
const arweave_js_1 = require("../common/arweave.js");
|
|
22
|
+
const index_js_1 = require("../common/index.js");
|
|
23
|
+
const constants_js_1 = require("../constants.js");
|
|
24
|
+
async function spawnANT({ module = constants_js_1.AOS_MODULE_ID, luaCodeTxId = constants_js_1.ANT_LUA_ID, scheduler = constants_js_1.DEFAULT_SCHEDULER_ID, ao = (0, aoconnect_1.connect)(), signer, state, stateContractTxId, }) {
|
|
25
|
+
//TODO: cache locally and only fetch if not cached
|
|
26
|
+
const luaString = (await arweave_js_1.defaultArweave.transactions.getData(luaCodeTxId, {
|
|
27
|
+
decode: true,
|
|
28
|
+
string: true,
|
|
29
|
+
}));
|
|
30
|
+
const processId = await ao.spawn({
|
|
31
|
+
module,
|
|
32
|
+
scheduler,
|
|
33
|
+
signer: await index_js_1.AOProcess.createAoSigner(signer),
|
|
34
|
+
});
|
|
35
|
+
const aosClient = new index_js_1.AOProcess({
|
|
36
|
+
processId,
|
|
37
|
+
ao,
|
|
38
|
+
});
|
|
39
|
+
await aosClient.send({
|
|
40
|
+
tags: [
|
|
41
|
+
{ name: 'Action', value: 'Eval' },
|
|
42
|
+
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
43
|
+
{ name: 'Source-Code-TX-ID', value: luaCodeTxId },
|
|
44
|
+
],
|
|
45
|
+
data: luaString,
|
|
46
|
+
signer,
|
|
47
|
+
});
|
|
48
|
+
if (state) {
|
|
49
|
+
await aosClient.send({
|
|
50
|
+
tags: [
|
|
51
|
+
{ name: 'Action', value: 'Initialize-State' },
|
|
52
|
+
...(stateContractTxId !== undefined
|
|
53
|
+
? [{ name: 'State-Contract-TX-ID', value: stateContractTxId }]
|
|
54
|
+
: []),
|
|
55
|
+
],
|
|
56
|
+
data: JSON.stringify(state),
|
|
57
|
+
signer,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return processId;
|
|
61
|
+
}
|
|
62
|
+
exports.spawnANT = spawnANT;
|
package/lib/cjs/utils/index.js
CHANGED
package/lib/cjs/version.js
CHANGED
|
@@ -17,23 +17,19 @@
|
|
|
17
17
|
import { connect } from '@permaweb/aoconnect';
|
|
18
18
|
import { createData } from 'arbundles';
|
|
19
19
|
import { version } from '../../version.js';
|
|
20
|
+
import { WriteInteractionError } from '../error.js';
|
|
20
21
|
import { DefaultLogger } from '../logger.js';
|
|
21
22
|
export class AOProcess {
|
|
22
23
|
logger;
|
|
23
24
|
processId;
|
|
24
25
|
ao;
|
|
25
|
-
constructor({ processId,
|
|
26
|
+
constructor({ processId, ao = connect(), logger = new DefaultLogger({ level: 'info' }), }) {
|
|
26
27
|
this.processId = processId;
|
|
27
28
|
this.logger = logger;
|
|
28
|
-
this.ao =
|
|
29
|
-
MU_URL: connectionConfig?.MU_URL,
|
|
30
|
-
CU_URL: connectionConfig?.CU_URL,
|
|
31
|
-
GATEWAY_URL: connectionConfig?.GATEWAY_URL,
|
|
32
|
-
GRAPHQL_URL: connectionConfig?.GRAPHQL_URL,
|
|
33
|
-
});
|
|
29
|
+
this.ao = ao;
|
|
34
30
|
}
|
|
35
31
|
// TODO: could abstract into our own interface that constructs different signers
|
|
36
|
-
async createAoSigner(signer) {
|
|
32
|
+
static async createAoSigner(signer) {
|
|
37
33
|
// ensure appropriate permissions are granted with injected signers.
|
|
38
34
|
if (signer.publicKey === undefined && 'setPublicKey' in signer) {
|
|
39
35
|
await signer.setPublicKey();
|
|
@@ -88,51 +84,81 @@ export class AOProcess {
|
|
|
88
84
|
}
|
|
89
85
|
throw lastError;
|
|
90
86
|
}
|
|
91
|
-
async send({ tags, data, signer, }) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
87
|
+
async send({ tags, data, signer, retries = 3, }) {
|
|
88
|
+
// main purpose of retries is to handle network errors/new process delays
|
|
89
|
+
let attempts = 0;
|
|
90
|
+
let lastError;
|
|
91
|
+
while (attempts < retries) {
|
|
92
|
+
try {
|
|
93
|
+
this.logger.debug(`Evaluating send interaction on contract`, {
|
|
94
|
+
tags,
|
|
95
|
+
data,
|
|
96
|
+
processId: this.processId,
|
|
97
|
+
});
|
|
98
|
+
// TODO: do a read as a dry run to check if the process supports the action
|
|
99
|
+
const messageId = await this.ao.message({
|
|
100
|
+
process: this.processId,
|
|
101
|
+
// TODO: any other default tags we want to add?
|
|
102
|
+
tags: [...tags, { name: 'AR-IO-SDK', value: version }],
|
|
103
|
+
data: typeof data !== 'string' ? JSON.stringify(data) : data,
|
|
104
|
+
signer: await AOProcess.createAoSigner(signer),
|
|
105
|
+
});
|
|
106
|
+
this.logger.debug(`Sent message to process`, {
|
|
107
|
+
messageId,
|
|
108
|
+
processId: this.processId,
|
|
109
|
+
});
|
|
110
|
+
// check the result of the send interaction
|
|
111
|
+
const output = await this.ao.result({
|
|
112
|
+
message: messageId,
|
|
113
|
+
process: this.processId,
|
|
114
|
+
});
|
|
115
|
+
this.logger.debug('Message result', {
|
|
116
|
+
output,
|
|
117
|
+
messageId,
|
|
118
|
+
processId: this.processId,
|
|
119
|
+
});
|
|
120
|
+
// check if there are any Messages in the output
|
|
121
|
+
if (output.Messages?.length === 0 || output.Messages === undefined) {
|
|
122
|
+
return { id: messageId };
|
|
123
|
+
}
|
|
124
|
+
const tagsOutput = output.Messages[0].Tags;
|
|
125
|
+
const error = tagsOutput.find((tag) => tag.name === 'Error');
|
|
126
|
+
// if there's an Error tag, throw an error related to it
|
|
127
|
+
if (error) {
|
|
128
|
+
const result = output.Messages[0].Data;
|
|
129
|
+
throw new WriteInteractionError(`${error.Value}: ${result}`);
|
|
130
|
+
}
|
|
131
|
+
const resultData = JSON.parse(output.Messages[0].Data);
|
|
132
|
+
this.logger.debug('Message result data', {
|
|
133
|
+
resultData,
|
|
134
|
+
messageId,
|
|
135
|
+
processId: this.processId,
|
|
136
|
+
});
|
|
137
|
+
return { id: messageId, result: resultData };
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
this.logger.error('Error sending message to process', {
|
|
141
|
+
error: error.message,
|
|
142
|
+
processId: this.processId,
|
|
143
|
+
tags,
|
|
144
|
+
});
|
|
145
|
+
// throw on write interaction errors. No point retrying wr ite interactions, waste of gas.
|
|
146
|
+
if (error.message.includes('500')) {
|
|
147
|
+
this.logger.debug('Retrying send interaction', {
|
|
148
|
+
attempts,
|
|
149
|
+
retries,
|
|
150
|
+
error: error.message,
|
|
151
|
+
processId: this.processId,
|
|
152
|
+
});
|
|
153
|
+
// exponential backoff
|
|
154
|
+
await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
|
|
155
|
+
attempts++;
|
|
156
|
+
lastError = error;
|
|
157
|
+
}
|
|
158
|
+
else
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
129
161
|
}
|
|
130
|
-
|
|
131
|
-
this.logger.debug('Message result data', {
|
|
132
|
-
resultData,
|
|
133
|
-
messageId,
|
|
134
|
-
processId: this.processId,
|
|
135
|
-
});
|
|
136
|
-
return { id: messageId, result: resultData };
|
|
162
|
+
throw lastError;
|
|
137
163
|
}
|
|
138
164
|
}
|
package/lib/esm/constants.js
CHANGED
|
@@ -23,3 +23,6 @@ export const ARNS_TESTNET_REGISTRY_TX = process.env.ARNS_REGISTRY_TX ?? 'bLAgYxA
|
|
|
23
23
|
export const ARNS_DEVNET_REGISTRY_TX = '_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8';
|
|
24
24
|
export const ioDevnetProcessId = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc';
|
|
25
25
|
export const MIO_PER_IO = 1_000_000;
|
|
26
|
+
export const AOS_MODULE_ID = '9afQ1PLf2mrshqCTZEzzJTR2gWaC9zNPnYgYEqg1Pt4';
|
|
27
|
+
export const ANT_LUA_ID = 'obPBMsBWmG5q2qODj3y-zdKiuhZaJC_nuBaQRvORKkU';
|
|
28
|
+
export const DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
* (at your option) any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
import { connect } from '@permaweb/aoconnect';
|
|
18
|
+
import { defaultArweave } from '../common/arweave.js';
|
|
19
|
+
import { AOProcess } from '../common/index.js';
|
|
20
|
+
import { ANT_LUA_ID, AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js';
|
|
21
|
+
export async function spawnANT({ module = AOS_MODULE_ID, luaCodeTxId = ANT_LUA_ID, scheduler = DEFAULT_SCHEDULER_ID, ao = connect(), signer, state, stateContractTxId, }) {
|
|
22
|
+
//TODO: cache locally and only fetch if not cached
|
|
23
|
+
const luaString = (await defaultArweave.transactions.getData(luaCodeTxId, {
|
|
24
|
+
decode: true,
|
|
25
|
+
string: true,
|
|
26
|
+
}));
|
|
27
|
+
const processId = await ao.spawn({
|
|
28
|
+
module,
|
|
29
|
+
scheduler,
|
|
30
|
+
signer: await AOProcess.createAoSigner(signer),
|
|
31
|
+
});
|
|
32
|
+
const aosClient = new AOProcess({
|
|
33
|
+
processId,
|
|
34
|
+
ao,
|
|
35
|
+
});
|
|
36
|
+
await aosClient.send({
|
|
37
|
+
tags: [
|
|
38
|
+
{ name: 'Action', value: 'Eval' },
|
|
39
|
+
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
40
|
+
{ name: 'Source-Code-TX-ID', value: luaCodeTxId },
|
|
41
|
+
],
|
|
42
|
+
data: luaString,
|
|
43
|
+
signer,
|
|
44
|
+
});
|
|
45
|
+
if (state) {
|
|
46
|
+
await aosClient.send({
|
|
47
|
+
tags: [
|
|
48
|
+
{ name: 'Action', value: 'Initialize-State' },
|
|
49
|
+
...(stateContractTxId !== undefined
|
|
50
|
+
? [{ name: 'State-Contract-TX-ID', value: stateContractTxId }]
|
|
51
|
+
: []),
|
|
52
|
+
],
|
|
53
|
+
data: JSON.stringify(state),
|
|
54
|
+
signer,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return processId;
|
|
58
|
+
}
|
package/lib/esm/utils/index.js
CHANGED
package/lib/esm/version.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { AOContract, ContractSigner } from '../../types.js';
|
|
2
|
+
import { AOContract, AoClient, ContractSigner } from '../../types.js';
|
|
3
3
|
import { DefaultLogger } from '../logger.js';
|
|
4
4
|
export declare class AOProcess implements AOContract {
|
|
5
5
|
private logger;
|
|
6
6
|
private processId;
|
|
7
7
|
private ao;
|
|
8
|
-
constructor({ processId,
|
|
8
|
+
constructor({ processId, ao, logger, }: {
|
|
9
9
|
processId: string;
|
|
10
|
-
|
|
11
|
-
CU_URL: string;
|
|
12
|
-
MU_URL: string;
|
|
13
|
-
GATEWAY_URL: string;
|
|
14
|
-
GRAPHQL_URL: string;
|
|
15
|
-
};
|
|
10
|
+
ao?: AoClient;
|
|
16
11
|
logger?: DefaultLogger;
|
|
17
12
|
});
|
|
18
|
-
createAoSigner(signer: ContractSigner): Promise<(args: {
|
|
13
|
+
static createAoSigner(signer: ContractSigner): Promise<(args: {
|
|
19
14
|
data: string | Buffer;
|
|
20
15
|
tags?: {
|
|
21
16
|
name: string;
|
|
@@ -34,13 +29,14 @@ export declare class AOProcess implements AOContract {
|
|
|
34
29
|
}>;
|
|
35
30
|
retries?: number;
|
|
36
31
|
}): Promise<K>;
|
|
37
|
-
send<I, K>({ tags, data, signer, }: {
|
|
32
|
+
send<I, K>({ tags, data, signer, retries, }: {
|
|
38
33
|
tags: Array<{
|
|
39
34
|
name: string;
|
|
40
35
|
value: string;
|
|
41
36
|
}>;
|
|
42
37
|
data?: I;
|
|
43
38
|
signer: ContractSigner;
|
|
39
|
+
retries?: number;
|
|
44
40
|
}): Promise<{
|
|
45
41
|
id: string;
|
|
46
42
|
result?: K;
|
package/lib/types/common.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
|
+
import { dryrun, message, monitor, result, results, spawn, unmonitor } from '@permaweb/aoconnect';
|
|
18
19
|
import { ArconnectSigner, ArweaveSigner } from 'arbundles';
|
|
19
20
|
import { GQLNodeInterface, Transaction } from 'warp-contracts';
|
|
20
21
|
import { RemoteContract, WarpContract } from './common/index.js';
|
|
@@ -224,4 +225,13 @@ export interface HTTPClient {
|
|
|
224
225
|
params?: object | I;
|
|
225
226
|
}): Promise<K>;
|
|
226
227
|
}
|
|
228
|
+
export interface AoClient {
|
|
229
|
+
result: typeof result;
|
|
230
|
+
results: typeof results;
|
|
231
|
+
message: typeof message;
|
|
232
|
+
spawn: typeof spawn;
|
|
233
|
+
monitor: typeof monitor;
|
|
234
|
+
unmonitor: typeof unmonitor;
|
|
235
|
+
dryrun: typeof dryrun;
|
|
236
|
+
}
|
|
227
237
|
export {};
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -22,3 +22,6 @@ export declare const ARNS_TESTNET_REGISTRY_TX: string;
|
|
|
22
22
|
export declare const ARNS_DEVNET_REGISTRY_TX = "_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8";
|
|
23
23
|
export declare const ioDevnetProcessId = "GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc";
|
|
24
24
|
export declare const MIO_PER_IO = 1000000;
|
|
25
|
+
export declare const AOS_MODULE_ID = "9afQ1PLf2mrshqCTZEzzJTR2gWaC9zNPnYgYEqg1Pt4";
|
|
26
|
+
export declare const ANT_LUA_ID = "obPBMsBWmG5q2qODj3y-zdKiuhZaJC_nuBaQRvORKkU";
|
|
27
|
+
export declare const DEFAULT_SCHEDULER_ID = "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ANTState } from '../contract-state.js';
|
|
2
|
+
import { AoClient, ContractSigner } from '../types.js';
|
|
3
|
+
export declare function spawnANT({ module, luaCodeTxId, scheduler, ao, signer, state, stateContractTxId, }: {
|
|
4
|
+
module: string;
|
|
5
|
+
luaCodeTxId: string;
|
|
6
|
+
ao: AoClient;
|
|
7
|
+
scheduler: string;
|
|
8
|
+
signer: ContractSigner;
|
|
9
|
+
state?: ANTState;
|
|
10
|
+
stateContractTxId?: string;
|
|
11
|
+
}): Promise<string>;
|
package/lib/types/version.d.ts
CHANGED