File tree 10 files changed +140
-15
lines changed 10 files changed +140
-15
lines changed Original file line number Diff line number Diff line change @@ -17,9 +17,11 @@ void main() async {
17
17
"secret add bag cluster deposit beach illness letter crouch position rain arctic" ,
18
18
"sr25519" );
19
19
await client.connect ();
20
+ final extrinsic = await client.clientBalances.transfer (
21
+ address: "5CJrCjZvsudNoJApTGG5PKcZfhAzAyGqgSK8bysoCV2oRBMC" , amount: 10 );
20
22
21
- // await client.apply(extrinsic);
22
- client.kvStrore.list ();
23
+ await client.apply (extrinsic);
24
+ // await client.kvStrore.list();
23
25
24
26
// await client.disconnect();
25
27
}
Original file line number Diff line number Diff line change 1
1
import 'package:polkadart/scale_codec.dart' ;
2
+ import 'package:polkadart_keyring/polkadart_keyring.dart' ;
2
3
import 'package:tfchain_client/generated/dev/types/frame_system/account_info.dart' ;
3
4
import 'package:tfchain_client/generated/dev/types/sp_runtime/multiaddress/multi_address.dart' ;
4
5
import 'package:tfchain_client/generated/dev/types/tfchain_runtime/runtime_call.dart' ;
@@ -9,9 +10,9 @@ class QueryBalances {
9
10
QueryBalances (this .client);
10
11
11
12
Future <AccountInfo ?> get ({required String address}) async {
12
- // TODO: should get pair.publicKey.bytes, How to get keypair if i don't have mnemonic
13
- final res = await client.api.query.system
14
- . account ( Address32 (address.codeUnits).value0 );
13
+ final keyring = Keyring ();
14
+ final publicKey = keyring. decodeAddress (address);
15
+ final res = await client.api.query.system. account (publicKey );
15
16
return res;
16
17
}
17
18
}
Original file line number Diff line number Diff line change @@ -43,7 +43,25 @@ class KVStore {
43
43
...client.keypair! .publicKey.bytes
44
44
]);
45
45
46
- final keys = await client.api.rpc.state.getKeys (key: partialKey);
46
+ List <Uint8List > keys = [];
47
+ int count = 2 ;
48
+ Uint8List ? startKey;
49
+ bool hasMore = true ;
50
+
51
+ while (hasMore) {
52
+ final keysPage = await client.api.rpc.state.getKeysPaged (
53
+ key: partialKey,
54
+ count: count,
55
+ startKey: startKey,
56
+ );
57
+
58
+ if (keysPage.isEmpty) {
59
+ hasMore = false ;
60
+ } else {
61
+ keys.addAll (keysPage);
62
+ startKey = keysPage.last;
63
+ }
64
+ }
47
65
48
66
final keysValues = await client.api.rpc.state.queryStorageAt (keys);
49
67
@@ -59,6 +77,7 @@ class KVStore {
59
77
keyValueMap[String .fromCharCodes (added)] = String .fromCharCodes (value);
60
78
}
61
79
80
+ print (keyValueMap);
62
81
return keyValueMap;
63
82
}
64
83
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ class QueryTFTPrice {
4
4
final QueryClient client;
5
5
QueryTFTPrice (this .client);
6
6
7
- Future <int ?> get ({ required String address} ) async {
7
+ Future <int ?> get () async {
8
8
final res = await client.api.query.tFTPriceModule.tftPrice ();
9
9
return res;
10
10
}
Original file line number Diff line number Diff line change
1
+ import 'package:polkadart_keyring/polkadart_keyring.dart' ;
1
2
import 'package:tfchain_client/generated/dev/types/pallet_tfgrid/types/twin.dart' ;
2
3
import 'package:tfchain_client/generated/dev/types/tfchain_runtime/runtime_call.dart' ;
3
4
import 'package:tfchain_client/tfchain_client.dart' ;
@@ -11,7 +12,9 @@ class QueryTwins {
11
12
return res;
12
13
}
13
14
14
- Future <int ?> getTwinIdByAccountId ({required List <int > accountId}) async {
15
+ Future <int ?> getTwinIdByAccountId ({required String address}) async {
16
+ final keyring = Keyring ();
17
+ final accountId = keyring.decodeAddress (address);
15
18
final res =
16
19
await client.api.query.tfgridModule.twinIdByAccountID (accountId);
17
20
return res;
Original file line number Diff line number Diff line change 1
1
import 'package:test/test.dart' ;
2
+ import 'package:tfchain_client/generated/dev/types/frame_system/account_info.dart' ;
3
+ import 'package:tfchain_client/tfchain_client.dart' ;
2
4
3
5
void main () {
4
6
group ("Query Balances Test" , () {
5
- // late QueryClient queryClient;
6
- // setUp(() {
7
- // queryClient = QueryClient("wss://tfchain.dev.grid.tf/ws");
8
- // });
7
+ late QueryClient queryClient;
8
+ setUp (() {
9
+ queryClient = QueryClient ("wss://tfchain.dev.grid.tf/ws" );
10
+ });
9
11
10
- // test('Test Get Balance', () {
11
-
12
- // });
12
+ test ('Test Get Balance' , () async {
13
+ String address = "5CJrCjZvsudNoJApTGG5PKcZfhAzAyGqgSK8bysoCV2oRBMC" ;
14
+ AccountInfo ? accountInfo =
15
+ await queryClient.balances.get (address: address);
16
+ expect (accountInfo, isNotNull);
17
+ });
18
+
19
+ test ('Test Get Balance with Invalid address' , () async {
20
+ String address = "address" ;
21
+ try {
22
+ AccountInfo ? accountInfo =
23
+ await queryClient.balances.get (address: address);
24
+ expect (accountInfo, isNull);
25
+ } catch (e) {
26
+ expect (e, isNotNull);
27
+ }
28
+ });
13
29
});
14
30
}
Original file line number Diff line number Diff line change
1
+ import 'package:test/test.dart' ;
2
+ import 'package:tfchain_client/generated/dev/types/pallet_tfgrid/types/pricing_policy.dart' ;
3
+ import 'package:tfchain_client/tfchain_client.dart' ;
4
+
5
+ void main () {
6
+ group ("Query Pricing Policies" , () {
7
+ late QueryClient queryClient;
8
+ setUp (() {
9
+ queryClient = QueryClient ("wss://tfchain.dev.grid.tf/ws" );
10
+ });
11
+
12
+ test ('Test Get Pricing Policy' , () async {
13
+ PricingPolicy ? res = await queryClient.policies.get (id: 1 );
14
+ expect (res, isNotNull);
15
+ });
16
+ });
17
+ }
Original file line number Diff line number Diff line change
1
+ import 'package:test/test.dart' ;
2
+ import 'package:tfchain_client/tfchain_client.dart' ;
3
+
4
+ void main () {
5
+ group ("Query Bridge Test" , () {
6
+ late QueryClient queryClient;
7
+ setUp (() {
8
+ queryClient = QueryClient ("wss://tfchain.dev.grid.tf/ws" );
9
+ });
10
+
11
+ test ('Test Get Withdraw fee' , () async {
12
+ BigInt ? fee = await queryClient.bridge.getWithdrawFee ();
13
+ expect (fee, isNotNull);
14
+ });
15
+
16
+ test ('Test Get Deposit fee' , () async {
17
+ BigInt ? fee = await queryClient.bridge.getDepositFee ();
18
+ expect (fee, isNotNull);
19
+ });
20
+ });
21
+ }
Original file line number Diff line number Diff line change
1
+ import 'package:test/test.dart' ;
2
+ import 'package:tfchain_client/tfchain_client.dart' ;
3
+
4
+ void main () {
5
+ group ("Query Price Test" , () {
6
+ late QueryClient queryClient;
7
+ setUp (() {
8
+ queryClient = QueryClient ("wss://tfchain.dev.grid.tf/ws" );
9
+ });
10
+
11
+ test ('Test Get TFT price' , () async {
12
+ final price = await queryClient.price.get ();
13
+ expect (price, isNotNull);
14
+ });
15
+ });
16
+ }
Original file line number Diff line number Diff line change
1
+ import 'package:test/test.dart' ;
2
+ import 'package:tfchain_client/tfchain_client.dart' ;
3
+
4
+ void main () {
5
+ group ("Query Twins Test" , () {
6
+ late QueryClient queryClient;
7
+ setUp (() {
8
+ queryClient = QueryClient ("wss://tfchain.dev.grid.tf/ws" );
9
+ });
10
+
11
+ test ('Test Get Twin with id' , () async {
12
+ int id = 214 ;
13
+ final twin = await queryClient.twins.get (id: id);
14
+ expect (twin, isNotNull);
15
+ });
16
+
17
+ test ('Test Get Twin with zero id' , () async {
18
+ int id = 0 ;
19
+ final twin = await queryClient.twins.get (id: id);
20
+ expect (twin, null );
21
+ });
22
+
23
+ test ('Test Get Twin Id with account Id' , () async {
24
+ String address = "5CJrCjZvsudNoJApTGG5PKcZfhAzAyGqgSK8bysoCV2oRBMC" ;
25
+ final twin =
26
+ await queryClient.twins.getTwinIdByAccountId (address: address);
27
+ expect (twin, 7845 );
28
+ });
29
+ });
30
+ }
You can’t perform that action at this time.
0 commit comments