forked from MattyIce/postpromoter
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcreate_account.js
71 lines (66 loc) · 2.01 KB
/
create_account.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
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
const dsteem = require('@hiveio/dhive')
const steem = require('@hiveio/hive-js');
const fs = require('fs')
const config = JSON.parse(fs.readFileSync('./config.json'))
const client = new dsteem.Client('https://anyx.io')
var wallet = JSON.parse(fs.readFileSync("wallet.json"));
const active_key = dsteem.PrivateKey.fromString(wallet.acc_creating_account.active)
var utils = require('./utils.js')
//TODO: pass client as argument or as module export
async function createAccount(wordsArray) {
let newAccount = wordsArray[1]
let ownerPubKey, activePubKey, postingPubKey, memoPubKey
//create keys for new account
if (wordsArray.length == 6) {
ownerPubKey = wordsArray[2]
activePubKey = wordsArray[3]
postingPubKey = wordsArray[4]
memoPubKey = wordsArray[5]
} else {
ownerPubKey = wordsArray[2]
activePubKey = wordsArray[2]
postingPubKey = wordsArray[2]
memoPubKey = wordsArray[2]
}
const ownerAuth = {
weight_threshold: 1,
account_auths: [],
key_auths: [[ownerPubKey, 1]],
}
const activeAuth = {
weight_threshold: 1,
account_auths: [],
key_auths: [[activePubKey, 1]],
}
const postingAuth = {
weight_threshold: 1,
account_auths: [],
key_auths: [[memoPubKey, 1]],
}
// then create discounted account operation
const create_op = [
'create_claimed_account',
{
creator: wallet.acc_creating_account.name,
new_account_name: newAccount,
owner: ownerAuth,
active: activeAuth,
posting: postingAuth,
memo_key: memoPubKey,
json_metadata: '',
extensions: [],
}
]
//check if account exists
var _account = await client.database.call('get_accounts', [[newAccount]])
//account not available to register
if (_account.length > 0) {
throw new Error('account name already taken')
} else {
utils.log('account is available')
return client.broadcast.sendOperations([create_op], active_key)
}
}
module.exports = {
createAccount: createAccount
}