@@ -13,6 +13,10 @@ import {
13
13
14
14
type ProgramImports = { [ key : string ] : string | Program } ;
15
15
16
+ interface AleoNetworkClientOptions {
17
+ headers ?: { [ key : string ] : string } ;
18
+ }
19
+
16
20
/**
17
21
* Client library that encapsulates REST calls to publicly exposed endpoints of Aleo nodes. The methods provided in this
18
22
* allow users to query public information from the Aleo blockchain and submit transactions to the network.
@@ -27,10 +31,20 @@ type ProgramImports = { [key: string]: string | Program };
27
31
*/
28
32
class AleoNetworkClient {
29
33
host : string ;
34
+ headers : { [ key : string ] : string } ;
30
35
account : Account | undefined ;
31
36
32
- constructor ( host : string ) {
37
+ constructor ( host : string , options ?: AleoNetworkClientOptions ) {
33
38
this . host = host + "/testnet3" ;
39
+
40
+ if ( options && options . headers ) {
41
+ this . headers = options . headers ;
42
+
43
+ } else {
44
+ this . headers = {
45
+ "X-Aleo-SDK-Version" : "0.6.9" ,
46
+ } ;
47
+ }
34
48
}
35
49
36
50
/**
@@ -69,8 +83,12 @@ class AleoNetworkClient {
69
83
url = "/" ,
70
84
) : Promise < Type > {
71
85
try {
72
- const response = await get ( this . host + url ) ;
86
+ const response = await get ( this . host + url , {
87
+ headers : this . headers
88
+ } ) ;
89
+
73
90
return await response . json ( ) ;
91
+
74
92
} catch ( error ) {
75
93
throw new Error ( "Error fetching data." ) ;
76
94
}
@@ -627,9 +645,9 @@ class AleoNetworkClient {
627
645
try {
628
646
const response = await post ( this . host + "/transaction/broadcast" , {
629
647
body : transaction_string ,
630
- headers : {
648
+ headers : Object . assign ( { } , this . headers , {
631
649
"Content-Type" : "application/json" ,
632
- } ,
650
+ } ) ,
633
651
} ) ;
634
652
635
653
try {
@@ -644,4 +662,4 @@ class AleoNetworkClient {
644
662
}
645
663
}
646
664
647
- export { AleoNetworkClient , ProgramImports }
665
+ export { AleoNetworkClient , AleoNetworkClientOptions , ProgramImports }
0 commit comments