@ar.io/sdk 2.5.0-alpha.6 → 2.5.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/README.md +107 -0
- package/bundles/web.bundle.min.js +35 -35
- package/lib/cjs/common/ant.js +19 -0
- package/lib/cjs/common/contracts/ao-process.js +12 -11
- package/lib/cjs/common/io.js +3 -9
- package/lib/cjs/types/ant.js +1 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/ant.js +19 -0
- package/lib/esm/common/contracts/ao-process.js +12 -11
- package/lib/esm/common/io.js +3 -9
- package/lib/esm/types/ant.js +1 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant.d.ts +12 -0
- package/lib/types/types/ant.d.ts +5 -2
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/common/ant.js
CHANGED
|
@@ -393,6 +393,25 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
393
393
|
signer: this.signer,
|
|
394
394
|
});
|
|
395
395
|
}
|
|
396
|
+
/**
|
|
397
|
+
* @param txId @type {string} - Arweave transaction id of the logo we want to set
|
|
398
|
+
* @param options @type {WriteOptions} - additional options to add to the write interaction (optional)
|
|
399
|
+
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* ant.setLogo({ logo: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f" });
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
async setLogo({ txId }, options) {
|
|
406
|
+
return this.process.send({
|
|
407
|
+
tags: [
|
|
408
|
+
...(options?.tags ?? []),
|
|
409
|
+
{ name: 'Action', value: 'Set-Logo' },
|
|
410
|
+
{ name: 'Logo', value: txId },
|
|
411
|
+
],
|
|
412
|
+
signer: this.signer,
|
|
413
|
+
});
|
|
414
|
+
}
|
|
396
415
|
/**
|
|
397
416
|
* @param name @type {string} The name you want to release. The name will be put up for auction on the IO contract. 50% of the winning bid will be distributed to the ANT owner at the time of release. If no bids, the name will be released and can be reregistered by anyone.
|
|
398
417
|
* @param ioProcessId @type {string} The processId of the IO contract. This is where the ANT will send the message to release the name.
|
|
@@ -50,11 +50,12 @@ class AOProcess {
|
|
|
50
50
|
this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
|
|
51
51
|
throw new Error(`Process ${this.processId} does not support provided action.`);
|
|
52
52
|
}
|
|
53
|
-
const tagsOutput = result.Messages[0]
|
|
54
|
-
const messageData = result.Messages[0]
|
|
55
|
-
const
|
|
53
|
+
const tagsOutput = result.Messages?.[0]?.Tags;
|
|
54
|
+
const messageData = result.Messages?.[0]?.Data;
|
|
55
|
+
const errorData = result.Error;
|
|
56
|
+
const error = errorData || tagsOutput?.find((tag) => tag.name === 'Error')?.value;
|
|
56
57
|
if (error) {
|
|
57
|
-
throw new Error(`${error
|
|
58
|
+
throw new Error(`${error}${messageData ? `: ${messageData}` : ''}`);
|
|
58
59
|
}
|
|
59
60
|
// return empty object if no data is returned
|
|
60
61
|
if (messageData === undefined) {
|
|
@@ -109,17 +110,17 @@ class AOProcess {
|
|
|
109
110
|
messageId,
|
|
110
111
|
processId: this.processId,
|
|
111
112
|
});
|
|
113
|
+
const errorData = output.Error;
|
|
114
|
+
const error = errorData ||
|
|
115
|
+
output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')
|
|
116
|
+
?.value;
|
|
117
|
+
if (error) {
|
|
118
|
+
throw new error_js_1.WriteInteractionError(error);
|
|
119
|
+
}
|
|
112
120
|
// check if there are any Messages in the output
|
|
113
121
|
if (output.Messages?.length === 0 || output.Messages === undefined) {
|
|
114
122
|
return { id: messageId };
|
|
115
123
|
}
|
|
116
|
-
const tagsOutput = output.Messages[0].Tags;
|
|
117
|
-
const error = tagsOutput.find((tag) => tag.name === 'Error');
|
|
118
|
-
// if there's an Error tag, throw an error related to it
|
|
119
|
-
if (error) {
|
|
120
|
-
const result = output.Messages[0].Data;
|
|
121
|
-
throw new error_js_1.WriteInteractionError(`${error.Value}: ${result}`);
|
|
122
|
-
}
|
|
123
124
|
if (output.Messages.length === 0) {
|
|
124
125
|
throw new Error(`Process ${this.processId} does not support provided action.`);
|
|
125
126
|
}
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -192,14 +192,7 @@ class IOReadable {
|
|
|
192
192
|
{ name: 'Action', value: 'Epoch' },
|
|
193
193
|
{
|
|
194
194
|
name: 'Timestamp',
|
|
195
|
-
value: (await this.arweave.
|
|
196
|
-
.getCurrent()
|
|
197
|
-
.then((block) => {
|
|
198
|
-
return { timestamp: block.timestamp * 1000 };
|
|
199
|
-
})
|
|
200
|
-
.catch(() => {
|
|
201
|
-
return { timestamp: Date.now() }; // fallback to current time
|
|
202
|
-
})).timestamp.toString(),
|
|
195
|
+
value: (await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
203
196
|
},
|
|
204
197
|
],
|
|
205
198
|
});
|
|
@@ -356,7 +349,8 @@ class IOReadable {
|
|
|
356
349
|
{ name: 'Name', value: name },
|
|
357
350
|
{
|
|
358
351
|
name: 'Timestamp',
|
|
359
|
-
value: timestamp?.toString() ??
|
|
352
|
+
value: timestamp?.toString() ??
|
|
353
|
+
(await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
|
|
360
354
|
},
|
|
361
355
|
{ name: 'Purchase-Type', value: type ?? 'lease' },
|
|
362
356
|
{
|
package/lib/cjs/types/ant.js
CHANGED
package/lib/cjs/version.js
CHANGED
package/lib/esm/common/ant.js
CHANGED
|
@@ -388,6 +388,25 @@ export class AoANTWriteable extends AoANTReadable {
|
|
|
388
388
|
signer: this.signer,
|
|
389
389
|
});
|
|
390
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* @param txId @type {string} - Arweave transaction id of the logo we want to set
|
|
393
|
+
* @param options @type {WriteOptions} - additional options to add to the write interaction (optional)
|
|
394
|
+
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
395
|
+
* @example
|
|
396
|
+
* ```ts
|
|
397
|
+
* ant.setLogo({ logo: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f" });
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
async setLogo({ txId }, options) {
|
|
401
|
+
return this.process.send({
|
|
402
|
+
tags: [
|
|
403
|
+
...(options?.tags ?? []),
|
|
404
|
+
{ name: 'Action', value: 'Set-Logo' },
|
|
405
|
+
{ name: 'Logo', value: txId },
|
|
406
|
+
],
|
|
407
|
+
signer: this.signer,
|
|
408
|
+
});
|
|
409
|
+
}
|
|
391
410
|
/**
|
|
392
411
|
* @param name @type {string} The name you want to release. The name will be put up for auction on the IO contract. 50% of the winning bid will be distributed to the ANT owner at the time of release. If no bids, the name will be released and can be reregistered by anyone.
|
|
393
412
|
* @param ioProcessId @type {string} The processId of the IO contract. This is where the ANT will send the message to release the name.
|
|
@@ -47,11 +47,12 @@ export class AOProcess {
|
|
|
47
47
|
this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
|
|
48
48
|
throw new Error(`Process ${this.processId} does not support provided action.`);
|
|
49
49
|
}
|
|
50
|
-
const tagsOutput = result.Messages[0]
|
|
51
|
-
const messageData = result.Messages[0]
|
|
52
|
-
const
|
|
50
|
+
const tagsOutput = result.Messages?.[0]?.Tags;
|
|
51
|
+
const messageData = result.Messages?.[0]?.Data;
|
|
52
|
+
const errorData = result.Error;
|
|
53
|
+
const error = errorData || tagsOutput?.find((tag) => tag.name === 'Error')?.value;
|
|
53
54
|
if (error) {
|
|
54
|
-
throw new Error(`${error
|
|
55
|
+
throw new Error(`${error}${messageData ? `: ${messageData}` : ''}`);
|
|
55
56
|
}
|
|
56
57
|
// return empty object if no data is returned
|
|
57
58
|
if (messageData === undefined) {
|
|
@@ -106,17 +107,17 @@ export class AOProcess {
|
|
|
106
107
|
messageId,
|
|
107
108
|
processId: this.processId,
|
|
108
109
|
});
|
|
110
|
+
const errorData = output.Error;
|
|
111
|
+
const error = errorData ||
|
|
112
|
+
output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')
|
|
113
|
+
?.value;
|
|
114
|
+
if (error) {
|
|
115
|
+
throw new WriteInteractionError(error);
|
|
116
|
+
}
|
|
109
117
|
// check if there are any Messages in the output
|
|
110
118
|
if (output.Messages?.length === 0 || output.Messages === undefined) {
|
|
111
119
|
return { id: messageId };
|
|
112
120
|
}
|
|
113
|
-
const tagsOutput = output.Messages[0].Tags;
|
|
114
|
-
const error = tagsOutput.find((tag) => tag.name === 'Error');
|
|
115
|
-
// if there's an Error tag, throw an error related to it
|
|
116
|
-
if (error) {
|
|
117
|
-
const result = output.Messages[0].Data;
|
|
118
|
-
throw new WriteInteractionError(`${error.Value}: ${result}`);
|
|
119
|
-
}
|
|
120
121
|
if (output.Messages.length === 0) {
|
|
121
122
|
throw new Error(`Process ${this.processId} does not support provided action.`);
|
|
122
123
|
}
|
package/lib/esm/common/io.js
CHANGED
|
@@ -188,14 +188,7 @@ export class IOReadable {
|
|
|
188
188
|
{ name: 'Action', value: 'Epoch' },
|
|
189
189
|
{
|
|
190
190
|
name: 'Timestamp',
|
|
191
|
-
value: (await this.arweave.
|
|
192
|
-
.getCurrent()
|
|
193
|
-
.then((block) => {
|
|
194
|
-
return { timestamp: block.timestamp * 1000 };
|
|
195
|
-
})
|
|
196
|
-
.catch(() => {
|
|
197
|
-
return { timestamp: Date.now() }; // fallback to current time
|
|
198
|
-
})).timestamp.toString(),
|
|
191
|
+
value: (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(),
|
|
199
192
|
},
|
|
200
193
|
],
|
|
201
194
|
});
|
|
@@ -352,7 +345,8 @@ export class IOReadable {
|
|
|
352
345
|
{ name: 'Name', value: name },
|
|
353
346
|
{
|
|
354
347
|
name: 'Timestamp',
|
|
355
|
-
value: timestamp?.toString() ??
|
|
348
|
+
value: timestamp?.toString() ??
|
|
349
|
+
(await getCurrentBlockUnixTimestampMs(this.arweave)).toString(),
|
|
356
350
|
},
|
|
357
351
|
{ name: 'Purchase-Type', value: type ?? 'lease' },
|
|
358
352
|
{
|
package/lib/esm/types/ant.js
CHANGED
package/lib/esm/version.js
CHANGED
|
@@ -214,6 +214,18 @@ export declare class AoANTWriteable extends AoANTReadable implements AoANTWrite
|
|
|
214
214
|
setKeywords({ keywords }: {
|
|
215
215
|
keywords: string[];
|
|
216
216
|
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
217
|
+
/**
|
|
218
|
+
* @param txId @type {string} - Arweave transaction id of the logo we want to set
|
|
219
|
+
* @param options @type {WriteOptions} - additional options to add to the write interaction (optional)
|
|
220
|
+
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* ant.setLogo({ logo: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f" });
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
setLogo({ txId }: {
|
|
227
|
+
txId: string;
|
|
228
|
+
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
217
229
|
/**
|
|
218
230
|
* @param name @type {string} The name you want to release. The name will be put up for auction on the IO contract. 50% of the winning bid will be distributed to the ANT owner at the time of release. If no bids, the name will be released and can be reregistered by anyone.
|
|
219
231
|
* @param ioProcessId @type {string} The processId of the IO contract. This is where the ANT will send the message to release the name.
|
package/lib/types/types/ant.d.ts
CHANGED
|
@@ -145,9 +145,9 @@ export declare const AntStateSchema: z.ZodObject<{
|
|
|
145
145
|
export type AoANTState = z.infer<typeof AntStateSchema>;
|
|
146
146
|
export declare const AntReadHandlers: readonly ["balance", "balances", "totalSupply", "info", "controllers", "record", "records", "state"];
|
|
147
147
|
export type AoANTReadHandler = (typeof AntReadHandlers)[number];
|
|
148
|
-
export declare const AntWriteHandlers: readonly ["evolve", "_eval", "_default", "transfer", "addController", "removeController", "setRecord", "removeRecord", "setName", "setTicker", "setDescription", "setKeywords", "initializeState", "releaseName", "reassignName"];
|
|
148
|
+
export declare const AntWriteHandlers: readonly ["evolve", "_eval", "_default", "transfer", "addController", "removeController", "setRecord", "removeRecord", "setName", "setTicker", "setDescription", "setKeywords", "setLogo", "initializeState", "releaseName", "reassignName"];
|
|
149
149
|
export type AoANTWriteHandler = (typeof AntWriteHandlers)[number];
|
|
150
|
-
export declare const AntHandlerNames: ("balance" | "balances" | "totalSupply" | "info" | "controllers" | "record" | "records" | "state" | "evolve" | "_eval" | "_default" | "transfer" | "addController" | "removeController" | "setRecord" | "removeRecord" | "setName" | "setTicker" | "setDescription" | "setKeywords" | "initializeState" | "releaseName" | "reassignName")[];
|
|
150
|
+
export declare const AntHandlerNames: ("balance" | "balances" | "totalSupply" | "info" | "controllers" | "record" | "records" | "state" | "evolve" | "_eval" | "_default" | "transfer" | "addController" | "removeController" | "setRecord" | "removeRecord" | "setName" | "setTicker" | "setDescription" | "setKeywords" | "setLogo" | "initializeState" | "releaseName" | "reassignName")[];
|
|
151
151
|
export type AoANTHandler = AoANTWriteHandler | AoANTReadHandler;
|
|
152
152
|
export declare const AntHandlersSchema: z.ZodEffects<z.ZodArray<z.ZodString, "many">, string[], string[]>;
|
|
153
153
|
export declare const AntInfoSchema: z.ZodObject<{
|
|
@@ -240,6 +240,9 @@ export interface AoANTWrite extends AoANTRead {
|
|
|
240
240
|
setName({ name }: {
|
|
241
241
|
name: string;
|
|
242
242
|
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
243
|
+
setLogo({ txId }: {
|
|
244
|
+
txId: string;
|
|
245
|
+
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
243
246
|
releaseName({ name, ioProcessId }: {
|
|
244
247
|
name: string;
|
|
245
248
|
ioProcessId: string;
|
package/lib/types/version.d.ts
CHANGED