forked from unicitynetwork/state-transition-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenpool.js
More file actions
43 lines (33 loc) · 907 Bytes
/
tokenpool.js
File metadata and controls
43 lines (33 loc) · 907 Bytes
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
"use strict"
const { getPubKey } = require('@unicitylabs/shared');
class TokenPool {
constructor(){
this.tokens = {};
this.pointers = {};
}
addPointer(pointer, nonce){
return this.pointers['_'+pointer] = nonce;
}
getNonce(pointer){
return this.pointers['_'+pointer];
}
addToken(secret, txfJson){
const pubkey = getPubKey(secret);
if(!this.tokens['_'+pubkey])this.tokens['_'+pubkey] = {};
const txf = JSON.parse(txfJson);
return this.tokens['_'+pubkey]['_'+txf.token.tokenId] = txfJson;
}
deleteToken(secret, tokenId){
const pubkey = getPubKey(secret);
delete this.tokens['_'+pubkey]['_'+tokenId];
}
getToken(secret, tokenId){
const pubkey = getPubKey(secret);
return this.tokens['_'+pubkey]['_'+tokenId];
}
getTokens(secret){
const pubkey = getPubKey(secret);
return this.tokens['_'+pubkey];
}
}
module.exports = { TokenPool }