-
Notifications
You must be signed in to change notification settings - Fork 8
/
stellar.ts
159 lines (129 loc) · 4.15 KB
/
stellar.ts
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
import {
BlockchainDeleteModel,
BlockchainGetModel,
BlockchainSignModel,
StellarWalletBalanceByAddressModel,
StellarWalletCreateModel,
StellarWalletInitModel,
StellarWalletTransferModel,
} from "../src";
import { getClient } from "./client_loader";
import { log } from "./utils";
async function create(client, account) {
const res = await client.stellar.create(account);
log("================= Creating account =================");
log(res);
log("================= Creating account =================");
return res;
}
async function init(client, account) {
const res = await client.stellar.init(account);
log("================= Initializing account =================");
log(res);
log("================= Initializing account =================");
}
async function list(client) {
const res = await client.stellar.list();
log("================= Listing account =================");
log(res);
log("================= Listing account =================");
}
async function exist(client, account) {
const res = await client.stellar.exist(account);
log("================= Checking account =================");
log(res);
log("================= Checking account =================");
}
async function get(client, account) {
const res = await client.stellar.get(account);
log("================= Getting account =================");
log(res);
log("================= Getting account =================");
return res;
}
async function balanceByAddress(client, address) {
const res = await client.stellar.balance_by_address(address);
log("================= Getting balance =================");
log(res);
log("================= Getting balance =================");
}
async function assets(client, account) {
const res = await client.stellar.assets(account);
log("================= Getting assets =================");
log(res);
log("================= Getting assets =================");
}
async function sign(client, message) {
const res = await client.stellar.sign(message);
log("================= Signing message =================");
log(res);
log("================= Signing message =================");
}
async function pay(client, payment) {
const res = await client.stellar.pay(payment);
log("================= Paying =================");
log(res);
log("================= Paying =================");
}
async function deleteAccount(client, account) {
const res = await client.stellar.delete(account);
log("================= Deleting account =================");
log(res);
log("================= Deleting account =================");
}
async function main() {
const grid3 = await getClient();
const createAccount: StellarWalletCreateModel = {
name: "stellarTest",
};
const account: StellarWalletInitModel = {
name: "stellarTest2",
secret: "SBCWGJ4A4IHDUUXPASQBL7VKGZGNRMVNV66GO5P6FU6Q4NDKHIHZFRKI",
};
const getAccount: BlockchainGetModel = {
name: "stellarTest2",
};
const signMessage: BlockchainSignModel = {
name: "stellarTest2",
content: "message",
};
const deleteAccount1: BlockchainDeleteModel = {
name: "stellarTest",
};
const deleteAccount2: BlockchainDeleteModel = {
name: "stellarTest2",
};
//Create account
const created_account = await create(grid3, createAccount);
//Initialize account
await init(grid3, account);
//List accounts
await list(grid3);
//Check if the account exists
await exist(grid3, getAccount);
//Get account
const test_account = await get(grid3, getAccount);
//Get balance by account address
const getBalance: StellarWalletBalanceByAddressModel = {
address: test_account.public_key,
};
await balanceByAddress(grid3, { address: getBalance });
//Get account assets
await assets(grid3, getAccount);
//Sign message
await sign(grid3, signMessage);
//Pay
const transaction: StellarWalletTransferModel = {
name: "stellarTest2",
address_dest: created_account.public_key,
amount: 1,
description: "paytest",
asset: "XLM",
};
await pay(grid3, transaction);
//Delete account
await deleteAccount(grid3, deleteAccount1);
await deleteAccount(grid3, deleteAccount2);
grid3.disconnect();
}
main();