@flashbacktech/flashbackclient 0.2.69 → 0.2.71
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.
|
@@ -136,11 +136,17 @@ class DealOps {
|
|
|
136
136
|
* @returns Promise resolving to the payment result
|
|
137
137
|
*/
|
|
138
138
|
this.payPendingConsumption = (0, decorator_1.withSignature)(async (provider_id, consumer_id, deal_id) => {
|
|
139
|
-
|
|
139
|
+
const args = [
|
|
140
140
|
{ value: provider_id, type: 'address' },
|
|
141
141
|
{ value: consumer_id, type: 'address' },
|
|
142
142
|
{ value: deal_id, type: 'u32' }
|
|
143
|
-
]
|
|
143
|
+
];
|
|
144
|
+
if (this.context.serverSourceAddress) {
|
|
145
|
+
await (0, transaction_1.executeServerTransaction)(this.context, this.context.serverSourceAddress, "pay_pending_consumption", args);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, '', "pay_pending_consumption", args);
|
|
149
|
+
}
|
|
144
150
|
});
|
|
145
151
|
/**
|
|
146
152
|
* Updates deal consumption metrics (owner only)
|
|
@@ -151,13 +157,19 @@ class DealOps {
|
|
|
151
157
|
* @returns Promise resolving to the update result
|
|
152
158
|
*/
|
|
153
159
|
this.updateDealConsumption = (0, decorator_1.withSignature)(async (provider_id, consumer_id, deal_id, params) => {
|
|
154
|
-
|
|
160
|
+
const args = [
|
|
155
161
|
{ value: provider_id, type: 'address' },
|
|
156
162
|
{ value: consumer_id, type: 'address' },
|
|
157
163
|
{ value: deal_id, type: 'u32' },
|
|
158
164
|
{ value: params.storage_mb, type: 'u64' },
|
|
159
165
|
{ value: params.egress_mb, type: 'u64' }
|
|
160
|
-
]
|
|
166
|
+
];
|
|
167
|
+
if (this.context.serverSourceAddress) {
|
|
168
|
+
await (0, transaction_1.executeServerTransaction)(this.context, this.context.serverSourceAddress, "update_deal_consumption", args);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, '', "update_deal_consumption", args);
|
|
172
|
+
}
|
|
161
173
|
});
|
|
162
174
|
/**
|
|
163
175
|
* Updates deal SLA metrics (owner only)
|
|
@@ -168,13 +180,19 @@ class DealOps {
|
|
|
168
180
|
* @returns Promise resolving to the update result
|
|
169
181
|
*/
|
|
170
182
|
this.updateDealSLA = (0, decorator_1.withSignature)(async (provider_id, consumer_id, deal_id, params) => {
|
|
171
|
-
|
|
183
|
+
const args = [
|
|
172
184
|
{ value: provider_id, type: 'address' },
|
|
173
185
|
{ value: consumer_id, type: 'address' },
|
|
174
186
|
{ value: deal_id, type: 'u32' },
|
|
175
187
|
{ value: params.sla_avg_latency_ms, type: 'u32' },
|
|
176
188
|
{ value: params.sla_avg_uptime_pct, type: 'u32' }
|
|
177
|
-
]
|
|
189
|
+
];
|
|
190
|
+
if (this.context.serverSourceAddress) {
|
|
191
|
+
await (0, transaction_1.executeServerTransaction)(this.context, this.context.serverSourceAddress, "update_deal_sla", args);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, '', "update_deal_sla", args);
|
|
195
|
+
}
|
|
178
196
|
});
|
|
179
197
|
this.context = context;
|
|
180
198
|
}
|
|
@@ -18,6 +18,13 @@ export interface FlashOnStellarClientConfigV2 {
|
|
|
18
18
|
signTransaction?: (xdrToSign: string) => Promise<string>;
|
|
19
19
|
/** Network configuration for Stellar (testnet/public) */
|
|
20
20
|
network: StellarNetwork;
|
|
21
|
+
/**
|
|
22
|
+
* Stellar public key used as the source account for owner-only
|
|
23
|
+
* server-side operations (e.g. oracle worker calls).
|
|
24
|
+
* When set, owner-only methods use executeServerTransaction
|
|
25
|
+
* which does NOT prepend this address to the contract args.
|
|
26
|
+
*/
|
|
27
|
+
serverSourceAddress?: string;
|
|
21
28
|
}
|
|
22
29
|
export type ClientContext = FlashOnStellarClientConfigV2;
|
|
23
30
|
/**
|
|
@@ -7,6 +7,12 @@ export interface StellarNetwork {
|
|
|
7
7
|
}
|
|
8
8
|
declare const getNetwork: (network: string) => StellarNetwork;
|
|
9
9
|
declare const getPublicKeyFromPrivateKey: (privateKey: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Set a custom Soroban RPC server URL for a network.
|
|
12
|
+
* Use this to point the client at a different RPC endpoint (e.g. your own node).
|
|
13
|
+
* Pass `undefined` as url to clear the override and revert to the default for that network.
|
|
14
|
+
*/
|
|
15
|
+
export declare const setServer: (network: string, url: string | undefined) => void;
|
|
10
16
|
declare const getServer: (network: StellarNetwork) => rpc.Server;
|
|
11
17
|
interface ContractMethodCall {
|
|
12
18
|
method: string;
|
|
@@ -21,6 +27,16 @@ export interface ContractMethodResponse {
|
|
|
21
27
|
result: string | unknown;
|
|
22
28
|
}
|
|
23
29
|
export declare const getHorizonServer: (network: string) => Horizon.Server;
|
|
30
|
+
/**
|
|
31
|
+
* Executes a contract call using a server-side source account.
|
|
32
|
+
* Unlike executeWalletTransaction, this does NOT prepend the source address
|
|
33
|
+
* to the contract args — the args are passed as-is to the contract method.
|
|
34
|
+
* Used for owner-only operations invoked from backend workers.
|
|
35
|
+
*/
|
|
36
|
+
export declare const executeServerTransaction: (context: ClientContext, sourceAddress: string, method: string, args?: Array<{
|
|
37
|
+
value: string | number | bigint | boolean | null | Array<unknown> | undefined;
|
|
38
|
+
type: "string" | "symbol" | "address" | "u32" | "i32" | "u64" | "i64" | "u128" | "i128" | "bool" | "vec";
|
|
39
|
+
}>) => Promise<ContractMethodResponse>;
|
|
24
40
|
export declare const executeWalletTransaction: (context: ClientContext, wallet_address: string, method: string, additionalArgs?: Array<{
|
|
25
41
|
value: string | number | bigint | boolean | null | Array<unknown> | undefined;
|
|
26
42
|
type: "string" | "symbol" | "address" | "u32" | "i32" | "u64" | "i64" | "u128" | "i128" | "bool" | "vec";
|
|
@@ -34,5 +50,10 @@ export declare const executeMultiWalletTransactions: (context: ClientContext, wa
|
|
|
34
50
|
}>, extraOperations?: xdr.Operation[]) => Promise<ContractMethodResponse>;
|
|
35
51
|
declare const prepareTransaction: (context: ClientContext, address: string, contractCalls: ContractMethodCall | ContractMethodCall[], extraOperations?: xdr.Operation[]) => Promise<ContractMethodResponse>;
|
|
36
52
|
declare const signTransaction: (context: ClientContext, xdrToSign: string, privateKey: string) => Promise<Transaction<Memo<MemoType>, Operation[]> | FeeBumpTransaction>;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a signTransaction callback that signs with a private key.
|
|
55
|
+
* Use this for server-side / backend workers where there is no browser wallet.
|
|
56
|
+
*/
|
|
57
|
+
export declare const createPrivateKeySigner: (secretKey: string, networkPassphrase: string) => ((xdrToSign: string) => Promise<string>);
|
|
37
58
|
declare const sendTransaction: (context: ClientContext, signedTransactionXDR: string, bDebug?: boolean) => Promise<any>;
|
|
38
59
|
export { prepareTransaction, sendTransaction, signTransaction, getNetwork, getPublicKeyFromPrivateKey, getServer, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getServer = exports.getPublicKeyFromPrivateKey = exports.getNetwork = exports.signTransaction = exports.sendTransaction = exports.prepareTransaction = exports.executeMultiWalletTransactions = exports.executeWalletTransaction = exports.getHorizonServer = void 0;
|
|
3
|
+
exports.getServer = exports.getPublicKeyFromPrivateKey = exports.getNetwork = exports.signTransaction = exports.sendTransaction = exports.prepareTransaction = exports.createPrivateKeySigner = exports.executeMultiWalletTransactions = exports.executeWalletTransaction = exports.executeServerTransaction = exports.getHorizonServer = exports.setServer = void 0;
|
|
4
4
|
const timing_1 = require("../utils/timing");
|
|
5
5
|
// Polyfill for BigInt JSON serialization
|
|
6
6
|
BigInt.prototype.toJSON = function () {
|
|
@@ -32,30 +32,37 @@ const getPublicKeyFromPrivateKey = (privateKey) => {
|
|
|
32
32
|
return keypair.publicKey();
|
|
33
33
|
};
|
|
34
34
|
exports.getPublicKeyFromPrivateKey = getPublicKeyFromPrivateKey;
|
|
35
|
+
const DEFAULT_RPC_URLS = {
|
|
36
|
+
TESTNET: "https://soroban-testnet.stellar.org",
|
|
37
|
+
PUBLIC: "https://soroban-rpc.creit.tech",
|
|
38
|
+
};
|
|
39
|
+
const customRpcUrls = {};
|
|
40
|
+
/**
|
|
41
|
+
* Set a custom Soroban RPC server URL for a network.
|
|
42
|
+
* Use this to point the client at a different RPC endpoint (e.g. your own node).
|
|
43
|
+
* Pass `undefined` as url to clear the override and revert to the default for that network.
|
|
44
|
+
*/
|
|
45
|
+
const setServer = (network, url) => {
|
|
46
|
+
if (url === undefined) {
|
|
47
|
+
delete customRpcUrls[network];
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
customRpcUrls[network] = url;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.setServer = setServer;
|
|
35
54
|
const getServer = (network) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
serverUrl = "https://soroban-testnet.stellar.org";
|
|
40
|
-
break;
|
|
41
|
-
case "PUBLIC":
|
|
42
|
-
//serverUrl = "https://rpc.stellar.org";
|
|
43
|
-
//serverUrl = "https://stellar-soroban-public.nodies.app";
|
|
44
|
-
serverUrl = "https://soroban-rpc.mainnet.stellar.gateway.fm";
|
|
45
|
-
break;
|
|
55
|
+
const serverUrl = customRpcUrls[network.network] ?? DEFAULT_RPC_URLS[network.network] ?? "";
|
|
56
|
+
if (!serverUrl) {
|
|
57
|
+
throw new Error(`No RPC URL configured for network "${network.network}". Use setServer(network, url) or ensure the network is one of: TESTNET, PUBLIC.`);
|
|
46
58
|
}
|
|
47
|
-
// For Stellar SDK v13+, we need to handle the allowHttp issue
|
|
48
|
-
let server;
|
|
49
|
-
// Approach 1: Try with allowHttp option
|
|
50
59
|
try {
|
|
51
|
-
|
|
52
|
-
return server;
|
|
60
|
+
return new stellar_sdk_2.rpc.Server(serverUrl, { allowHttp: true });
|
|
53
61
|
}
|
|
54
62
|
catch (error) {
|
|
55
63
|
console.log(`Failed with allowHttp: true:`, error instanceof Error ? error.message : String(error));
|
|
64
|
+
throw new Error(`Failed to create Soroban RPC server for ${network.network} at ${serverUrl}. All configuration attempts failed.`);
|
|
56
65
|
}
|
|
57
|
-
// If all approaches fail, throw a comprehensive error
|
|
58
|
-
throw new Error(`Failed to create Soroban RPC server for ${network.network} at ${serverUrl}. All configuration attempts failed.`);
|
|
59
66
|
};
|
|
60
67
|
exports.getServer = getServer;
|
|
61
68
|
const TIMEOUT_TRANSACTION = 60;
|
|
@@ -72,6 +79,38 @@ const getHorizonServer = (network) => {
|
|
|
72
79
|
}
|
|
73
80
|
};
|
|
74
81
|
exports.getHorizonServer = getHorizonServer;
|
|
82
|
+
/**
|
|
83
|
+
* Executes a contract call using a server-side source account.
|
|
84
|
+
* Unlike executeWalletTransaction, this does NOT prepend the source address
|
|
85
|
+
* to the contract args — the args are passed as-is to the contract method.
|
|
86
|
+
* Used for owner-only operations invoked from backend workers.
|
|
87
|
+
*/
|
|
88
|
+
const executeServerTransaction = async (context, sourceAddress, method, args = []) => {
|
|
89
|
+
try {
|
|
90
|
+
const response = await prepareTransaction(context, sourceAddress, {
|
|
91
|
+
method,
|
|
92
|
+
args,
|
|
93
|
+
});
|
|
94
|
+
if (response.isSuccess) {
|
|
95
|
+
if (response.isReadOnly) {
|
|
96
|
+
return response;
|
|
97
|
+
}
|
|
98
|
+
const signedTxXDR = await context.signTransaction(response.result);
|
|
99
|
+
const sendResponse = await sendTransaction(context, signedTxXDR);
|
|
100
|
+
return {
|
|
101
|
+
isSuccess: true,
|
|
102
|
+
isReadOnly: false,
|
|
103
|
+
result: sendResponse,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return response;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error('executeServerTransaction: Error occurred:', error);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
exports.executeServerTransaction = executeServerTransaction;
|
|
75
114
|
const executeWalletTransaction = async (context, wallet_address, method, additionalArgs = []) => {
|
|
76
115
|
try {
|
|
77
116
|
const response = await prepareTransaction(context, wallet_address, {
|
|
@@ -225,6 +264,19 @@ const signTransaction = async (context, xdrToSign, privateKey) => {
|
|
|
225
264
|
return preparedTransaction;
|
|
226
265
|
};
|
|
227
266
|
exports.signTransaction = signTransaction;
|
|
267
|
+
/**
|
|
268
|
+
* Creates a signTransaction callback that signs with a private key.
|
|
269
|
+
* Use this for server-side / backend workers where there is no browser wallet.
|
|
270
|
+
*/
|
|
271
|
+
const createPrivateKeySigner = (secretKey, networkPassphrase) => {
|
|
272
|
+
return async (xdrToSign) => {
|
|
273
|
+
const keypair = stellar_sdk_1.Keypair.fromSecret(secretKey);
|
|
274
|
+
const tx = stellar_sdk_1.TransactionBuilder.fromXDR(xdrToSign, networkPassphrase);
|
|
275
|
+
tx.sign(keypair);
|
|
276
|
+
return tx.toXDR();
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
exports.createPrivateKeySigner = createPrivateKeySigner;
|
|
228
280
|
const sendTransaction = async (context, signedTransactionXDR, bDebug = false) => {
|
|
229
281
|
try {
|
|
230
282
|
const server = getServer(context.network);
|