@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.js
CHANGED
|
@@ -3406,9 +3406,15 @@ async function setMany(many, options) {
|
|
|
3406
3406
|
clearCacheByPrefix(path);
|
|
3407
3407
|
});
|
|
3408
3408
|
if (setResponse.status === 202) {
|
|
3409
|
-
// This means that the document needs to be set on-chain
|
|
3410
|
-
// required info to run this transaction.
|
|
3411
|
-
const transactions = setResponse.data
|
|
3409
|
+
// This means that the document needs to be set on-chain (or signed for offchain),
|
|
3410
|
+
// the API did nothing and gave us the required info to run this transaction.
|
|
3411
|
+
const { transactions, offchainTransaction } = setResponse.data;
|
|
3412
|
+
// Handle offchain transaction flow (for 'offchain' protocol apps)
|
|
3413
|
+
if (offchainTransaction) {
|
|
3414
|
+
const transactionResult = await handleOffchainTransaction(offchainTransaction, authProvider, options);
|
|
3415
|
+
return Object.assign(Object.assign({}, documents.map(d => d.document)), { transactionId: transactionResult.signature, signedTransaction: transactionResult.signedTransaction });
|
|
3416
|
+
}
|
|
3417
|
+
// Handle Solana on-chain transaction flow
|
|
3412
3418
|
let lastTxSignature = undefined;
|
|
3413
3419
|
let signedTransaction = undefined;
|
|
3414
3420
|
for (let i = 0; i < transactions.length; i++) {
|
|
@@ -3489,6 +3495,40 @@ async function setMany(many, options) {
|
|
|
3489
3495
|
const transactionResult = await authProvider.runTransaction(undefined, solTransaction, options);
|
|
3490
3496
|
return transactionResult;
|
|
3491
3497
|
}
|
|
3498
|
+
async function handleOffchainTransaction(tx, authProvider, options) {
|
|
3499
|
+
const config = await getConfig();
|
|
3500
|
+
// 1. Sign the transaction message using the auth provider
|
|
3501
|
+
const signature = await authProvider.signMessage(tx.message);
|
|
3502
|
+
// 2. Create signed transaction
|
|
3503
|
+
const signedTx = {
|
|
3504
|
+
transaction: tx,
|
|
3505
|
+
signature
|
|
3506
|
+
};
|
|
3507
|
+
// 3. If shouldSubmitTx is false, return signed but not submitted
|
|
3508
|
+
if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
|
|
3509
|
+
return {
|
|
3510
|
+
signature: '',
|
|
3511
|
+
signedTransaction: bufferExports.Buffer.from(JSON.stringify(signedTx)).toString('base64')
|
|
3512
|
+
};
|
|
3513
|
+
}
|
|
3514
|
+
// 4. Submit to RPC endpoint
|
|
3515
|
+
const rpcUrl = `${config.apiUrl}/app/${config.appId}/rpc`;
|
|
3516
|
+
const rpcResponse = await fetch(rpcUrl, {
|
|
3517
|
+
method: 'POST',
|
|
3518
|
+
headers: { 'Content-Type': 'application/json' },
|
|
3519
|
+
body: JSON.stringify({
|
|
3520
|
+
jsonrpc: '2.0',
|
|
3521
|
+
id: 1,
|
|
3522
|
+
method: 'sendTransaction',
|
|
3523
|
+
params: [bufferExports.Buffer.from(JSON.stringify(signedTx)).toString('base64')]
|
|
3524
|
+
})
|
|
3525
|
+
});
|
|
3526
|
+
const result = await rpcResponse.json();
|
|
3527
|
+
if (result.error) {
|
|
3528
|
+
throw new Error(result.error.message);
|
|
3529
|
+
}
|
|
3530
|
+
return { signature: result.result };
|
|
3531
|
+
}
|
|
3492
3532
|
}
|
|
3493
3533
|
// Helper to clear cache entries by prefix
|
|
3494
3534
|
function clearCacheByPrefix(prefix) {
|