forked from permaweb/ao-localnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(seed): rework almost all seed scripts
- Loading branch information
1 parent
150e9e1
commit 8c78bb7
Showing
15 changed files
with
104 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* | ||
!/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# extras | ||
|
||
Some seed scripts may write intermediate data files into this folder. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env node | ||
|
||
import { readFile } from 'node:fs/promises' | ||
|
||
import { instance as arweave } from './utils/arweave.mjs' | ||
|
||
const wallet = JSON.parse(await readFile(import.meta.resolve('../wallets/scheduler-location-publisher-wallet.json').slice(7), 'utf8')) | ||
const address = await arweave.wallets.getAddress(wallet) | ||
|
||
console.log('address', address) | ||
|
||
const tx = await arweave.createTransaction( | ||
{ | ||
data: Math.random.toString().slice(-4), | ||
tags: [ | ||
{ | ||
name: 'Data-Protocol', | ||
value: 'ao', | ||
}, | ||
{ | ||
name: 'Type', | ||
value: 'Scheduler-Location', | ||
}, | ||
{ | ||
name: 'Variant', | ||
value: 'ao.LN.1', | ||
}, | ||
{ | ||
name: 'URL', | ||
value: 'http://localhost:4003', | ||
}, | ||
{ | ||
name: 'Time-To-Live', | ||
value: '86400', | ||
}, | ||
].map(({ name, value }) => ({ | ||
name: Buffer.from(name).toString('base64'), | ||
value: Buffer.from(value).toString('base64'), | ||
})), | ||
}, | ||
) | ||
|
||
await arweave.transactions.sign(tx, wallet) | ||
|
||
console.log(tx) | ||
|
||
const res = await arweave.transactions.post(tx) | ||
|
||
console.log(`${res.status} ${res.statusText}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/package.json | ||
|
||
/package-lock.json | ||
/pnpm-lock.yaml | ||
/yarn.lock | ||
|
||
/drive.json | ||
/wallet.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import safeImport from './safeImport.mjs' | ||
const { arDriveFactory, JWKWallet } = await safeImport('ardrive-core-js') | ||
|
||
import { instance as arweave } from './arweave.mjs' | ||
import { loadWallet } from './loadWallet.mjs' | ||
|
||
export const arDrive = arDriveFactory({ | ||
arweave, | ||
wallet: new JWKWallet(await loadWallet()), | ||
// TODO: should we be using the turbo service? | ||
// turboSettings: { | ||
// turboUrl: 'http://localhost:4005', | ||
// } | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { readFile } from 'node:fs/promises' | ||
import { dirname, join } from 'node:path' | ||
|
||
export async function loadWallet () { | ||
const json = await readFile('wallet.json', 'utf-8') | ||
export async function loadWallet (filename = 'user-wallet.json') { | ||
const __dirname = dirname(import.meta.url.slice(7)) | ||
const userWalletFile = join(__dirname, '..', '..', 'wallets', filename) | ||
const json = await readFile(userWalletFile, 'utf-8') | ||
return JSON.parse(json) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { execFileSync } from 'node:child_process' | ||
import { dirname } from 'node:path' | ||
|
||
export default async function safeImport (module) { | ||
try { | ||
return await import(module); | ||
} catch (e) { | ||
console.log(`Installing '${module}' from npm...`) | ||
execFileSync('npm', ['install', module], { | ||
cwd: dirname(import.meta.url).slice(7), | ||
encoding: 'utf-8', | ||
}) | ||
console.log(`Installed '${module}'.`) | ||
return await import(module); | ||
} | ||
} |