mainnet-js 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,8 +9,12 @@ import {
9
9
  import { parseElectrumUrl } from "./util.js";
10
10
  import { ElectrumHostParams, ElectrumClusterParams } from "./interface.js";
11
11
  import { Network } from "../interface.js";
12
- import { networkTickerMap, clusterParams } from "./constant.js";
13
- import { ELECTRUM_CASH_PROTOCOL_VERSION } from "./constant.js";
12
+ import {
13
+ networkTickerMap,
14
+ clusterParams,
15
+ ELECTRUM_CASH_PROTOCOL_VERSION,
16
+ ELECTRUM_CASH_PROTOCOL_VERSION_MAINNET,
17
+ } from "./constant.js";
14
18
 
15
19
  export function setGlobalProvider(
16
20
  network: Network,
@@ -75,11 +79,11 @@ export function getNetworkProvider(
75
79
  let clusterParam = clusterParams[network];
76
80
  clusterParam["confidence"] = getConfidence();
77
81
  clusterParam = Object.assign({}, clusterParam, options);
78
- clusterOrClient = getCluster(servers, clusterParam);
82
+ clusterOrClient = getCluster(servers, clusterParam, network);
79
83
  }
80
84
  // The server is a single string in an array
81
85
  else {
82
- clusterOrClient = getClient(servers);
86
+ clusterOrClient = getClient(servers, network);
83
87
  }
84
88
  let provider = new ElectrumNetworkProvider(
85
89
  clusterOrClient,
@@ -98,8 +102,8 @@ export function getNetworkProvider(
98
102
  }
99
103
 
100
104
  // Create a cluster give a list of servers and parameters
101
- function getCluster(servers: string[], params) {
102
- let electrum = getElectrumCluster(params);
105
+ function getCluster(servers: string[], params, network: Network) {
106
+ let electrum = getElectrumCluster(params, network);
103
107
 
104
108
  for (const s of servers) {
105
109
  let url = parseElectrumUrl(s);
@@ -115,15 +119,17 @@ function getCluster(servers: string[], params) {
115
119
  }
116
120
 
117
121
  // create a client with a list of servers
118
- function getClient(servers: string[]) {
122
+ function getClient(servers: string[], network: Network) {
119
123
  let url = parseElectrumUrl(servers[0]);
120
- return getElectrumClient(url, 120000);
124
+ return getElectrumClient(url, 120000, network);
121
125
  }
122
126
 
123
- function getElectrumCluster(params: ElectrumClusterParams) {
127
+ function getElectrumCluster(params: ElectrumClusterParams, network: Network) {
124
128
  return new ElectrumCluster(
125
129
  getUserAgent(),
126
- ELECTRUM_CASH_PROTOCOL_VERSION,
130
+ network === Network.MAINNET
131
+ ? ELECTRUM_CASH_PROTOCOL_VERSION_MAINNET
132
+ : ELECTRUM_CASH_PROTOCOL_VERSION,
127
133
  params.confidence,
128
134
  params.distribution,
129
135
  params.order,
@@ -131,10 +137,16 @@ function getElectrumCluster(params: ElectrumClusterParams) {
131
137
  );
132
138
  }
133
139
 
134
- function getElectrumClient(params: ElectrumHostParams, timeout: number) {
140
+ function getElectrumClient(
141
+ params: ElectrumHostParams,
142
+ timeout: number,
143
+ network: Network
144
+ ) {
135
145
  return new ElectrumClient(
136
146
  getUserAgent(),
137
- ELECTRUM_CASH_PROTOCOL_VERSION,
147
+ network === Network.MAINNET
148
+ ? ELECTRUM_CASH_PROTOCOL_VERSION_MAINNET
149
+ : ELECTRUM_CASH_PROTOCOL_VERSION,
138
150
  params.host,
139
151
  params.port,
140
152
  params.scheme,
@@ -1,4 +1,5 @@
1
1
  import { ClusterOrder } from "electrum-cash";
2
+ import { NFTCapability } from "../interface";
2
3
 
3
4
  export interface BlockHeader {
4
5
  height: number;
@@ -23,6 +24,18 @@ export interface ElectrumUtxo {
23
24
  value: number;
24
25
  tx_hash: string;
25
26
  height: number;
27
+ token_data:
28
+ | {
29
+ amount: string;
30
+ category: string;
31
+ nft:
32
+ | {
33
+ capability: NFTCapability | undefined;
34
+ commitment: string | undefined;
35
+ }
36
+ | undefined;
37
+ }
38
+ | undefined;
26
39
  }
27
40
 
28
41
  export interface ElectrumRawTransaction {
@@ -6,13 +6,21 @@ import { binToHex, utf8ToBin } from "@bitauth/libauth";
6
6
  import { delay } from "../util";
7
7
 
8
8
  beforeAll(async () => {
9
- await initProviders([Network.REGTEST]);
9
+ await initProviders();
10
10
  });
11
11
  afterAll(async () => {
12
- await disconnectProviders([Network.REGTEST]);
12
+ await disconnectProviders();
13
13
  });
14
14
 
15
15
  describe(`Test cashtokens`, () => {
16
+ test("Test chipnet request", async () => {
17
+ const wallet = await TestNetWallet.watchOnly(
18
+ "bchtest:pzszr88euuuy87uarx9krcuh5psy4zzghsm2033xk4"
19
+ );
20
+ const utxos = await wallet.getTokenUtxos();
21
+ expect(utxos[0].token?.tokenId).toBeDefined();
22
+ });
23
+
16
24
  test("Test tokens will not be burned when sending bch value", async () => {
17
25
  const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
18
26
  const bob = await RegTestWallet.newRandom();