@everyprotocol/every-cli 0.1.3 → 0.1.5
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/.every.toml +6 -6
- package/dist/abi.js +1 -0
- package/dist/cmdgen.js +51 -139
- package/dist/cmds/balance.js +43 -0
- package/dist/cmds/config.js +46 -0
- package/dist/cmds/kind.js +14 -0
- package/dist/cmds/matter.js +432 -0
- package/dist/cmds/minter.js +31 -0
- package/dist/cmds/object.js +175 -0
- package/dist/cmds/relation.js +16 -0
- package/dist/cmds/set.js +31 -0
- package/dist/cmds/unique.js +14 -0
- package/dist/cmds/universe.js +21 -0
- package/dist/cmds/value.js +14 -0
- package/dist/{wallet.js → cmds/wallet.js} +19 -19
- package/dist/commander-patch.js +64 -0
- package/dist/config.js +18 -93
- package/dist/ethereum.js +33 -0
- package/dist/from-opts.js +161 -0
- package/dist/index.js +3 -2
- package/dist/logger.js +39 -0
- package/dist/parsers.js +70 -0
- package/dist/program.js +28 -39
- package/dist/substrate.js +24 -18
- package/dist/utils.js +131 -184
- package/package.json +5 -1
- package/dist/cmds.js +0 -132
- package/dist/matter.js +0 -96
- package/dist/mint.js +0 -78
- package/dist/options.js +0 -26
- package/dist/relate.js +0 -104
package/dist/matter.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { ApiPromise, WsProvider } from "@polkadot/api";
|
|
3
|
-
import "@polkadot/api-augment/substrate";
|
|
4
|
-
import * as fs from "fs";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import { getObserverConfig, keystoreFromOptions } from "./utils.js";
|
|
7
|
-
import "./options.js";
|
|
8
|
-
import { findEvent, submitTransaction } from "./substrate.js";
|
|
9
|
-
import JSON5 from "json5";
|
|
10
|
-
function guessContentType(filePath) {
|
|
11
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
12
|
-
switch (ext) {
|
|
13
|
-
case ".txt":
|
|
14
|
-
return "text/plain";
|
|
15
|
-
case ".json":
|
|
16
|
-
return "application/json";
|
|
17
|
-
case ".wasm":
|
|
18
|
-
return "application/wasm";
|
|
19
|
-
case ".jpg":
|
|
20
|
-
case ".jpeg":
|
|
21
|
-
return "image/jpeg";
|
|
22
|
-
case ".png":
|
|
23
|
-
return "image/png";
|
|
24
|
-
default:
|
|
25
|
-
return "application/octet-stream";
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export function genMatterCommand() {
|
|
29
|
-
const cmd = new Command().name("matter").description("manage matters");
|
|
30
|
-
cmd
|
|
31
|
-
.command("register")
|
|
32
|
-
.description("Register matter on the Substrate chain")
|
|
33
|
-
.argument("<files...>", "Path to the file(s) containing the matter content")
|
|
34
|
-
.option("-c, --content-type <type>", "Default content type")
|
|
35
|
-
.option("-h, --hasher <number>", "Default hasher", "1")
|
|
36
|
-
.option("-u, --universe <name>", "Universe name")
|
|
37
|
-
.option("-o, --observer <name>", "Observer name")
|
|
38
|
-
.accountOptions()
|
|
39
|
-
.action(async (files, options) => {
|
|
40
|
-
const materials = [];
|
|
41
|
-
// Process each file argument
|
|
42
|
-
for (const file of files) {
|
|
43
|
-
const [filePath, hasher_, contentType_] = file.split(":");
|
|
44
|
-
const hasher = hasher_ ? Number(hasher_) : Number(options.hasher) || 1;
|
|
45
|
-
const contentType = contentType_ || options.contentType || guessContentType(filePath);
|
|
46
|
-
materials.push({ filePath, hasher, contentType });
|
|
47
|
-
}
|
|
48
|
-
const conf = getObserverConfig(options);
|
|
49
|
-
const keystore = await keystoreFromOptions(options);
|
|
50
|
-
const pair = await keystore.pair();
|
|
51
|
-
// Connect to the Substrate node
|
|
52
|
-
// console.log(`Connecting to ${conf.rpc}...`);
|
|
53
|
-
const provider = new WsProvider(conf.rpc);
|
|
54
|
-
const api = await ApiPromise.create({ provider });
|
|
55
|
-
await api.isReady;
|
|
56
|
-
// console.log("Connected to Substrate node");
|
|
57
|
-
const txns = [];
|
|
58
|
-
// Submit transactions for each material
|
|
59
|
-
for (const { filePath, hasher, contentType } of materials) {
|
|
60
|
-
console.log(`Processing ${filePath}: content-type=${contentType}, hasher=${hasher}`);
|
|
61
|
-
const content = fs.readFileSync(filePath);
|
|
62
|
-
const contentRaw = api.createType("Raw", content, content.length);
|
|
63
|
-
const call = api.tx.every.matterRegister(hasher, contentType, contentRaw);
|
|
64
|
-
console.log(`Submitting transaction for ${filePath}...`);
|
|
65
|
-
const txn = await submitTransaction(api, call, pair);
|
|
66
|
-
console.log(`Transaction submitted: ${txn.txHash}`);
|
|
67
|
-
txns.push({ txn, filePath });
|
|
68
|
-
}
|
|
69
|
-
// Wait for all transactions to be finalized
|
|
70
|
-
for (const { txn, filePath } of txns) {
|
|
71
|
-
console.log(`Waiting for ${filePath} to be finalized...`);
|
|
72
|
-
const receipt = await txn.receipt;
|
|
73
|
-
const event = findEvent(receipt.events, "MaterialAdded");
|
|
74
|
-
if (event) {
|
|
75
|
-
const hash = event.data[0].toString();
|
|
76
|
-
console.log(`${filePath} finalized in block ${receipt.blockHash}`);
|
|
77
|
-
console.log(` Matter hash: ${hash}`);
|
|
78
|
-
if (conf.gateway) {
|
|
79
|
-
console.log(` Preimage: ${conf.gateway}/m/${hash}`);
|
|
80
|
-
}
|
|
81
|
-
if (conf.explorer) {
|
|
82
|
-
// console.log(` Transaction: ${conf.explorer}/extrinsic/${receipt.blockNumber}-${receipt.txIndex}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
console.log(`${filePath} finalized, but no MaterialAdded event found`);
|
|
87
|
-
for (const { event } of receipt.events) {
|
|
88
|
-
console.log(`${event.method.padEnd(20)}`, JSON5.stringify(event.data.toHuman()));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
await api.disconnect();
|
|
93
|
-
console.log("Disconnected from Substrate node");
|
|
94
|
-
});
|
|
95
|
-
return cmd;
|
|
96
|
-
}
|
package/dist/mint.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { defaultWriteFunctionOptions } from "./cmds.js";
|
|
3
|
-
import { getClientsEth, stringify } from "./utils.js";
|
|
4
|
-
import { getUniverseConfig } from "./config.js";
|
|
5
|
-
import { parseEventLogs, parseUnits } from "viem";
|
|
6
|
-
import { abi } from "./abi.js";
|
|
7
|
-
export function genMintCommand() {
|
|
8
|
-
const cmd = new Command()
|
|
9
|
-
.name("mint")
|
|
10
|
-
.description("Mint an object via the object minter or directly from the set")
|
|
11
|
-
.option("--to <address>", "specify the recipient")
|
|
12
|
-
.option("--value <amount>", "the amount of ETH to send together", "0")
|
|
13
|
-
.option("--auth <data>", "authorization data for a permissioned mint", "0x")
|
|
14
|
-
.option("--policy <index>", "the index number of the mint policy", "0")
|
|
15
|
-
.option("--no-minter", "mint directly from set contract instead of using ObjectMinter")
|
|
16
|
-
.argument("<sid>", "scoped object ID, in form of set.id (e.g., 17.1)")
|
|
17
|
-
.argument("[data]", "additional input data", "0x")
|
|
18
|
-
.action(action);
|
|
19
|
-
defaultWriteFunctionOptions().forEach((option) => cmd.addOption(option));
|
|
20
|
-
return cmd;
|
|
21
|
-
}
|
|
22
|
-
async function action() {
|
|
23
|
-
const opts = this.opts();
|
|
24
|
-
const args0 = this.args;
|
|
25
|
-
const conf = getUniverseConfig(opts);
|
|
26
|
-
const setRegistry = conf.contracts["SetRegistry"];
|
|
27
|
-
const { publicClient, walletClient } = await getClientsEth(conf, opts);
|
|
28
|
-
const account = walletClient.account;
|
|
29
|
-
const [set, id] = args0[0].split(".");
|
|
30
|
-
const setContract = (await publicClient.readContract({
|
|
31
|
-
address: setRegistry,
|
|
32
|
-
abi: abi.setContract,
|
|
33
|
-
functionName: "setContract",
|
|
34
|
-
args: [BigInt(set)],
|
|
35
|
-
}));
|
|
36
|
-
const value = parseUnits(opts.value || "0", 18);
|
|
37
|
-
// Use the provided recipient address or default to the sender's address
|
|
38
|
-
const recipientAddress = (opts.to || account.address);
|
|
39
|
-
const mintData = (args0[1] || "0x");
|
|
40
|
-
let hash;
|
|
41
|
-
if (opts.minter) {
|
|
42
|
-
// Mint via ObjectMinter
|
|
43
|
-
const objectMinter = conf.contracts["ObjectMinter"];
|
|
44
|
-
const { request } = await publicClient.simulateContract({
|
|
45
|
-
address: objectMinter,
|
|
46
|
-
abi: abi.mint,
|
|
47
|
-
functionName: "mint",
|
|
48
|
-
args: [recipientAddress, setContract, BigInt(id), mintData, opts.auth || "0x", Number(opts.policy || "0")],
|
|
49
|
-
account,
|
|
50
|
-
value,
|
|
51
|
-
});
|
|
52
|
-
hash = await walletClient.writeContract(request);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// Mint directly from set contract
|
|
56
|
-
const { request } = await publicClient.simulateContract({
|
|
57
|
-
address: setContract,
|
|
58
|
-
abi: abi.create,
|
|
59
|
-
functionName: "create",
|
|
60
|
-
args: [recipientAddress, BigInt(id), mintData],
|
|
61
|
-
account,
|
|
62
|
-
value,
|
|
63
|
-
});
|
|
64
|
-
hash = await walletClient.writeContract(request);
|
|
65
|
-
}
|
|
66
|
-
console.log(`Transaction sent: ${hash}`);
|
|
67
|
-
console.log("Transaction mining...");
|
|
68
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
69
|
-
console.log("Transaction mined");
|
|
70
|
-
if (receipt.logs && receipt.logs.length > 0) {
|
|
71
|
-
const abiToUse = opts.minter ? abi.mint : abi.create;
|
|
72
|
-
const parsedLogs = parseEventLogs({ abi: abiToUse, logs: receipt.logs });
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
|
-
parsedLogs.forEach((log) => {
|
|
75
|
-
console.log(" - Event", log.eventName, stringify(log.args));
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
package/dist/options.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Command, Option } from "commander";
|
|
2
|
-
export const optRpcUrl = new Option("--rpc-url <url>", "RPC endpoint URL");
|
|
3
|
-
export const optChainId = new Option("--chain-id <id>", "Chain ID").argParser(Number);
|
|
4
|
-
export const optPkey = new Option("--private-key <hex>", "Sender private key");
|
|
5
|
-
export const optFrom = new Option("--from <address>", "Sender address");
|
|
6
|
-
export const optDerivePath = new Option("--path <hd>", "Derivation path (HD)");
|
|
7
|
-
export const optVerbose = new Option("-v, --verbose", "Enable verbose logging");
|
|
8
|
-
export const optSilent = new Option("--silent", "Suppress output");
|
|
9
|
-
export const optAccount = new Option("-a, --account <account>", "Name of the keystore");
|
|
10
|
-
export const optPassword = new Option("-p, --password [password]", "Password to decrypt the keystore");
|
|
11
|
-
export const optPasswordFile = new Option("--password-file <file>", "File containing the keystore password");
|
|
12
|
-
export const optFoundry = new Option("-f, --foundry", "use foundry keystores (~/.foundry/keystores)");
|
|
13
|
-
export const accountOptions = [optAccount, optPassword, optPasswordFile, optFoundry];
|
|
14
|
-
Command.prototype.useOptions = function (options) {
|
|
15
|
-
options.forEach((o) => this.addOption(o));
|
|
16
|
-
return this;
|
|
17
|
-
};
|
|
18
|
-
// (Command.prototype as unknown as Command).networkOptions = function () {
|
|
19
|
-
// return (this as Command).useOptions(networkGroup);
|
|
20
|
-
// };
|
|
21
|
-
Command.prototype.accountOptions = function () {
|
|
22
|
-
return this.useOptions(accountOptions);
|
|
23
|
-
};
|
|
24
|
-
// (Command.prototype as unknown as Command).commonOptions = function () {
|
|
25
|
-
// return (this as Command).useOptions(commonGroup);
|
|
26
|
-
// };
|
package/dist/relate.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { defaultWriteFunctionOptions } from "./cmds.js";
|
|
3
|
-
import { getClientsEth, stringify } from "./utils.js";
|
|
4
|
-
import { getUniverseConfig } from "./config.js";
|
|
5
|
-
import { parseEventLogs } from "viem";
|
|
6
|
-
import { abi } from "./abi.js";
|
|
7
|
-
export function genRelateCommand() {
|
|
8
|
-
const cmd = new Command()
|
|
9
|
-
.name("relate")
|
|
10
|
-
.description("Link a tail object to a head object through a relation")
|
|
11
|
-
.argument("<tail>", "tail node, in form of [[data.]grant.]set.id")
|
|
12
|
-
.argument("<rel>", "relation ID")
|
|
13
|
-
.argument("<head>", "head node in form of [grant.]set.id, ")
|
|
14
|
-
.action(async function () {
|
|
15
|
-
await action(this, "relate");
|
|
16
|
-
});
|
|
17
|
-
defaultWriteFunctionOptions().forEach((option) => cmd.addOption(option));
|
|
18
|
-
return cmd;
|
|
19
|
-
}
|
|
20
|
-
export function genUnrelateCommand() {
|
|
21
|
-
const cmd = new Command()
|
|
22
|
-
.name("unrelate")
|
|
23
|
-
.description("Unlinks a tail object from a head object")
|
|
24
|
-
.argument("<tail>", "tail node, in form of [[data.]grant.]set.id")
|
|
25
|
-
.argument("<rel>", "relation ID")
|
|
26
|
-
.argument("<head>", "head node in form of [grant.]set.id, ")
|
|
27
|
-
.action(async function () {
|
|
28
|
-
await action(this, "unrelate");
|
|
29
|
-
});
|
|
30
|
-
defaultWriteFunctionOptions().forEach((option) => cmd.addOption(option));
|
|
31
|
-
return cmd;
|
|
32
|
-
}
|
|
33
|
-
async function action(cmd, functionName) {
|
|
34
|
-
const opts = cmd.opts();
|
|
35
|
-
const args0 = cmd.args;
|
|
36
|
-
const conf = getUniverseConfig(opts);
|
|
37
|
-
const address = conf.contracts["OmniRegistry"];
|
|
38
|
-
const tail = parseNode4(args0[0]);
|
|
39
|
-
const rel = BigInt(args0[1]);
|
|
40
|
-
const head = parseNode3(args0[2]);
|
|
41
|
-
await sendTransaction(conf, opts, address, abi.relation, functionName, [tail, rel, head]);
|
|
42
|
-
}
|
|
43
|
-
async function sendTransaction(conf, opts, address, abi /* eslint-disable-line @typescript-eslint/no-explicit-any*/, functionName, args /* eslint-disable-line @typescript-eslint/no-explicit-any*/) {
|
|
44
|
-
const { publicClient, walletClient } = await getClientsEth(conf, opts);
|
|
45
|
-
const { request } = await publicClient.simulateContract({
|
|
46
|
-
address,
|
|
47
|
-
abi,
|
|
48
|
-
functionName: "relate",
|
|
49
|
-
args,
|
|
50
|
-
account: walletClient.account,
|
|
51
|
-
});
|
|
52
|
-
const hash = await walletClient.writeContract(request);
|
|
53
|
-
console.log(`Transaction sent: ${hash}`);
|
|
54
|
-
console.log("Transaction mining...");
|
|
55
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
56
|
-
console.log("Transaction mined");
|
|
57
|
-
if (receipt.logs && receipt.logs.length > 0) {
|
|
58
|
-
const parsedLogs = parseEventLogs({ abi: abi.relation, logs: receipt.logs });
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
parsedLogs.forEach((log) => {
|
|
61
|
-
console.log(" - Event", log.eventName, stringify(log.args));
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function parseNode4(arg) {
|
|
66
|
-
const parts = arg.split(".");
|
|
67
|
-
let [data, grant, set, id] = [0n, 0n, 0n, 0n];
|
|
68
|
-
if (parts.length == 2) {
|
|
69
|
-
set = BigInt(parts[0]);
|
|
70
|
-
id = BigInt(parts[1]);
|
|
71
|
-
}
|
|
72
|
-
else if (parts.length == 3) {
|
|
73
|
-
grant = BigInt(parts[0]);
|
|
74
|
-
set = BigInt(parts[1]);
|
|
75
|
-
id = BigInt(parts[2]);
|
|
76
|
-
}
|
|
77
|
-
else if (parts.length == 4) {
|
|
78
|
-
data = BigInt(parts[0]);
|
|
79
|
-
grant = BigInt(parts[1]);
|
|
80
|
-
set = BigInt(parts[2]);
|
|
81
|
-
id = BigInt(parts[3]);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
throw new Error("");
|
|
85
|
-
}
|
|
86
|
-
return (data << 192n) | (grant << 128n) | (set << 64n) | id;
|
|
87
|
-
}
|
|
88
|
-
function parseNode3(arg) {
|
|
89
|
-
const parts = arg.split(".");
|
|
90
|
-
let [grant, set, id] = [0n, 0n, 0n];
|
|
91
|
-
if (parts.length == 2) {
|
|
92
|
-
set = BigInt(parts[0]);
|
|
93
|
-
id = BigInt(parts[1]);
|
|
94
|
-
}
|
|
95
|
-
else if (parts.length == 3) {
|
|
96
|
-
grant = BigInt(parts[0]);
|
|
97
|
-
set = BigInt(parts[1]);
|
|
98
|
-
id = BigInt(parts[2]);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
throw new Error("");
|
|
102
|
-
}
|
|
103
|
-
return (grant << 128n) | (set << 64n) | id;
|
|
104
|
-
}
|