-
Notifications
You must be signed in to change notification settings - Fork 0
/
flat.js
37 lines (31 loc) · 995 Bytes
/
flat.js
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
/*******************************************************************************
* flat.js demo
*/
const accountNamespace = require("../flat.js")
const account = require("./account.js")
/// Parse
const base64ToUtf8 = x => Buffer.from(x, "base64").toString("utf8")
const dataAttr = accountNamespace.read(account, base64ToUtf8)
console.log(dataAttr)
console.log()
/// Iterate
for (let key in dataAttr) {
if (!key.match(/^wallet./)) continue
console.log(key.substr(7) + ": " + dataAttr[key])
}
console.log()
/// Get scope object
const scope = {}
for (let key in dataAttr) {
if (key.match(/^conf.multisig./)) scope[key.substr(14)] = dataAttr[key]
}
console.log(scope)
/// Rewrite scope
for (let key in dataAttr) {
if (key.match(/^conf\.multisig/)) delete dataAttr[key]
}
dataAttr["conf.multisig.collector"] = "https://example.org/.well_known/multisig.toml"
console.log()
/// Write changes on the legder
const tx = accountNamespace.write(account, dataAttr)
console.log(tx.operations)