-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbles_meta_set_pending_admin.js
More file actions
123 lines (119 loc) · 3.83 KB
/
bles_meta_set_pending_admin.js
File metadata and controls
123 lines (119 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const { Command, Argument } = require("commander");
const chalk = require("chalk");
const { WALLET_PATH } = require("../../lib/constants");
const {
getBlsContractClient,
getPath,
readKeypair,
bs58Message,
} = require("../utils");
const { PublicKey } = require("@solana/web3.js");
const blessMetaSetPendingAdminCommand = new Command("pending-admin")
.option(
"--cluster <cluster>",
"solana cluster: mainnet, testnet, devnet, localnet, <custom>",
)
.option(
"--programId <programId>",
"Program ID: Specify the program ID when working on devnet, testnet, or localnet; it will not work on mainnet.",
)
.option(
"--signer <signer>",
"signer: the signer is the payer of the bless meta, default: " +
WALLET_PATH,
)
.option(
"--admin <admin>",
"admin: the admin of the bless meta, default: " + WALLET_PATH,
)
.option(
"--squads <true/false>",
"squads: if true, use Squads to sign the transaction; default: false.",
)
.description(
"pending-admin: set the pending admin of the bless meta, the value is base58",
);
const mint = new Argument("mint", "mint: the public key of the mint token");
mint.required = true;
const pending = new Argument(
"pending-admin",
"pending-admin: the pending admin of the bless meta",
);
pending.required = true;
blessMetaSetPendingAdminCommand
.addArgument(mint)
.addArgument(pending)
.action(async (mint, pending, options) => {
options.cluster = options.cluster || "localnet";
options.signer = options.signer || getPath(WALLET_PATH);
options.squads = options.squads || false;
try {
const keypair = readKeypair(options.signer);
const client = getBlsContractClient(
options.cluster,
keypair,
options.programId,
);
let pendingAdmin = new PublicKey(pending);
let mintPubkey = new PublicKey(mint);
const state =
await client.blessTokenClient.getBlessTokenMetaState(mintPubkey);
if (options.squads) {
if (options.admin == null) {
console.log(chalk.red("admin is required."));
process.exit(1);
}
const adminPubkey = new PublicKey(options.admin);
if (state.admin.toBase58() != adminPubkey.toBase58()) {
console.log(
chalk.red(
"set pending admin is denied, admin is not matched, the state admin is " +
state.admin.toBase58(),
),
);
process.exit(1);
}
const tx = await client.blessTokenClient.getSetPendingAdminAccountTx(
mintPubkey,
adminPubkey,
pendingAdmin,
{ signer: adminPubkey },
);
const itx = await bs58Message(
client.connection,
tx.instructions,
keypair,
);
console.log(
"bless meta set pending admin transaction created: \n" + itx,
);
} else {
options.admin = options.admin || getPath(WALLET_PATH);
const adminKeypair = readKeypair(options.admin);
if (state.admin.toBase58() != adminKeypair.publicKey.toBase58()) {
console.log(
chalk.red(
"set pending admin is denied, admin is not matched, the state admin is " +
state.admin.toBase58(),
),
);
process.exit(1);
}
await client.blessTokenClient.setPendingAdminAccount(
mintPubkey,
adminKeypair.publicKey,
pendingAdmin,
{
signer: keypair.publicKey,
signerKeypair: [keypair, adminKeypair],
},
);
}
console.log(chalk.green("bless meta set pending admin success."));
process.exit(0);
} catch (e) {
console.log(chalk.red("bless meta set the pending admin failed: " + e));
process.exit(1);
}
});
module.exports = blessMetaSetPendingAdminCommand;