-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwallet.js
More file actions
171 lines (152 loc) · 5.01 KB
/
Copy pathwallet.js
File metadata and controls
171 lines (152 loc) · 5.01 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const { exec } = require("child_process");
var path = require('path');
const serverStatus = function (body) {
let myPromise = new Promise(function (myResolve, myReject) {
exec("./cli-wallet server-status", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
myReject();
}
if (stderr) {
console.log(`stderr: ${stderr}`);
myReject();
}
console.log(`stdout: ${stdout}`);
myResolve(stdout);
});
});
return myPromise
}
function sendAsset(color, address) {
let myPromise = new Promise(function (myResolve, myReject) {
console.log("send asset:", color, address)
let command = `./cli-wallet send-funds -color ${color} -amount 1337 -dest-addr ${address}`
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
myReject();
}
if (stderr) {
console.log(`stderr: ${stderr}`);
myReject();
}
myResolve(stdout);
});
});
return myPromise
}
function sendNft(id, address) {
let myPromise = new Promise(function (myResolve, myReject) {
console.log("nft asset:", id, address)
let command = `./cli-wallet transfer-nft -id ${id} -dest-addr ${address}`
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
myReject();
}
if (stderr) {
console.log(`stderr: ${stderr}`);
myReject();
}
myResolve(stdout);
});
});
return myPromise
}
function mintNft(img_link) {
let myPromise = new Promise(function (myResolve, myReject) {
console.log("create nft for image:", img_link)
let nft_metadate = {
"title": "Asset Metadata",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "MyFirstNFT"
},
"description": {
"type": "string",
"description": "My very first NFT that has this metadata attached to it."
},
"image": {
"type": "string",
"description": img_link
}
}
}
var fs = require('fs');
const callbackFunction = function(err, test) {
console.log("err", err)
console.log("test", test)
}
let image_path = "./nfts/" + Date.now() + ".json"
fs.writeFile(image_path, JSON.stringify(nft_metadate), callbackFunction)
let command = `./cli-wallet create-nft -immutable-data ${image_path}`
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
myReject();
}
if (stderr) {
console.log(`stderr: ${stderr}`);
myReject();
}
myResolve(stdout);
});
});
return myPromise
}
function mintNftCert(vc) {
let myPromise = new Promise(function (myResolve, myReject) {
console.log("create nft for vc:", vc)
let nft_metadate = {
"title": "Asset Metadata",
"type": "object",
"properties": {
"vc": vc
}
}
var fs = require('fs');
const callbackFunction = function(err, test) {
console.log("err", err)
console.log("test", test)
}
let image_path = "./certs/" + Date.now() + ".json"
fs.writeFile(image_path, JSON.stringify(nft_metadate), callbackFunction)
let command = `./cli-wallet create-nft -immutable-data ${image_path}`
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
myReject();
}
if (stderr) {
console.log(`stderr: ${stderr}`);
myReject();
}
myResolve(stdout);
});
});
return myPromise
}
// create an asset in the form of colored coins
function mintAsset(name, symbol) {
let myPromise = new Promise(function (myResolve, myReject) {
let command = `src/plugins/nft/cli-wallet create-asset -amount 1 -name ${name}`
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
myReject();
}
if (stderr) {
console.log(`stderr: ${stderr}`);
myReject();
}
console.log(`stdout: ${stdout}`);
myResolve(stdout);
});
});
return myPromise
}
module.exports = {
serverStatus, sendAsset, mintNft, mintNftCert, sendNft
}