@suxinmin/plugin-casper 1.0.3 → 1.0.4
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/dist/client.js +15 -4
- package/dist/config.d.ts +2 -2
- package/dist/config.js +2 -2
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -10,6 +10,16 @@ class AuthenticatedCasperRpcClient extends casper_js_sdk_1.CasperServiceByJsonRP
|
|
|
10
10
|
this.client.requestManager.transports = [transport];
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
function extractBlockHeader(blockInfo) {
|
|
14
|
+
if (blockInfo?.block?.header) {
|
|
15
|
+
return blockInfo.block.header;
|
|
16
|
+
}
|
|
17
|
+
const version2Header = blockInfo?.block_with_signatures?.block?.Version2?.header;
|
|
18
|
+
if (version2Header) {
|
|
19
|
+
return version2Header;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
13
23
|
class CasperClient {
|
|
14
24
|
constructor(config) {
|
|
15
25
|
this.config = config;
|
|
@@ -180,10 +190,11 @@ class CasperClient {
|
|
|
180
190
|
async getLatestBlock() {
|
|
181
191
|
try {
|
|
182
192
|
const blockInfo = await this.client.getLatestBlockInfo();
|
|
193
|
+
const header = extractBlockHeader(blockInfo);
|
|
183
194
|
return {
|
|
184
|
-
stateRootHash:
|
|
185
|
-
timestamp:
|
|
186
|
-
height:
|
|
195
|
+
stateRootHash: header?.state_root_hash,
|
|
196
|
+
timestamp: header?.timestamp,
|
|
197
|
+
height: header?.height,
|
|
187
198
|
};
|
|
188
199
|
}
|
|
189
200
|
catch (error) {
|
|
@@ -196,7 +207,7 @@ class CasperClient {
|
|
|
196
207
|
*/
|
|
197
208
|
async getStateRootHash() {
|
|
198
209
|
const blockInfo = await this.client.getLatestBlockInfo();
|
|
199
|
-
return blockInfo
|
|
210
|
+
return extractBlockHeader(blockInfo)?.state_root_hash || '';
|
|
200
211
|
}
|
|
201
212
|
}
|
|
202
213
|
exports.CasperClient = CasperClient;
|
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IAgentRuntime } from '@elizaos/core';
|
|
2
2
|
import { CasperClient, CasperConfig } from './client';
|
|
3
|
-
/**
|
|
4
|
-
export declare const DEFAULT_CASPER_NODE_URL = "https://
|
|
3
|
+
/** Official Casper Association public testnet RPC (no API key required). */
|
|
4
|
+
export declare const DEFAULT_CASPER_NODE_URL = "https://node.testnet.casper.network/rpc";
|
|
5
5
|
export declare function getCasperConfigFromRuntime(runtime: IAgentRuntime): CasperConfig;
|
|
6
6
|
export declare function createCasperClient(runtime: IAgentRuntime): CasperClient;
|
package/dist/config.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.DEFAULT_CASPER_NODE_URL = void 0;
|
|
|
4
4
|
exports.getCasperConfigFromRuntime = getCasperConfigFromRuntime;
|
|
5
5
|
exports.createCasperClient = createCasperClient;
|
|
6
6
|
const client_1 = require("./client");
|
|
7
|
-
/**
|
|
8
|
-
exports.DEFAULT_CASPER_NODE_URL = 'https://
|
|
7
|
+
/** Official Casper Association public testnet RPC (no API key required). */
|
|
8
|
+
exports.DEFAULT_CASPER_NODE_URL = 'https://node.testnet.casper.network/rpc';
|
|
9
9
|
function getCasperConfigFromRuntime(runtime) {
|
|
10
10
|
const nodeUrl = runtime.getSetting('CASPER_NODE_URL') || exports.DEFAULT_CASPER_NODE_URL;
|
|
11
11
|
const apiKey = runtime.getSetting('CASPER_API_KEY');
|