Skip to content

Commit b15bc97

Browse files
authored
Merge thorest and thor - part 1 (#385)
* fix: move accounts to thor * fix: update examples in doc * fix: update examples * fix: move logs to thor-client * fix: move blocks to thor * fix: move tests * fix: update examples * fix: update after merge
1 parent 0c98c39 commit b15bc97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+538
-534
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"eslint.format.enable": true,
33
"editor.codeActionsOnSave": {
4-
"source.fixAll.eslint": true
4+
"source.fixAll.eslint": "explicit"
55
},
66
"[typescript]": {
77
"editor.defaultFormatter": "esbenp.prettier-vscode"

docs/examples/polls/event-poll-dapp.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import {
22
HttpClient,
33
Poll,
4-
ThorestClient
4+
ThorestClient,
5+
ThorClient
56
} from '@vechainfoundation/vechain-sdk-network';
67

78
// 1 - Create client for testnet
89

910
const _testnetUrl = 'https://testnet.vechain.org';
1011
const testNetwork = new HttpClient(_testnetUrl);
1112
const thorestClient = new ThorestClient(testNetwork);
13+
const thorClient = new ThorClient(thorestClient);
1214

1315
// 2 - Init accounts
1416

@@ -21,7 +23,7 @@ const accounts = [
2123

2224
for (const account of accounts) {
2325
const monitoringPoll = Poll.createEventPoll(
24-
async () => await thorestClient.accounts.getAccount(account),
26+
async () => await thorClient.accounts.getAccount(account),
2527
1000
2628
)
2729
// Add listeners for start event

docs/examples/polls/sync-poll-wait-balance-update.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
HttpClient,
33
Poll,
4-
ThorestClient
4+
ThorestClient,
5+
ThorClient
56
} from '@vechainfoundation/vechain-sdk-network';
67
import {
78
dataUtils,
@@ -16,11 +17,12 @@ import { expect } from 'expect';
1617
const _soloUrl = 'http://localhost:8669';
1718
const soloNetwork = new HttpClient(_soloUrl);
1819
const thorestSoloClient = new ThorestClient(soloNetwork);
20+
const thorSoloClient = new ThorClient(thorestSoloClient);
1921

2022
// 2- Init transaction
2123

2224
// 2.1 - Get latest block
23-
const latestBlock = await thorestSoloClient.blocks.getBestBlock();
25+
const latestBlock = await thorSoloClient.blocks.getBestBlock();
2426

2527
// 2.2 - Transaction sender and receiver
2628
const sender = {
@@ -73,11 +75,11 @@ const raw = `0x${encoded.toString('hex')}`;
7375
// 3 - Get the sender and receiver balance before the transaction
7476

7577
const senderBalanceBefore = (
76-
await thorestSoloClient.accounts.getAccount(sender.address)
78+
await thorSoloClient.accounts.getAccount(sender.address)
7779
).balance;
7880

7981
const receiverBalanceBefore = (
80-
await thorestSoloClient.accounts.getAccount(receiver.address)
82+
await thorSoloClient.accounts.getAccount(receiver.address)
8183
).balance;
8284

8385
console.log('Sender balance before:', senderBalanceBefore);
@@ -98,15 +100,15 @@ expect(dataUtils.isHexString(sentedTransaction.id)).toBe(true);
98100
// New balance of sender (wait until the balance is updated)
99101
const newBalanceSender = await Poll.SyncPoll(
100102
async () =>
101-
(await thorestSoloClient.accounts.getAccount(sender.address)).balance
103+
(await thorSoloClient.accounts.getAccount(sender.address)).balance
102104
).waitUntil((newBalance) => {
103105
return newBalance !== senderBalanceBefore;
104106
});
105107

106108
// New balance of receiver (wait until the balance is updated)
107109
const newBalanceReceiver = await Poll.SyncPoll(
108110
async () =>
109-
(await thorestSoloClient.accounts.getAccount(receiver.address)).balance
111+
(await thorSoloClient.accounts.getAccount(receiver.address)).balance
110112
).waitUntil((newBalance) => {
111113
return newBalance !== receiverBalanceBefore;
112114
});

docs/examples/polls/sync-poll-wait-new-block.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
HttpClient,
33
Poll,
4-
ThorestClient
4+
ThorestClient,
5+
ThorClient
56
} from '@vechainfoundation/vechain-sdk-network';
67
import { expect } from 'expect';
78

@@ -10,10 +11,11 @@ import { expect } from 'expect';
1011
const _testnetUrl = 'https://testnet.vechain.org';
1112
const testNetwork = new HttpClient(_testnetUrl);
1213
const thorestClient = new ThorestClient(testNetwork);
14+
const thorClient = new ThorClient(thorestClient);
1315

1416
// 2 - Get current block
1517

16-
const currentBlock = await thorestClient.blocks.getBestBlock();
18+
const currentBlock = await thorClient.blocks.getBestBlock();
1719

1820
console.log('Current block:', currentBlock);
1921

@@ -22,7 +24,7 @@ console.log('Current block:', currentBlock);
2224
// Wait until a new block is created with polling interval of 3 seconds
2325
const newBlock = await Poll.SyncPoll(
2426
// Get the latest block as polling target function
25-
async () => await thorestClient.blocks.getBlock('best'),
27+
async () => await thorClient.blocks.getBlock('best'),
2628
// Polling interval is 3 seconds
2729
{ requestIntervalInMilliseconds: 3000 }
2830
).waitUntil((newBlockData) => {

docs/examples/thorest-client/accounts.ts docs/examples/thor-client/accounts.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
HttpClient,
3-
ThorestClient
3+
ThorestClient,
4+
ThorClient
45
} from '@vechainfoundation/vechain-sdk-network';
56
import { expect } from 'expect';
67

@@ -9,23 +10,24 @@ import { expect } from 'expect';
910
const _testnetUrl = 'https://testnet.vechain.org';
1011
const testNetwork = new HttpClient(_testnetUrl);
1112
const thorestClient = new ThorestClient(testNetwork);
13+
const thorClient = new ThorClient(thorestClient);
1214

1315
// 2 - Get account details
1416

1517
// Account details
16-
const accountDetails = await thorestClient.accounts.getAccount(
18+
const accountDetails = await thorClient.accounts.getAccount(
1719
'0x5034aa590125b64023a0262112b98d72e3c8e40e'
1820
);
1921
expect(accountDetails).toBeDefined();
2022

2123
// Account code
22-
const accountCode = await thorestClient.accounts.getBytecode(
24+
const accountCode = await thorClient.accounts.getBytecode(
2325
'0x5034aa590125b64023a0262112b98d72e3c8e40e'
2426
);
2527
expect(accountCode).toEqual('0x');
2628

2729
// Get account storage
28-
const accountStorage = await thorestClient.accounts.getStorageAt(
30+
const accountStorage = await thorClient.accounts.getStorageAt(
2931
'0x5034aa590125b64023a0262112b98d72e3c8e40e',
3032
'0x0000000000000000000000000000000000000000000000000000000000000001'
3133
);

docs/examples/thorest-client/logs.ts docs/examples/thor-client/logs.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
HttpClient,
3-
ThorestClient
3+
ThorestClient,
4+
ThorClient
45
} from '@vechainfoundation/vechain-sdk-network';
56
import { expect } from 'expect';
67

@@ -9,10 +10,11 @@ import { expect } from 'expect';
910
const _testnetUrl = 'https://testnet.vechain.org';
1011
const testNetwork = new HttpClient(_testnetUrl);
1112
const thorestClient = new ThorestClient(testNetwork);
13+
const thorClient = new ThorClient(thorestClient);
1214

1315
// 2 - Filter event logs based on the provided criteria. (EXAMPLE 1)
1416

15-
const eventLogs = await thorestClient.logs.filterEventLogs({
17+
const eventLogs = await thorClient.logs.filterEventLogs({
1618
// Specify the range of blocks to search for events
1719
range: {
1820
unit: 'block',
@@ -96,7 +98,7 @@ expect(eventLogs).toEqual([
9698

9799
// 3 - Filter again event logs based on the provided criteria. (EXAMPLE 2)
98100

99-
const transferLogs = await thorestClient.logs.filterTransferLogs({
101+
const transferLogs = await thorClient.logs.filterTransferLogs({
100102
// Specify the range of blocks to search for transfer events
101103
range: {
102104
unit: 'block',

docs/examples/thorest-client/blocks.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
HttpClient,
3-
ThorestClient
3+
ThorestClient,
4+
ThorClient
45
} from '@vechainfoundation/vechain-sdk-network';
56
import { expect } from 'expect';
67

@@ -9,11 +10,12 @@ import { expect } from 'expect';
910
const _testnetUrl = 'https://testnet.vechain.org';
1011
const testNetwork = new HttpClient(_testnetUrl);
1112
const thorestClient = new ThorestClient(testNetwork);
13+
const thorClient = new ThorClient(thorestClient);
1214

1315
// 2 - Get block details
1416

1517
// Details of block
16-
const blockDetails = await thorestClient.blocks.getBlock(1);
18+
const blockDetails = await thorClient.blocks.getBlock(1);
1719
expect(blockDetails).toEqual({
1820
number: 1,
1921
id: '0x000000019015bbd98fc1c9088d793ba9add53896a29cd9aa3a4dcabd1f561c38',
@@ -41,10 +43,10 @@ expect(blockDetails).toEqual({
4143

4244
// 3 - Get best block details
4345

44-
const bestBlockDetails = await thorestClient.blocks.getBestBlock();
46+
const bestBlockDetails = await thorClient.blocks.getBestBlock();
4547
expect(bestBlockDetails).toBeDefined();
4648

4749
// 4 - Get finalizes block details
4850

49-
const finalBlockDetails = await thorestClient.blocks.getFinalBlock();
51+
const finalBlockDetails = await thorClient.blocks.getFinalBlock();
5052
expect(finalBlockDetails).toBeDefined();

docs/examples/thorest-client/delegated-transactions.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
} from '@vechainfoundation/vechain-sdk-core';
88
import {
99
HttpClient,
10-
ThorestClient
10+
ThorestClient,
11+
ThorClient
1112
} from '@vechainfoundation/vechain-sdk-network';
1213
import { expect } from 'expect';
1314

@@ -16,10 +17,11 @@ import { expect } from 'expect';
1617
const _soloUrl = 'http://localhost:8669';
1718
const soloNetwork = new HttpClient(_soloUrl);
1819
const thorestSoloClient = new ThorestClient(soloNetwork);
20+
const thorSoloClient = new ThorClient(thorestSoloClient);
1921

2022
// 2 - Get latest block
2123

22-
const latestBlock = await thorestSoloClient.blocks.getBestBlock();
24+
const latestBlock = await thorSoloClient.blocks.getBestBlock();
2325

2426
// 3 - Create transaction clauses
2527

docs/examples/thorest-client/transactions.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@vechainfoundation/vechain-sdk-core';
88
import {
99
HttpClient,
10+
ThorClient,
1011
ThorestClient
1112
} from '@vechainfoundation/vechain-sdk-network';
1213
import { expect } from 'expect';
@@ -16,10 +17,11 @@ import { expect } from 'expect';
1617
const _soloUrl = 'http://localhost:8669';
1718
const soloNetwork = new HttpClient(_soloUrl);
1819
const thorestSoloClient = new ThorestClient(soloNetwork);
20+
const thorSoloClient = new ThorClient(thorestSoloClient);
1921

2022
// 2 - Get latest block
2123

22-
const latestBlock = await thorestSoloClient.blocks.getBestBlock();
24+
const latestBlock = await thorSoloClient.blocks.getBestBlock();
2325

2426
// 3 - Create clauses
2527

docs/polls.md

+17-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ This section illustrates the methodology for monitoring the production of a new
1111
import {
1212
HttpClient,
1313
Poll,
14-
ThorestClient
14+
ThorestClient,
15+
ThorClient
1516
} from '@vechainfoundation/vechain-sdk-network';
1617
import { expect } from 'expect';
1718

@@ -20,10 +21,11 @@ import { expect } from 'expect';
2021
const _testnetUrl = 'https://testnet.vechain.org';
2122
const testNetwork = new HttpClient(_testnetUrl);
2223
const thorestClient = new ThorestClient(testNetwork);
24+
const thorClient = new ThorClient(thorestClient);
2325

2426
// 2 - Get current block
2527

26-
const currentBlock = await thorestClient.blocks.getBestBlock();
28+
const currentBlock = await thorClient.blocks.getBestBlock();
2729

2830
console.log('Current block:', currentBlock);
2931

@@ -32,7 +34,7 @@ console.log('Current block:', currentBlock);
3234
// Wait until a new block is created with polling interval of 3 seconds
3335
const newBlock = await Poll.SyncPoll(
3436
// Get the latest block as polling target function
35-
async () => await thorestClient.blocks.getBlock('best'),
37+
async () => await thorClient.blocks.getBlock('best'),
3638
// Polling interval is 3 seconds
3739
{ requestIntervalInMilliseconds: 3000 }
3840
).waitUntil((newBlockData) => {
@@ -54,7 +56,8 @@ Here, we explore the approach to monitor balance changes subsequent to a transfe
5456
import {
5557
HttpClient,
5658
Poll,
57-
ThorestClient
59+
ThorestClient,
60+
ThorClient
5861
} from '@vechainfoundation/vechain-sdk-network';
5962
import {
6063
dataUtils,
@@ -69,11 +72,12 @@ import { expect } from 'expect';
6972
const _soloUrl = 'http://localhost:8669';
7073
const soloNetwork = new HttpClient(_soloUrl);
7174
const thorestSoloClient = new ThorestClient(soloNetwork);
75+
const thorSoloClient = new ThorClient(thorestSoloClient);
7276

7377
// 2- Init transaction
7478

7579
// 2.1 - Get latest block
76-
const latestBlock = await thorestSoloClient.blocks.getBestBlock();
80+
const latestBlock = await thorSoloClient.blocks.getBestBlock();
7781

7882
// 2.2 - Transaction sender and receiver
7983
const sender = {
@@ -126,11 +130,11 @@ const raw = `0x${encoded.toString('hex')}`;
126130
// 3 - Get the sender and receiver balance before the transaction
127131

128132
const senderBalanceBefore = (
129-
await thorestSoloClient.accounts.getAccount(sender.address)
133+
await thorSoloClient.accounts.getAccount(sender.address)
130134
).balance;
131135

132136
const receiverBalanceBefore = (
133-
await thorestSoloClient.accounts.getAccount(receiver.address)
137+
await thorSoloClient.accounts.getAccount(receiver.address)
134138
).balance;
135139

136140
console.log('Sender balance before:', senderBalanceBefore);
@@ -151,15 +155,15 @@ expect(dataUtils.isHexString(sentedTransaction.id)).toBe(true);
151155
// New balance of sender (wait until the balance is updated)
152156
const newBalanceSender = await Poll.SyncPoll(
153157
async () =>
154-
(await thorestSoloClient.accounts.getAccount(sender.address)).balance
158+
(await thorSoloClient.accounts.getAccount(sender.address)).balance
155159
).waitUntil((newBalance) => {
156160
return newBalance !== senderBalanceBefore;
157161
});
158162

159163
// New balance of receiver (wait until the balance is updated)
160164
const newBalanceReceiver = await Poll.SyncPoll(
161165
async () =>
162-
(await thorestSoloClient.accounts.getAccount(receiver.address)).balance
166+
(await thorSoloClient.accounts.getAccount(receiver.address)).balance
163167
).waitUntil((newBalance) => {
164168
return newBalance !== receiverBalanceBefore;
165169
});
@@ -186,14 +190,16 @@ This example demonstrates the application of an asynchronous poll for tracking t
186190
import {
187191
HttpClient,
188192
Poll,
189-
ThorestClient
193+
ThorestClient,
194+
ThorClient
190195
} from '@vechainfoundation/vechain-sdk-network';
191196

192197
// 1 - Create client for testnet
193198

194199
const _testnetUrl = 'https://testnet.vechain.org';
195200
const testNetwork = new HttpClient(_testnetUrl);
196201
const thorestClient = new ThorestClient(testNetwork);
202+
const thorClient = new ThorClient(thorestClient);
197203

198204
// 2 - Init accounts
199205

@@ -206,7 +212,7 @@ const accounts = [
206212

207213
for (const account of accounts) {
208214
const monitoringPoll = Poll.createEventPoll(
209-
async () => await thorestClient.accounts.getAccount(account),
215+
async () => await thorClient.accounts.getAccount(account),
210216
1000
211217
)
212218
// Add listeners for start event

0 commit comments

Comments
 (0)