@typemove/aptos 1.0.2-rc.2 → 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/Readme.md +13 -1
- package/dist/cjs/account-resource-client.d.ts +35 -0
- package/dist/cjs/account-resource-client.d.ts.map +1 -0
- package/dist/cjs/account-resource-client.js +44 -0
- package/dist/cjs/account-resource-client.js.map +1 -0
- package/dist/cjs/account-resource-client.test.d.ts +2 -0
- package/dist/cjs/account-resource-client.test.d.ts.map +1 -0
- package/dist/cjs/account-resource-client.test.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/account-resource-client.d.ts +35 -0
- package/dist/esm/account-resource-client.d.ts.map +1 -0
- package/dist/esm/account-resource-client.js +40 -0
- package/dist/esm/account-resource-client.js.map +1 -0
- package/dist/esm/account-resource-client.test.d.ts +2 -0
- package/dist/esm/account-resource-client.test.d.ts.map +1 -0
- package/dist/esm/account-resource-client.test.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/account-resource-client.ts +58 -0
- package/src/index.ts +1 -0
- package/src/tests/abis/0xbd35135844473187163ca197ca93b2ab014370587bb0ed3befff9e902d6bb541.json +3717 -0
- package/src/tests/types/0xbd35135844473187163ca197ca93b2ab014370587bb0ed3befff9e902d6bb541.ts +2030 -0
- package/src/tests/types/index.ts +1 -0
package/Readme.md
CHANGED
|
@@ -65,4 +65,16 @@ const res = await _0x1.coin.entry.transfer(client, account, {
|
|
|
65
65
|
|
|
66
66
|
Checkout our [tests](./src/tests/move-call.test.ts) for more examples.
|
|
67
67
|
|
|
68
|
-
### Resource
|
|
68
|
+
### Resource client
|
|
69
|
+
We provide a resource client to help you retrieve resources:
|
|
70
|
+
```typescript
|
|
71
|
+
const poolType = amm.Pool.type()
|
|
72
|
+
const allPoolResources = await accountResourceClient.matchAll(ACCOUNT_ADDRESS, poolType)
|
|
73
|
+
```
|
|
74
|
+
or if you want to partial match one of the type parameters:
|
|
75
|
+
```typescript
|
|
76
|
+
const poolTypeWithAptos = amm.Pool.type(aptos_coin.AptosCoin.type(), ANY_TYPE)
|
|
77
|
+
const aptosPoolResources = await accountResourceClient.matchAll(ACCOUNT_ADDRESS, poolTypeWithAptos)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Checkout our [tests](./src/account-resource-client.test.ts) for more examples.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AptosClient, MaybeHexString } from 'aptos';
|
|
2
|
+
import { TypeDescriptor } from '@typemove/move';
|
|
3
|
+
import { TypedMoveResource } from './models.js';
|
|
4
|
+
type ResourceQuery = {
|
|
5
|
+
ledgerVersion?: bigint | number;
|
|
6
|
+
};
|
|
7
|
+
export declare class AccountResourceClient {
|
|
8
|
+
client: AptosClient;
|
|
9
|
+
constructor(client: AptosClient);
|
|
10
|
+
/**
|
|
11
|
+
* Get all resources of an account, same as `getAccountResources` in aptos client
|
|
12
|
+
* @param accountAddress
|
|
13
|
+
* @param query
|
|
14
|
+
*/
|
|
15
|
+
getAll(accountAddress: MaybeHexString, query?: ResourceQuery): Promise<{
|
|
16
|
+
type: string;
|
|
17
|
+
data: {};
|
|
18
|
+
}[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Match a single resource with exact type, resource type should not contain any type
|
|
21
|
+
* @param accountAddress
|
|
22
|
+
* @param resourceType
|
|
23
|
+
* @param query
|
|
24
|
+
*/
|
|
25
|
+
matchExact<T>(accountAddress: MaybeHexString, resourceType: TypeDescriptor<T>, query?: ResourceQuery): Promise<TypedMoveResource<T> | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Match all resources with type pattern, it could be a partial type like `amm.Pool<aptos_coin.AptosCoin.type(), ANY_TYPE>`
|
|
28
|
+
* @param accountAddress
|
|
29
|
+
* @param resourceType
|
|
30
|
+
* @param query
|
|
31
|
+
*/
|
|
32
|
+
matchAll<T>(accountAddress: MaybeHexString, resourceType: TypeDescriptor<T>, query?: ResourceQuery): Promise<TypedMoveResource<T>[]>;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=account-resource-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-resource-client.d.ts","sourceRoot":"","sources":["../../src/account-resource-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,KAAK,aAAa,GAAG;IACnB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAChC,CAAA;AAED,qBAAa,qBAAqB;IAChC,MAAM,EAAE,WAAW,CAAA;gBACP,MAAM,EAAE,WAAW;IAI/B;;;;OAIG;IACG,MAAM,CAAC,cAAc,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,aAAa;;;;IAIlE;;;;;OAKG;IACG,UAAU,CAAC,CAAC,EAChB,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC,EAC/B,KAAK,CAAC,EAAE,aAAa,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAS5C;;;;;OAKG;IACG,QAAQ,CAAC,CAAC,EACd,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC,EAC/B,KAAK,CAAC,EAAE,aAAa,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;CAInC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccountResourceClient = void 0;
|
|
4
|
+
const move_coder_js_1 = require("./move-coder.js");
|
|
5
|
+
class AccountResourceClient {
|
|
6
|
+
client;
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Get all resources of an account, same as `getAccountResources` in aptos client
|
|
12
|
+
* @param accountAddress
|
|
13
|
+
* @param query
|
|
14
|
+
*/
|
|
15
|
+
async getAll(accountAddress, query) {
|
|
16
|
+
return this.client.getAccountResources(accountAddress, query);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Match a single resource with exact type, resource type should not contain any type
|
|
20
|
+
* @param accountAddress
|
|
21
|
+
* @param resourceType
|
|
22
|
+
* @param query
|
|
23
|
+
*/
|
|
24
|
+
async matchExact(accountAddress, resourceType, query) {
|
|
25
|
+
if (resourceType.existAnyType()) {
|
|
26
|
+
throw new Error('resource type for match call should not contain any type');
|
|
27
|
+
}
|
|
28
|
+
const typeStr = resourceType.getSignature();
|
|
29
|
+
const result = await this.client.getAccountResource(accountAddress, typeStr, query);
|
|
30
|
+
return (0, move_coder_js_1.defaultMoveCoder)(this.client.nodeUrl).decodeResource(result);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Match all resources with type pattern, it could be a partial type like `amm.Pool<aptos_coin.AptosCoin.type(), ANY_TYPE>`
|
|
34
|
+
* @param accountAddress
|
|
35
|
+
* @param resourceType
|
|
36
|
+
* @param query
|
|
37
|
+
*/
|
|
38
|
+
async matchAll(accountAddress, resourceType, query) {
|
|
39
|
+
const result = await this.client.getAccountResources(accountAddress, query);
|
|
40
|
+
return (0, move_coder_js_1.defaultMoveCoder)(this.client.nodeUrl).filterAndDecodeResources(resourceType, result);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.AccountResourceClient = AccountResourceClient;
|
|
44
|
+
//# sourceMappingURL=account-resource-client.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
{"version":3,"file":"account-resource-client.test.d.ts","sourceRoot":"","sources":["../../src/account-resource-client.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-resource-client.test.js","sourceRoot":"","sources":["../../src/account-resource-client.test.ts"],"names":[],"mappings":";;AAAA,iCAAmC;AACnC,+BAA6B;AAC7B,2CAAoC;AACpC,6EAAoE;AACpE,gLAAgH;AAChH,8CAA6C;AAC7C,yCAAyC;AAEzC,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,MAAM,MAAM,GAAG,IAAI,mBAAW,CAAC,gCAAgC,CAAC,CAAA;IAChE,MAAM,qBAAqB,GAAG,IAAI,kDAAqB,CAAC,MAAM,CAAC,CAAA;IAC/D,MAAM,eAAe,GAAG,oEAAoE,CAAA;IAE5F,cAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAEvB,IAAI,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;QAC/B,MAAM,QAAQ,GAAG,4EAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;QAChC,MAAM,gBAAgB,GAAG,MAAM,qBAAqB,CAAC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAA;QACxF,IAAA,aAAM,EAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;QACjD,KAAK,MAAM,CAAC,IAAI,gBAAgB,EAAE;YAChC,IAAA,aAAM,EAAC,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAA;SAClD;QAED,MAAM,iBAAiB,GAAG,4EAAG,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAU,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,eAAQ,CAAC,CAAA;QAC9E,MAAM,kBAAkB,GAAG,MAAM,qBAAqB,CAAC,QAAQ,CAAC,eAAe,EAAE,iBAAiB,C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M,EAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAA;SAC1F;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultMoveCoder = exports.MoveCoder = void 0;
|
|
3
|
+
exports.AccountResourceClient = exports.defaultMoveCoder = exports.MoveCoder = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./models.js"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./move-types.js"), exports);
|
|
7
7
|
var move_coder_js_1 = require("./move-coder.js");
|
|
8
8
|
Object.defineProperty(exports, "MoveCoder", { enumerable: true, get: function () { return move_coder_js_1.MoveCoder; } });
|
|
9
9
|
Object.defineProperty(exports, "defaultMoveCoder", { enumerable: true, get: function () { return move_coder_js_1.defaultMoveCoder; } });
|
|
10
|
+
var account_resource_client_js_1 = require("./account-resource-client.js");
|
|
11
|
+
Object.defineProperty(exports, "AccountResourceClient", { enumerable: true, get: function () { return account_resource_client_js_1.AccountResourceClient; } });
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,sDAA2B;AAC3B,0DAA+B;AAC/B,iDAA6D;AAApD,0GAAA,SAAS,OAAA;AAAE,iHAAA,gBAAgB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,sDAA2B;AAC3B,0DAA+B;AAC/B,iDAA6D;AAApD,0GAAA,SAAS,OAAA;AAAE,iHAAA,gBAAgB,OAAA;AACpC,2EAAoE;AAA3D,mIAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AptosClient, MaybeHexString } from 'aptos';
|
|
2
|
+
import { TypeDescriptor } from '@typemove/move';
|
|
3
|
+
import { TypedMoveResource } from './models.js';
|
|
4
|
+
type ResourceQuery = {
|
|
5
|
+
ledgerVersion?: bigint | number;
|
|
6
|
+
};
|
|
7
|
+
export declare class AccountResourceClient {
|
|
8
|
+
client: AptosClient;
|
|
9
|
+
constructor(client: AptosClient);
|
|
10
|
+
/**
|
|
11
|
+
* Get all resources of an account, same as `getAccountResources` in aptos client
|
|
12
|
+
* @param accountAddress
|
|
13
|
+
* @param query
|
|
14
|
+
*/
|
|
15
|
+
getAll(accountAddress: MaybeHexString, query?: ResourceQuery): Promise<{
|
|
16
|
+
type: string;
|
|
17
|
+
data: {};
|
|
18
|
+
}[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Match a single resource with exact type, resource type should not contain any type
|
|
21
|
+
* @param accountAddress
|
|
22
|
+
* @param resourceType
|
|
23
|
+
* @param query
|
|
24
|
+
*/
|
|
25
|
+
matchExact<T>(accountAddress: MaybeHexString, resourceType: TypeDescriptor<T>, query?: ResourceQuery): Promise<TypedMoveResource<T> | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Match all resources with type pattern, it could be a partial type like `amm.Pool<aptos_coin.AptosCoin.type(), ANY_TYPE>`
|
|
28
|
+
* @param accountAddress
|
|
29
|
+
* @param resourceType
|
|
30
|
+
* @param query
|
|
31
|
+
*/
|
|
32
|
+
matchAll<T>(accountAddress: MaybeHexString, resourceType: TypeDescriptor<T>, query?: ResourceQuery): Promise<TypedMoveResource<T>[]>;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=account-resource-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-resource-client.d.ts","sourceRoot":"","sources":["../../src/account-resource-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,KAAK,aAAa,GAAG;IACnB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAChC,CAAA;AAED,qBAAa,qBAAqB;IAChC,MAAM,EAAE,WAAW,CAAA;gBACP,MAAM,EAAE,WAAW;IAI/B;;;;OAIG;IACG,MAAM,CAAC,cAAc,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,aAAa;;;;IAIlE;;;;;OAKG;IACG,UAAU,CAAC,CAAC,EAChB,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC,EAC/B,KAAK,CAAC,EAAE,aAAa,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAS5C;;;;;OAKG;IACG,QAAQ,CAAC,CAAC,EACd,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC,EAC/B,KAAK,CAAC,EAAE,aAAa,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;CAInC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defaultMoveCoder } from './move-coder.js';
|
|
2
|
+
export class AccountResourceClient {
|
|
3
|
+
client;
|
|
4
|
+
constructor(client) {
|
|
5
|
+
this.client = client;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Get all resources of an account, same as `getAccountResources` in aptos client
|
|
9
|
+
* @param accountAddress
|
|
10
|
+
* @param query
|
|
11
|
+
*/
|
|
12
|
+
async getAll(accountAddress, query) {
|
|
13
|
+
return this.client.getAccountResources(accountAddress, query);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Match a single resource with exact type, resource type should not contain any type
|
|
17
|
+
* @param accountAddress
|
|
18
|
+
* @param resourceType
|
|
19
|
+
* @param query
|
|
20
|
+
*/
|
|
21
|
+
async matchExact(accountAddress, resourceType, query) {
|
|
22
|
+
if (resourceType.existAnyType()) {
|
|
23
|
+
throw new Error('resource type for match call should not contain any type');
|
|
24
|
+
}
|
|
25
|
+
const typeStr = resourceType.getSignature();
|
|
26
|
+
const result = await this.client.getAccountResource(accountAddress, typeStr, query);
|
|
27
|
+
return defaultMoveCoder(this.client.nodeUrl).decodeResource(result);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Match all resources with type pattern, it could be a partial type like `amm.Pool<aptos_coin.AptosCoin.type(), ANY_TYPE>`
|
|
31
|
+
* @param accountAddress
|
|
32
|
+
* @param resourceType
|
|
33
|
+
* @param query
|
|
34
|
+
*/
|
|
35
|
+
async matchAll(accountAddress, resourceType, query) {
|
|
36
|
+
const result = await this.client.getAccountResources(accountAddress, query);
|
|
37
|
+
return defaultMoveCoder(this.client.nodeUrl).filterAndDecodeResources(resourceType, result);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=account-resource-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-resource-client.js","sourceRoot":"","sources":["../../src/account-resource-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAOlD,MAAM,OAAO,qBAAqB;IAChC,MAAM,CAAa;IACnB,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,cAA8B,EAAE,KAAqB;QAChE,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;IAC/D,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CACd,cAA8B,EAC9B,YAA+B,EAC/B,KAAqB;QAErB,IAAI,YAAY,CAAC,YAAY,EAAE,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAA;SAC5E;QACD,MAAM,OAAO,GAAG,YAAY,CAAC,YAAY,EAAE,CAAA;QAC3C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,cAAc,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;QACnF,OAAO,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAI,MAAM,CAAC,CAAA;IACxE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,CACZ,cAA8B,EAC9B,YAA+B,EAC/B,KAAqB;QAErB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;QAC3E,OAAO,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,wBAAwB,CAAI,YAAY,EAAE,MAAM,CAAC,CAAA;IAChG,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-resource-client.test.d.ts","sourceRoot":"","sources":["../../src/account-resource-client.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-resource-client.test.js","sourceRoot":"","sources":["../../src/account-resource-client.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,qFAAqF,CAAA;AAChH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,gCAAgC,CAAC,CAAA;IAChE,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAA;IAC/D,MAAM,eAAe,GAAG,oEAAoE,CAAA;IAE5F,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAEvB,IAAI,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;QAC/B,MAAM,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;QAChC,MAAM,gBAAgB,GAAG,MAAM,qBAAqB,CAAC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAA;QACxF,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;QACjD,KAAK,MAAM,CAAC,IAAI,gBAAgB,EAAE;YAChC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC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G,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAA;QACjE,IAAI;YACF,MAAM,CAAC,GAAG,MAAM,qBAAqB,CAAC,UAAU,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;SACxE;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAA;SAC1F;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typemove/aptos",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"aptos": "^1.19.0",
|
|
33
33
|
"chalk": "^5.3.0",
|
|
34
34
|
"radash": "^11.0.0",
|
|
35
|
-
"@typemove/move": "1.0
|
|
35
|
+
"@typemove/move": "1.1.0"
|
|
36
36
|
},
|
|
37
37
|
"url": "https://github.com/sentioxyz/typemove",
|
|
38
38
|
"scripts": {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AptosClient, MaybeHexString } from 'aptos'
|
|
2
|
+
import { TypeDescriptor } from '@typemove/move'
|
|
3
|
+
import { defaultMoveCoder } from './move-coder.js'
|
|
4
|
+
import { TypedMoveResource } from './models.js'
|
|
5
|
+
|
|
6
|
+
type ResourceQuery = {
|
|
7
|
+
ledgerVersion?: bigint | number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class AccountResourceClient {
|
|
11
|
+
client: AptosClient
|
|
12
|
+
constructor(client: AptosClient) {
|
|
13
|
+
this.client = client
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get all resources of an account, same as `getAccountResources` in aptos client
|
|
18
|
+
* @param accountAddress
|
|
19
|
+
* @param query
|
|
20
|
+
*/
|
|
21
|
+
async getAll(accountAddress: MaybeHexString, query?: ResourceQuery) {
|
|
22
|
+
return this.client.getAccountResources(accountAddress, query)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Match a single resource with exact type, resource type should not contain any type
|
|
27
|
+
* @param accountAddress
|
|
28
|
+
* @param resourceType
|
|
29
|
+
* @param query
|
|
30
|
+
*/
|
|
31
|
+
async matchExact<T>(
|
|
32
|
+
accountAddress: MaybeHexString,
|
|
33
|
+
resourceType: TypeDescriptor<T>,
|
|
34
|
+
query?: ResourceQuery
|
|
35
|
+
): Promise<TypedMoveResource<T> | undefined> {
|
|
36
|
+
if (resourceType.existAnyType()) {
|
|
37
|
+
throw new Error('resource type for match call should not contain any type')
|
|
38
|
+
}
|
|
39
|
+
const typeStr = resourceType.getSignature()
|
|
40
|
+
const result = await this.client.getAccountResource(accountAddress, typeStr, query)
|
|
41
|
+
return defaultMoveCoder(this.client.nodeUrl).decodeResource<T>(result)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Match all resources with type pattern, it could be a partial type like `amm.Pool<aptos_coin.AptosCoin.type(), ANY_TYPE>`
|
|
46
|
+
* @param accountAddress
|
|
47
|
+
* @param resourceType
|
|
48
|
+
* @param query
|
|
49
|
+
*/
|
|
50
|
+
async matchAll<T>(
|
|
51
|
+
accountAddress: MaybeHexString,
|
|
52
|
+
resourceType: TypeDescriptor<T>,
|
|
53
|
+
query?: ResourceQuery
|
|
54
|
+
): Promise<TypedMoveResource<T>[]> {
|
|
55
|
+
const result = await this.client.getAccountResources(accountAddress, query)
|
|
56
|
+
return defaultMoveCoder(this.client.nodeUrl).filterAndDecodeResources<T>(resourceType, result)
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/index.ts
CHANGED