-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconnection.js
More file actions
183 lines (165 loc) · 4.4 KB
/
connection.js
File metadata and controls
183 lines (165 loc) · 4.4 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
172
173
174
175
176
177
178
179
180
181
182
183
"use strict";
const assert = require('assert');
var address1;
var issuedata;
var listassets;
var totalbalance;
var listwallettransactions;
const connection = {
port: "yourport",
host: '127.0.0.1',
user: "multichainrpc",
pass: "yourpass"
}
const bluebird = require("bluebird");
console.log("Connecting....")
const multichain = bluebird.promisifyAll(require("../index.js")(connection), {suffix: "Method"});
console.log("***********Connection established*********")
function getInfo(req,resp) {
console.log("Calling Get info Method...");
// return true;
multichain.getInfo((err, res) => {
console.log(res);
})
}
//list all assets method
/* function listAssets(req,resp)
{
console.log("Calling List Assets Method...");
// return true;
multichain.listAssetsMethod()
.then (listassetsresp => {
assert(listassetsresp , "Could not get new address")
listassets=listassetsresp ;
console.log(listassets);
})
} */
//Get new address and validate it
/* function getNewVarifiedaddress()
{
console.log("Calling Get New Address Method...");
multichain.getNewAddressMethod()
.then(address => {
assert(address, "Could not get new address")
address1 = address;
console.log(address1)
return multichain.validateAddressMethod({address: address1})
})
} */
function getTotalBalance()
{
multichain.getTotalBalancesMethod({minconf: 1})
.then (totalbalanceresp => {
assert(totalbalanceresp, "Could not get new address")
totalbalance=totalbalanceresp;
console.log(totalbalance);
})
}
/* function listWalletTransactions()
{
multichain.listWalletTransactionsMethod({count: 10})
.then(wallettransresp => {
assert(wallettransresp, "Could not wallet transactions")
listwallettransactions=wallettransresp;
console.log(listwallettransactions);
})
} */
// issue Assets
/* function createAssets ()
{
console.log("Calling Issue Assets Method...");
multichain.issueMethod(
issuedata = {
address: "133H9FFJ9Uhbivv97QZgHTDzQh1D2e8YPCMvmv",
asset: { name: "ashish2",open: true },
qty: 1000,
units: 0.1
}, (err, res) => {
console.log('Txn id of Block is : ' +res)
})
} */
/* function sendAssets ()
{
console.log("Calling Send Assets Method...");
multichain.sendAssetFromMethod({
from: "1bWzkMJ6cicQjDA4yi86favKX15tmJy1dkEGBP",
to: "1bWzkMJ6cicQjDA4yi86favKX15tmJy1dkEGBP",
asset: "asset_chk1",
qty: 10
},(err, res) => {
console.log('Txn id of Block is : ' +res)
console.log(err);
})
} */
/* function sendAssetswithdata ()
{
console.log("Calling Send Assets Method...");
multichain.sendWithMetadataFromMethod({
from: "1bWzkMJ6cicQjDA4yi86favKX15tmJy1dkEGBP",
to: "1E3d1Zs9JBLPPU8oqPvs7fMwXSxmjb81LLU8JA",
//1bK2FjwY3kUhVj4wxDf1M1pqZgczufmVd1cUKF
amount: {"asset_chk1":10},
data: new Buffer("a nice message, for you").toString("hex")
},(err, res) => {
console.log('Txn id of Block is : ' +res)
})
} */
/* {
"from":"hgj",
"to":"hgjh",
"amount":"hgmn:67",
"data":"gjh"
} */
/* {
"from":"1bWzkMJ6cicQjDA4yi86favKX15tmJy1dkEGBP",
"to":"1bK2FjwY3kUhVj4wxDf1M1pqZgczufmVd1cUKF",
"amount":"asset_chk1:10",
"data":"pli"
} */
/* function grantAddress()
{
console.log("Calling Grant Method...");
multichain.grantMethod({
addresses: "1VL98y8Dgyrd7syQa34wzjtDU8jRkrxDaYuzax",
permissions: "send"
})
} */
/* function issueAssets(data)
{
multichain.getNewAddressMethod()
.then(address => {
assert(address, "Could not get new address")
address1 = address;
return multichain.validateAddressMethod({address: address1})
})
.then(privateKey => {
assert(privateKey)
return multichain.grantMethod({
addresses: address1,
permissions: "send,receive,issue,admin"
})
})
.then(revokeTxid => {
assert(revokeTxid);
console.log("Issue Asset Started")
return multichain.issueMethod(
issuedata = {
address: address1,
asset: { name: "test1",open: true },
qty: 1000,
units: 0.1
}, (err, res) => {
console.log('Txn id of Block is : ' +res)
})
})
} */
getInfo()
/* createAssets() */
/* getNewVarifiedaddress() */
/* issueAssets () */
//listAssets()
/* grantAddress() */
//sendAssets ()
/* sendAssetswithdata() */
getTotalBalance()
/* listWalletTransactions() */