@pooflabs/core 0.0.11 → 0.0.12
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/index.js +43 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -3
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +20 -0
- package/dist/utils/sol/poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZpDevnet-program.d.ts +127 -54
- package/dist/utils/sol/poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZpMainnet-program.d.ts +127 -54
- package/package.json +62 -62
package/dist/index.mjs
CHANGED
|
@@ -3386,9 +3386,15 @@ async function setMany(many, options) {
|
|
|
3386
3386
|
clearCacheByPrefix(path);
|
|
3387
3387
|
});
|
|
3388
3388
|
if (setResponse.status === 202) {
|
|
3389
|
-
// This means that the document needs to be set on-chain
|
|
3390
|
-
// required info to run this transaction.
|
|
3391
|
-
const transactions = setResponse.data
|
|
3389
|
+
// This means that the document needs to be set on-chain (or signed for offchain),
|
|
3390
|
+
// the API did nothing and gave us the required info to run this transaction.
|
|
3391
|
+
const { transactions, offchainTransaction } = setResponse.data;
|
|
3392
|
+
// Handle offchain transaction flow (for 'offchain' protocol apps)
|
|
3393
|
+
if (offchainTransaction) {
|
|
3394
|
+
const transactionResult = await handleOffchainTransaction(offchainTransaction, authProvider, options);
|
|
3395
|
+
return Object.assign(Object.assign({}, documents.map(d => d.document)), { transactionId: transactionResult.signature, signedTransaction: transactionResult.signedTransaction });
|
|
3396
|
+
}
|
|
3397
|
+
// Handle Solana on-chain transaction flow
|
|
3392
3398
|
let lastTxSignature = undefined;
|
|
3393
3399
|
let signedTransaction = undefined;
|
|
3394
3400
|
for (let i = 0; i < transactions.length; i++) {
|
|
@@ -3469,6 +3475,40 @@ async function setMany(many, options) {
|
|
|
3469
3475
|
const transactionResult = await authProvider.runTransaction(undefined, solTransaction, options);
|
|
3470
3476
|
return transactionResult;
|
|
3471
3477
|
}
|
|
3478
|
+
async function handleOffchainTransaction(tx, authProvider, options) {
|
|
3479
|
+
const config = await getConfig();
|
|
3480
|
+
// 1. Sign the transaction message using the auth provider
|
|
3481
|
+
const signature = await authProvider.signMessage(tx.message);
|
|
3482
|
+
// 2. Create signed transaction
|
|
3483
|
+
const signedTx = {
|
|
3484
|
+
transaction: tx,
|
|
3485
|
+
signature
|
|
3486
|
+
};
|
|
3487
|
+
// 3. If shouldSubmitTx is false, return signed but not submitted
|
|
3488
|
+
if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
|
|
3489
|
+
return {
|
|
3490
|
+
signature: '',
|
|
3491
|
+
signedTransaction: bufferExports.Buffer.from(JSON.stringify(signedTx)).toString('base64')
|
|
3492
|
+
};
|
|
3493
|
+
}
|
|
3494
|
+
// 4. Submit to RPC endpoint
|
|
3495
|
+
const rpcUrl = `${config.apiUrl}/app/${config.appId}/rpc`;
|
|
3496
|
+
const rpcResponse = await fetch(rpcUrl, {
|
|
3497
|
+
method: 'POST',
|
|
3498
|
+
headers: { 'Content-Type': 'application/json' },
|
|
3499
|
+
body: JSON.stringify({
|
|
3500
|
+
jsonrpc: '2.0',
|
|
3501
|
+
id: 1,
|
|
3502
|
+
method: 'sendTransaction',
|
|
3503
|
+
params: [bufferExports.Buffer.from(JSON.stringify(signedTx)).toString('base64')]
|
|
3504
|
+
})
|
|
3505
|
+
});
|
|
3506
|
+
const result = await rpcResponse.json();
|
|
3507
|
+
if (result.error) {
|
|
3508
|
+
throw new Error(result.error.message);
|
|
3509
|
+
}
|
|
3510
|
+
return { signature: result.result };
|
|
3511
|
+
}
|
|
3472
3512
|
}
|
|
3473
3513
|
// Helper to clear cache entries by prefix
|
|
3474
3514
|
function clearCacheByPrefix(prefix) {
|