-
Notifications
You must be signed in to change notification settings - Fork 1
/
blox-account.js
115 lines (108 loc) · 3.4 KB
/
blox-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
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
import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
/**
* `blox-account`
* Creates an account on the EOS blockchain
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class BloxAccount extends PolymerElement {
static get template() {
return html`
<style>
:host {
display: block;
}
</style>
`;
}
static get properties() {
return {
eos: {
type: Object,
},
creator: {
type: String,
},
name: {
type: String,
},
owner: {
type: String,
},
active: {
type: String,
}
};
}
exists(eos, accountName){
return new Promise((resolve, reject) => {
if(eos && accountName){
eos.getAccount(accountName)
.then((response) => {
resolve(true);
})
.catch((err) => {
resolve(false);
})
} else {
reject('Missing Arguments');
}
})
}
_makeAccount(){
if(this.eos && this.owner && this.active && this.creator && this.name){
this.makeAccount(this.eos, this.creator, this.name, this.owner, this.active)
}
}
// CREATOR the acocunt name of the creator 12 charectors
// NAME is the new account name yoiu want to register 12 charectors
// OWNER is the public key for the owner account
// ACTIVE is the public key for the active account
makeAccount(eos, creator, name, owner, active, bytesIn, stakeNetQuantityIn, stakeCpuQuantityIn, transferIn) {
return new Promise((resolve, reject) => {
//stakeNetQuantityIn += (netCountDecimal[1].length === 0 ? "." : "") + "0".repeat(4 - netCountDecimal[1].length)
var netCountDecimal = stakeNetQuantityIn.split(".");
if(netCountDecimal[1].length === 0){
stakeNetQuantityIn = stakeNetQuantityIn+'.0000'
} else if (netCountDecimal[1].length === 1){
stakeNetQuantityIn = stakeNetQuantityIn+'000'
} else if (netCountDecimal[1].length === 2){
stakeNetQuantityIn = stakeNetQuantityIn+'00'
} else if (netCountDecimal[1].length === 3){
stakeNetQuantityIn = stakeNetQuantityIn+'0'
}
var cpuCountDecimal = stakeCpuQuantityIn.split(".");
if(cpuCountDecimal[1].length === 0){
stakeCpuQuantityIn = stakeCpuQuantityIn+'.0000'
} else if (cpuCountDecimal[1].length === 1){
stakeCpuQuantityIn = stakeCpuQuantityIn+'000'
} else if (cpuCountDecimal[1].length === 2){
stakeCpuQuantityIn = stakeCpuQuantityIn+'00'
} else if (cpuCountDecimal[1].length === 3){
stakeCpuQuantityIn = stakeCpuQuantityIn+'0'
}
const bytes = parseInt(bytesIn) || 7000;
const stake_net_quantity = stakeNetQuantityIn +' EOS' ||'0.1000 EOS';
const stake_cpu_quantity = stakeCpuQuantityIn +' EOS' || '0.2000 EOS';
const transfer = parseInt(transferIn) || 0;
console.log(creator)
console.log(name)
console.log(stake_net_quantity)
console.log(stake_cpu_quantity)
console.log(transfer)
eos.transaction(tr => {
tr.newaccount(creator, name, owner, active)
tr.buyrambytes(creator, name, bytes)
tr.delegatebw(creator, name, stake_net_quantity, stake_cpu_quantity, transfer)
})
.then((response) => {
resolve(response.transaction_id)
})
.catch((err) => {
reject(err)
})
})
}
} window.customElements.define('blox-account', BloxAccount);