Skip to content
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.83.0
targets: wasm32-unknown-unknown

- name: Install wasm-pack
run: cargo install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

# Need to build the WASM before type-checking
# otherwise we're missing code and tsc will fail
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/deploy-runtime-upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Deploy Runtime Upgrade to GitHub Pages

on:
push:
branches: [paseo-runtime-upgrade]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages-paseo-runtime-upgrade"
cancel-in-progress: true

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 22.x

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.83.0
targets: wasm32-unknown-unknown

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

# Need to build the WASM before type-checking
# otherwise we're missing code and tsc will fail
- name: Build WASM
run: pnpm build:wasm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Generate papi descriptors
run: pnpm run papi:generate

- name: Build
run: pnpm build

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: dist

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.83.0
targets: wasm32-unknown-unknown

- name: Install wasm-pack
Expand Down
Binary file modified .papi/metadata/polkaStorage.scale
Binary file not shown.
6 changes: 3 additions & 3 deletions .papi/polkadot-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"descriptorPath": ".papi/descriptors",
"entries": {
"polkaStorage": {
"wsUrl": "ws://localhost:42069",
"wsUrl": "wss://collator.polka-storage.eiger.co",
"metadata": ".papi/metadata/polkaStorage.scale",
"genesis": "0x4545454545454545454545454545454545454545454545454545454545454545",
"codeHash": "0xb84fe515e735f6a2ca1032f6d1ff7befc5a29c5c48ea56bd90eebb0d509533ee"
"genesis": "0xa6f9a4facafa6157734b6a52503070304d34919a8299f46e6c7bde2ee000ccd6",
"codeHash": "0x6f566b9e2ea5b0c4fc8389087736baf74e42dd8fa8ab0d7f3da55dc62a39ccaa"
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"ipfs-unixfs": "^11.2.1",
"lucide-react": "^0.477.0",
"multiformats": "^13.3.2",
"papi": "^1.1.2",
"polkadot-api": "^1.14.1",
"postcss": "^8.5.3",
"react": "^19.0.0",
Expand Down
66 changes: 54 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/lib/conversion.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Multiaddr, NodeAddress } from "@multiformats/multiaddr";
import { BLOCK_TIME } from "./consts";

export function blockToTime(
Expand Down Expand Up @@ -60,3 +61,26 @@ export function formatDuration(duration: {
}
return `${result.join(", ")}`;
}

export function baseURLFromP2pMultiaddr(nodeAddress: NodeAddress): string {
const { address, port } = nodeAddress;

// address can be an IP or a hostname depending on the multiaddr
// We only rewrite when it's our p2p DNS name.
const uploadHost =
typeof address === "string" && address.startsWith("p2p.")
? address.replace(/^p2p\./, "upload.")
: address;

// If the p2p multiaddr is tcp/443/wss, upload should be https on 443
// If you're on some other port locally, keep it consistent.
const isStandardHttps = port === 443 || port === 0 || port == null;

return isStandardHttps ? `https://${uploadHost}` : `https://${uploadHost}:${port}`;
}

export type ProviderInfo = {
accountId: string;
multiaddr: Multiaddr;
pricePerBlock: number;
};
5 changes: 3 additions & 2 deletions src/lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { type Multiaddr, multiaddr } from "@multiformats/multiaddr";
import { fileTypeFromBuffer } from "file-type";
import { CID } from "multiformats";
import type { PolkaStorageApi } from "../GlobalCtx";
import { baseURLFromP2pMultiaddr } from "./conversion";
import type { Deal } from "./deals";

export async function downloadDeal(api: PolkaStorageApi | null, deal: Deal) {
if (!api) throw new Error("API not ready");

// look up provider addr
const maddr = await getProviderMultiaddr(api, deal.value.provider);
const { address, port } = maddr.nodeAddress();
const baseUrl = baseURLFromP2pMultiaddr(maddr.nodeAddress());

// fetch the raw piece
const pieceCid = CID.decode(deal.value.piece_cid.asBytes()).toString();
const res = await fetch(`http://${address}:${port}/api/v0/download/${pieceCid}`);
const res = await fetch(`${baseUrl}/api/v0/download/${pieceCid}`);
if (!res.ok) throw new Error(res.statusText);
const blob = await res.blob();

Expand Down
3 changes: 2 additions & 1 deletion src/lib/fileUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function uploadFile(
body.append("file", file);

const addr = secure_addr ? secure_addr : `http://${address.ip}:${address.port}`;

console.log(`Uploading to: ${addr}`);
return await fetch(`${addr}/api/v0/upload/${dealCid}`, {
method: "PUT",
body,
Expand All @@ -32,6 +32,7 @@ export async function proposeDeal(
}

const addr = secure_addr ? secure_addr : `http://${address.ip}:${address.port}`;
console.log(`Proposing to: ${addr}`);
const response = await fetch(`${addr}/api/v0/propose_deal`, {
method: "POST",
headers: { "Content-Type": "application/json" },
Expand Down
Loading
Loading