@clonegod/ttd-sui-common 1.0.0 → 1.0.3
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 +12 -0
- package/dist/grpc/grpc-connection.d.ts +13 -0
- package/dist/grpc/grpc-connection.js +99 -0
- package/dist/grpc/index.d.ts +5 -0
- package/dist/grpc/index.js +13 -0
- package/dist/grpc/ledger-service.d.ts +12 -0
- package/dist/grpc/ledger-service.js +159 -0
- package/dist/grpc/live-data-service.d.ts +10 -0
- package/dist/grpc/live-data-service.js +101 -0
- package/dist/grpc/subscription-service.d.ts +7 -0
- package/dist/grpc/subscription-service.js +63 -0
- package/dist/grpc/transaction-service.d.ts +7 -0
- package/dist/grpc/transaction-service.js +48 -0
- package/dist/index.js +1 -1
- package/dist/rpc/account-api.d.ts +14 -0
- package/dist/rpc/account-api.js +113 -0
- package/dist/rpc/coin-api.d.ts +0 -0
- package/dist/rpc/coin-api.js +0 -0
- package/dist/rpc/index.d.ts +5 -0
- package/dist/rpc/index.js +13 -0
- package/dist/rpc/rpc-connection.d.ts +8 -0
- package/dist/rpc/rpc-connection.js +54 -0
- package/dist/test/test.d.ts +1 -0
- package/dist/test/test.js +126 -0
- package/dist/test/test_grpc.d.ts +1 -0
- package/dist/test/test_grpc.js +93 -0
- package/dist/test/test_rpc.d.ts +1 -0
- package/dist/test/test_rpc.js +34 -0
- package/dist/transaction_28FaeTYoctpP1VdWCuyPxNEBeaMm3ebj27kdF5umi9YL.json +4754 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +43 -0
- package/package.json +21 -16
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AccountApi = void 0;
|
|
13
|
+
class AccountApi {
|
|
14
|
+
constructor(connection) {
|
|
15
|
+
this.connection = connection;
|
|
16
|
+
}
|
|
17
|
+
getBalance(owner_1) {
|
|
18
|
+
return __awaiter(this, arguments, void 0, function* (owner, coinType = '0x2::sui::SUI') {
|
|
19
|
+
return this.connection.makeRequest('suix_getBalance', [owner, coinType]);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
getAllBalances(owner) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return this.connection.makeRequest('suix_getAllBalances', [owner]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getAllCoins(owner, cursor, limit) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const params = [owner];
|
|
30
|
+
if (cursor)
|
|
31
|
+
params.push(cursor);
|
|
32
|
+
if (limit)
|
|
33
|
+
params.push(limit.toString());
|
|
34
|
+
return this.connection.makeRequest('suix_getAllCoins', params);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getAllCoinsComplete(owner_1) {
|
|
38
|
+
return __awaiter(this, arguments, void 0, function* (owner, limit = 50) {
|
|
39
|
+
const allCoins = [];
|
|
40
|
+
let cursor;
|
|
41
|
+
let hasNextPage = true;
|
|
42
|
+
while (hasNextPage) {
|
|
43
|
+
const result = yield this.getAllCoins(owner, cursor, limit);
|
|
44
|
+
if (result.data && Array.isArray(result.data)) {
|
|
45
|
+
allCoins.push(...result.data);
|
|
46
|
+
}
|
|
47
|
+
hasNextPage = result.hasNextPage === true;
|
|
48
|
+
cursor = result.nextCursor;
|
|
49
|
+
}
|
|
50
|
+
return allCoins;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
getCoins(owner, coinType, cursor, limit) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const params = [owner, coinType];
|
|
56
|
+
if (cursor)
|
|
57
|
+
params.push(cursor);
|
|
58
|
+
if (limit)
|
|
59
|
+
params.push(limit.toString());
|
|
60
|
+
return this.connection.makeRequest('suix_getCoins', params);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
getCoinsComplete(owner_1, coinType_1) {
|
|
64
|
+
return __awaiter(this, arguments, void 0, function* (owner, coinType, limit = 50) {
|
|
65
|
+
const allCoins = [];
|
|
66
|
+
let cursor;
|
|
67
|
+
let hasNextPage = true;
|
|
68
|
+
while (hasNextPage) {
|
|
69
|
+
const result = yield this.getCoins(owner, coinType, cursor, limit);
|
|
70
|
+
if (result.data && Array.isArray(result.data)) {
|
|
71
|
+
allCoins.push(...result.data);
|
|
72
|
+
}
|
|
73
|
+
hasNextPage = result.hasNextPage === true;
|
|
74
|
+
cursor = result.nextCursor;
|
|
75
|
+
}
|
|
76
|
+
return allCoins;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getOwnedObjects(owner, filter, cursor, limit) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const params = [owner];
|
|
82
|
+
if (filter)
|
|
83
|
+
params.push(filter);
|
|
84
|
+
if (cursor)
|
|
85
|
+
params.push(cursor);
|
|
86
|
+
if (limit)
|
|
87
|
+
params.push(limit.toString());
|
|
88
|
+
return this.connection.makeRequest('suix_getOwnedObjects', params);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getAllOwnedObjects(owner_1, filter_1) {
|
|
92
|
+
return __awaiter(this, arguments, void 0, function* (owner, filter, limit = 50) {
|
|
93
|
+
const allObjects = [];
|
|
94
|
+
let cursor;
|
|
95
|
+
let hasNextPage = true;
|
|
96
|
+
while (hasNextPage) {
|
|
97
|
+
const result = yield this.getOwnedObjects(owner, filter, cursor, limit);
|
|
98
|
+
if (result.data && Array.isArray(result.data)) {
|
|
99
|
+
allObjects.push(...result.data);
|
|
100
|
+
}
|
|
101
|
+
hasNextPage = result.hasNextPage === true;
|
|
102
|
+
cursor = result.nextCursor;
|
|
103
|
+
}
|
|
104
|
+
return allObjects;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
getCoinMetadata(coinType) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
return this.connection.makeRequest('suix_getCoinMetadata', [coinType]);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.AccountApi = AccountApi;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetworkService = exports.TransactionService = exports.ObjectService = exports.AccountService = exports.RpcConnection = void 0;
|
|
4
|
+
var rpc_connection_1 = require("./rpc-connection");
|
|
5
|
+
Object.defineProperty(exports, "RpcConnection", { enumerable: true, get: function () { return rpc_connection_1.RpcConnection; } });
|
|
6
|
+
var account_service_1 = require("./account-service");
|
|
7
|
+
Object.defineProperty(exports, "AccountService", { enumerable: true, get: function () { return account_service_1.AccountService; } });
|
|
8
|
+
var object_service_1 = require("./object-service");
|
|
9
|
+
Object.defineProperty(exports, "ObjectService", { enumerable: true, get: function () { return object_service_1.ObjectService; } });
|
|
10
|
+
var transaction_service_1 = require("./transaction-service");
|
|
11
|
+
Object.defineProperty(exports, "TransactionService", { enumerable: true, get: function () { return transaction_service_1.TransactionService; } });
|
|
12
|
+
var network_service_1 = require("./network-service");
|
|
13
|
+
Object.defineProperty(exports, "NetworkService", { enumerable: true, get: function () { return network_service_1.NetworkService; } });
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RpcConnection = void 0;
|
|
13
|
+
class RpcConnection {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.endpoint = process.env.RPC_ENDPOINT || '';
|
|
16
|
+
if (!this.endpoint) {
|
|
17
|
+
throw new Error('RPC_ENDPOINT 环境变量未设置');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
static getInstance() {
|
|
21
|
+
if (!RpcConnection.instance) {
|
|
22
|
+
RpcConnection.instance = new RpcConnection();
|
|
23
|
+
}
|
|
24
|
+
return RpcConnection.instance;
|
|
25
|
+
}
|
|
26
|
+
makeRequest(method, params) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const response = yield fetch(this.endpoint, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/json',
|
|
32
|
+
},
|
|
33
|
+
body: JSON.stringify({
|
|
34
|
+
jsonrpc: '2.0',
|
|
35
|
+
id: 1,
|
|
36
|
+
method: method,
|
|
37
|
+
params: params
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
42
|
+
}
|
|
43
|
+
const data = yield response.json();
|
|
44
|
+
if (data.error) {
|
|
45
|
+
throw new Error(`JSON-RPC error: ${data.error.message}`);
|
|
46
|
+
}
|
|
47
|
+
return data.result;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getEndpoint() {
|
|
51
|
+
return this.endpoint;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.RpcConnection = RpcConnection;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const dotenv = __importStar(require("dotenv"));
|
|
37
|
+
dotenv.config();
|
|
38
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
39
|
+
const protoLoader = __importStar(require("@grpc/proto-loader"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const PROTO_PATH = path.join(__dirname, 'protos/sui/rpc/v2beta2/ledger_service.proto');
|
|
42
|
+
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
|
|
43
|
+
keepCase: true,
|
|
44
|
+
longs: String,
|
|
45
|
+
enums: String,
|
|
46
|
+
defaults: true,
|
|
47
|
+
oneofs: true,
|
|
48
|
+
includeDirs: [path.join(__dirname, 'protos')],
|
|
49
|
+
});
|
|
50
|
+
const suiProto = grpc.loadPackageDefinition(packageDefinition);
|
|
51
|
+
const LedgerService = suiProto.sui.rpc.v2beta2.LedgerService;
|
|
52
|
+
const endpoint = process.env.SUI_GRPC_ENDPOINT;
|
|
53
|
+
const token = process.env.SUI_GRPC_TOKEN;
|
|
54
|
+
if (!endpoint || !token) {
|
|
55
|
+
throw new Error('SUI_GRPC_ENDPOINT and SUI_GRPC_TOKEN must be set');
|
|
56
|
+
}
|
|
57
|
+
const client = new LedgerService(endpoint, grpc.credentials.createSsl(), {
|
|
58
|
+
'grpc.keepalive_time_ms': 30000,
|
|
59
|
+
'grpc.keepalive_timeout_ms': 5000,
|
|
60
|
+
'grpc.keepalive_permit_without_calls': true,
|
|
61
|
+
'grpc.http2.max_pings_without_data': 0,
|
|
62
|
+
'grpc.http2.min_time_between_pings_ms': 10000,
|
|
63
|
+
'grpc.http2.min_ping_interval_without_data_ms': 300000
|
|
64
|
+
});
|
|
65
|
+
const metadata = new grpc.Metadata();
|
|
66
|
+
metadata.add('x-token', token);
|
|
67
|
+
const suiSystemPackageId = '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
68
|
+
const request = {
|
|
69
|
+
object_id: suiSystemPackageId,
|
|
70
|
+
read_mask: {
|
|
71
|
+
paths: [
|
|
72
|
+
'object_id',
|
|
73
|
+
'version',
|
|
74
|
+
'digest',
|
|
75
|
+
'owner',
|
|
76
|
+
'object_type',
|
|
77
|
+
'has_public_transfer',
|
|
78
|
+
'previous_transaction',
|
|
79
|
+
'storage_rebate'
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
function decodeBytes(obj) {
|
|
84
|
+
if (Array.isArray(obj)) {
|
|
85
|
+
return obj.map(decodeBytes);
|
|
86
|
+
}
|
|
87
|
+
else if (obj && typeof obj === 'object') {
|
|
88
|
+
const result = {};
|
|
89
|
+
for (const key in obj) {
|
|
90
|
+
const val = obj[key];
|
|
91
|
+
if (val instanceof Uint8Array || ((val === null || val === void 0 ? void 0 : val.type) === 'Buffer' && Array.isArray(val.data))) {
|
|
92
|
+
const buffer = val instanceof Uint8Array ? val : Buffer.from(val.data);
|
|
93
|
+
result[key] = buffer.toString('hex');
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
result[key] = decodeBytes(val);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return obj;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
client.GetObject(request, metadata, (err, response) => {
|
|
106
|
+
if (err) {
|
|
107
|
+
console.error('gRPC Error:', err);
|
|
108
|
+
console.error('Error details:', {
|
|
109
|
+
code: err.code,
|
|
110
|
+
details: err.details,
|
|
111
|
+
metadata: err.metadata
|
|
112
|
+
});
|
|
113
|
+
if (err.code === 14) {
|
|
114
|
+
console.error('Connection failed. Please check:');
|
|
115
|
+
console.error('1. QuickNode endpoint is correct');
|
|
116
|
+
console.error('2. Token is valid');
|
|
117
|
+
console.error('3. Network connection is stable');
|
|
118
|
+
console.error('4. Port 9000 is accessible');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
const decoded = decodeBytes(response);
|
|
123
|
+
console.log('Response:', JSON.stringify(decoded, null, 2));
|
|
124
|
+
}
|
|
125
|
+
client.close();
|
|
126
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
13
|
+
const grpc_connection_1 = require("../grpc/grpc-connection");
|
|
14
|
+
const ledger_service_1 = require("../grpc/ledger-service");
|
|
15
|
+
const subscription_service_1 = require("../grpc/subscription-service");
|
|
16
|
+
const live_data_service_1 = require("../grpc/live-data-service");
|
|
17
|
+
const grpc_endpoint = process.env.SUI_GRPC_ENDPOINT;
|
|
18
|
+
const grpc_token = process.env.SUI_GRPC_TOKEN;
|
|
19
|
+
const test_get_service_info = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
21
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
22
|
+
const serviceInfo = yield ledgerService.getServiceInfo();
|
|
23
|
+
(0, dist_1.log_info)(`serviceInfo`, serviceInfo);
|
|
24
|
+
});
|
|
25
|
+
const test_get_epoch = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
27
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
28
|
+
const epoch = yield ledgerService.getEpoch();
|
|
29
|
+
(0, dist_1.log_info)(`epoch`, epoch);
|
|
30
|
+
});
|
|
31
|
+
const test_get_checkpoint = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
33
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
34
|
+
const checkpoint = yield ledgerService.getCheckpoint();
|
|
35
|
+
(0, dist_1.log_info)(`checkpoint`, checkpoint);
|
|
36
|
+
});
|
|
37
|
+
const test_get_object = (object_id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
39
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
40
|
+
const object = yield ledgerService.getObject(object_id);
|
|
41
|
+
(0, dist_1.log_info)(`object`, object);
|
|
42
|
+
});
|
|
43
|
+
const test_get_objects = (object_ids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
45
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
46
|
+
const objects = yield ledgerService.batchGetObjects(object_ids);
|
|
47
|
+
(0, dist_1.log_info)(`objects`, objects);
|
|
48
|
+
});
|
|
49
|
+
const test_get_transaction = (txid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
51
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
52
|
+
const transaction = yield ledgerService.getTransaction(txid);
|
|
53
|
+
(0, dist_1.log_info)(`transaction`, transaction);
|
|
54
|
+
});
|
|
55
|
+
const test_subscribe_checkpoints = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
57
|
+
const subscriptionService = new subscription_service_1.SubscriptionService(connection);
|
|
58
|
+
subscriptionService.subscribeCheckpoints((response) => {
|
|
59
|
+
(0, dist_1.log_info)(response.cursor);
|
|
60
|
+
}, (error) => {
|
|
61
|
+
(0, dist_1.log_info)(`error`, error);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
const test_get_balance = (wallet_address, coin_type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
66
|
+
const liveDataService = new live_data_service_1.LiveDataService(connection);
|
|
67
|
+
const balance = yield liveDataService.getBalance(wallet_address, coin_type);
|
|
68
|
+
(0, dist_1.log_info)(`balance`, balance);
|
|
69
|
+
});
|
|
70
|
+
const test_list_balances = (wallet_address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
72
|
+
const liveDataService = new live_data_service_1.LiveDataService(connection);
|
|
73
|
+
const balances = yield liveDataService.listBalances(wallet_address);
|
|
74
|
+
(0, dist_1.log_info)(`balances`, balances);
|
|
75
|
+
});
|
|
76
|
+
const test_get_coin_info = (coin_type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
78
|
+
const liveDataService = new live_data_service_1.LiveDataService(connection);
|
|
79
|
+
const coinInfo = yield liveDataService.getCoinInfo(coin_type);
|
|
80
|
+
(0, dist_1.log_info)(`coinInfo`, coinInfo);
|
|
81
|
+
});
|
|
82
|
+
const test_list_owned_objects = (wallet_address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
84
|
+
const liveDataService = new live_data_service_1.LiveDataService(connection);
|
|
85
|
+
const ownedObjects = yield liveDataService.listOwnedObjects(wallet_address);
|
|
86
|
+
(0, dist_1.log_info)(`ownedObjects`, ownedObjects);
|
|
87
|
+
});
|
|
88
|
+
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
test_get_objects(['0xc99d460f211ef0a8f89d7bf4bdc373e593f84258b0e57f222217a1cca1ae302d', '0x2374395d7e409c411bf63a14eba8d47b9ef9bf83b2bb215cf678d711e11be806']);
|
|
90
|
+
const wallet_address = '0x6367c8755b8c39cab7305bfa75cb17d050508d2e55f6862a7682377ad6d46ee7';
|
|
91
|
+
const usdc_coin_type = '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC';
|
|
92
|
+
});
|
|
93
|
+
main();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
13
|
+
const rpc_connection_1 = require("../rpc/rpc-connection");
|
|
14
|
+
const account_api_1 = require("../rpc/account-api");
|
|
15
|
+
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const wallet_address = '0x6367c8755b8c39cab7305bfa75cb17d050508d2e55f6862a7682377ad6d46ee7';
|
|
17
|
+
const sui_coin_type = '0x2::sui::SUI';
|
|
18
|
+
const usdc_coin_type = '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC';
|
|
19
|
+
const connection = rpc_connection_1.RpcConnection.getInstance();
|
|
20
|
+
const accountApi = new account_api_1.AccountApi(connection);
|
|
21
|
+
const sui_coin_metadata = yield accountApi.getCoinMetadata(sui_coin_type);
|
|
22
|
+
(0, dist_1.log_info)(`sui_coin_metadata`, sui_coin_metadata);
|
|
23
|
+
const usdc_coin_metadata = yield accountApi.getCoinMetadata(usdc_coin_type);
|
|
24
|
+
(0, dist_1.log_info)(`usdc_coin_metadata`, usdc_coin_metadata);
|
|
25
|
+
const sui_balance = yield accountApi.getBalance(wallet_address);
|
|
26
|
+
(0, dist_1.log_info)(`sui_balance`, sui_balance);
|
|
27
|
+
const usdc_balance = yield accountApi.getBalance(wallet_address, usdc_coin_type);
|
|
28
|
+
(0, dist_1.log_info)(`usdc_balance`, usdc_balance);
|
|
29
|
+
const allBalances = yield accountApi.getAllBalances(wallet_address);
|
|
30
|
+
(0, dist_1.log_info)(`allBalances`, allBalances);
|
|
31
|
+
const ownedObjects = yield accountApi.getOwnedObjects(wallet_address);
|
|
32
|
+
(0, dist_1.log_info)(`ownedObjects`, ownedObjects);
|
|
33
|
+
});
|
|
34
|
+
main();
|