-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrap_by_payload.ts
More file actions
75 lines (69 loc) · 2.07 KB
/
Copy pathscrap_by_payload.ts
File metadata and controls
75 lines (69 loc) · 2.07 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
import "./env";
import assert from "assert";
import fs from "fs";
import { MetalSeal, MetalServiceV2, SymbolService } from "metal-on-symbol";
import mime from "mime";
import { Account, MetadataType, MosaicId, NamespaceId, NetworkType, PublicAccount } from "symbol-sdk";
// Edit here -------------
const nodeUrl = process.env.TEST_NODE_URL;
const privateKey = process.env.TEST_PRIVATE_KEY; // The account will be signer/source/target
const payloadFilePath = process.argv[2];
let text = process.argv[3];
// -----------------------
assert(payloadFilePath);
const payload = fs.readFileSync(payloadFilePath);
text = text ?? new MetalSeal(payload.length, mime.getType(payloadFilePath) ?? undefined).stringify();
assert(nodeUrl);
const symbolService = new SymbolService({ node_url: nodeUrl });
const metalService = new MetalServiceV2(symbolService);
assert(privateKey);
const signerAccount = Account.createFromPrivateKey(privateKey, NetworkType.TEST_NET);
const destroyMetal = async (
type: MetadataType,
sourcePubAccount: PublicAccount,
targetPubAccount: PublicAccount,
targetId: undefined | MosaicId | NamespaceId,
payload: Uint8Array,
additive: number,
text: string,
signerAccount: Account,
cosignerAccounts: Account[]
) => {
const txs = await metalService.createDestroyTxs(
type,
sourcePubAccount,
targetPubAccount,
targetId,
payload,
additive,
text,
);
if (!txs) {
throw Error("Transaction creation error.");
}
const batches = await symbolService.buildSignedAggregateCompleteTxBatches(
txs,
signerAccount,
cosignerAccounts,
);
const errors = await symbolService.executeBatches(batches, signerAccount);
if (errors) {
throw Error("Transaction error.");
}
};
destroyMetal(
MetadataType.Account,
signerAccount.publicAccount,
signerAccount.publicAccount,
undefined,
payload,
0,
text,
signerAccount,
[]
).then(() => {
console.log(`Scrapped!`);
}).catch((e) => {
console.error(e);
process.exit(1);
});