Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ jobs:
echo "TEST_DIR=$TEST_DIR" >> "$GITHUB_ENV"
mkdir -p "$TEST_DIR"
just run-store-chunked-data "bulletin-westend-runtime"
- name: Run store big data (PJS-API, RPC node, Westend parachain)
working-directory: examples
run: |
export TEST_DIR="$(mktemp -d $GITHUB_WORKSPACE/bulletin-tests-run-XXXXX)/test"
echo "TEST_DIR=$TEST_DIR" >> $GITHUB_ENV
mkdir -p "$TEST_DIR"
just run-store-big-data "bulletin-westend-runtime"

# TODO: Polkadot parachain

Expand All @@ -203,6 +210,14 @@ jobs:
mkdir -p "$TEST_DIR"
just run-store-chunked-data "bulletin-polkadot-runtime"

- name: Run store big data (PJS-API, RPC node, Polkadot solochain)
working-directory: examples
run: |
export TEST_DIR="$(mktemp -d $GITHUB_WORKSPACE/bulletin-tests-run-XXXXX)/test"
echo "TEST_DIR=$TEST_DIR" >> $GITHUB_ENV
mkdir -p "$TEST_DIR"
just run-store-big-data "bulletin-polkadot-runtime"

# Collects logs from the last failed zombienet run.
- name: Upload Zombienet logs (on failure)
if: failure()
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ package-lock.json
examples/retrieved_picture.*
kubo/
zombienet-*
zombienet/
75 changes: 53 additions & 22 deletions examples/api.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,66 @@
import { cidFromBytes } from "./cid_dag_metadata.js";
import { Binary } from '@polkadot-api/substrate-bindings';

export async function authorizeAccount(typedApi, sudoSigner, who, transactions, bytes) {
console.log('Authorizing account...');

const authorizeTx = typedApi.tx.TransactionStorage.authorize_account({
who,
transactions,
bytes
});

const sudoTx = typedApi.tx.Sudo.sudo({
call: authorizeTx.decodedCall
});
import { Binary, Enum } from '@polkadot-api/substrate-bindings';

export async function authorizeAccount(
typedApi,
sudoSigner,
whos,
transactions,
bytes,
txMode = TX_MODE_IN_BLOCK
) {
const accounts = Array.isArray(whos) ? whos : [whos];

console.log(
`⬆️ Authorizing accounts: ${accounts.join(', ')} ` +
`for transactions: ${transactions} and bytes: ${bytes}...`
);

// TODO: rewrite with batch
for (const who of accounts) {
const auth = await typedApi.query.TransactionStorage.Authorizations.getValue(Enum("Account", who));
console.log(`ℹ Account: ${who} Authorization info: `, auth);
if (auth != null) {
const authValue = auth.extent;
const accountTransactions = authValue.transactions;
const accountBytes = authValue.bytes;

if (accountTransactions > transactions && accountBytes > bytes) {
console.log('✅ Account authorization is sufficient.');
continue;
}
} else {
console.log('ℹ️ No existing authorization found — requesting new one...');
}

const authorizeTx = typedApi.tx.TransactionStorage.authorize_account({
who,
transactions,
bytes
});
const sudoTx = typedApi.tx.Sudo.sudo({
call: authorizeTx.decodedCall
});

await waitForTransaction(sudoTx, sudoSigner, "Authorize");
await waitForTransaction(sudoTx, sudoSigner, "Authorize", txMode);
}
}

export async function store(typedApi, signer, data) {
export async function store(typedApi, signer, data, txMode = TX_MODE_IN_BLOCK) {
console.log('⬆️ Storing data with length=', data.length);
const cid = await cidFromBytes(data);

// Convert data to Uint8Array then wrap in Binary for PAPI typed API
const dataBytes = typeof data === 'string' ?
new Uint8Array(Buffer.from(data)) :
new Uint8Array(data);
const bytes =
typeof data === 'string'
? new Uint8Array(Buffer.from(data))
: data instanceof Uint8Array
? data
: new Uint8Array(data);
const binaryData = new Binary(bytes);

const binaryData = Binary.fromBytes(dataBytes);
const tx = typedApi.tx.TransactionStorage.store({ data: binaryData });

await waitForTransaction(tx, signer, "Store");
await waitForTransaction(tx, signer, "Store", txMode);
return cid;
}

Expand Down
Loading