@carrot-protocol/boost-http-client 0.3.0 → 0.3.1-http-print1-dev-89d812a
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.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +12 -2
- package/package.json +1 -1
- package/src/index.ts +13 -2
package/dist/index.d.ts
CHANGED
|
@@ -10,11 +10,12 @@ export declare class Client {
|
|
|
10
10
|
private readonly baseUrl;
|
|
11
11
|
private readonly http;
|
|
12
12
|
private readonly provider;
|
|
13
|
+
private readonly dryRun;
|
|
13
14
|
/**
|
|
14
15
|
* Create a new Carrot Boost API client
|
|
15
16
|
* @param baseUrl Base URL for the API
|
|
16
17
|
*/
|
|
17
|
-
constructor(baseUrl: string, provider?: AnchorProvider);
|
|
18
|
+
constructor(baseUrl: string, provider?: AnchorProvider, dryRun?: boolean);
|
|
18
19
|
address(): web3.PublicKey;
|
|
19
20
|
private send;
|
|
20
21
|
/**
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,7 @@ class Client {
|
|
|
56
56
|
* Create a new Carrot Boost API client
|
|
57
57
|
* @param baseUrl Base URL for the API
|
|
58
58
|
*/
|
|
59
|
-
constructor(baseUrl, provider) {
|
|
59
|
+
constructor(baseUrl, provider, dryRun) {
|
|
60
60
|
this.baseUrl = new URL(baseUrl).toString();
|
|
61
61
|
this.http = axios_1.default.create({
|
|
62
62
|
baseURL: this.baseUrl,
|
|
@@ -67,6 +67,7 @@ class Client {
|
|
|
67
67
|
if (!provider) {
|
|
68
68
|
provider = getDummyProvider();
|
|
69
69
|
}
|
|
70
|
+
this.dryRun = dryRun ?? false;
|
|
70
71
|
this.provider = provider;
|
|
71
72
|
}
|
|
72
73
|
address() {
|
|
@@ -74,6 +75,10 @@ class Client {
|
|
|
74
75
|
}
|
|
75
76
|
// sign and send tx to api for sending to network
|
|
76
77
|
async send(unsignedBase64Tx, userRequestId) {
|
|
78
|
+
if (this.dryRun) {
|
|
79
|
+
// for debugging purposes only
|
|
80
|
+
console.log("unsigedBase64Tx", unsignedBase64Tx);
|
|
81
|
+
}
|
|
77
82
|
// deserialize into tx obj
|
|
78
83
|
const txBytes = Buffer.from(unsignedBase64Tx, "base64");
|
|
79
84
|
const tx = anchor_1.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
@@ -88,7 +93,12 @@ class Client {
|
|
|
88
93
|
txns: [encodedAndSignedTx],
|
|
89
94
|
};
|
|
90
95
|
// send to api
|
|
91
|
-
|
|
96
|
+
if (!this.dryRun) {
|
|
97
|
+
await handleApiCall(() => this.http.post(`send`, sendRequest));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
console.warn("dry run enabled, did not send tx");
|
|
101
|
+
}
|
|
92
102
|
// return txsig
|
|
93
103
|
return bs58_1.default.encode(txSig);
|
|
94
104
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -50,12 +50,13 @@ export class Client {
|
|
|
50
50
|
private readonly baseUrl: string;
|
|
51
51
|
private readonly http: AxiosInstance;
|
|
52
52
|
private readonly provider: AnchorProvider;
|
|
53
|
+
private readonly dryRun: boolean;
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Create a new Carrot Boost API client
|
|
56
57
|
* @param baseUrl Base URL for the API
|
|
57
58
|
*/
|
|
58
|
-
constructor(baseUrl: string, provider?: AnchorProvider) {
|
|
59
|
+
constructor(baseUrl: string, provider?: AnchorProvider, dryRun?: boolean) {
|
|
59
60
|
this.baseUrl = new URL(baseUrl).toString();
|
|
60
61
|
this.http = axios.create({
|
|
61
62
|
baseURL: this.baseUrl,
|
|
@@ -66,6 +67,7 @@ export class Client {
|
|
|
66
67
|
if (!provider) {
|
|
67
68
|
provider = getDummyProvider();
|
|
68
69
|
}
|
|
70
|
+
this.dryRun = dryRun ?? false;
|
|
69
71
|
this.provider = provider;
|
|
70
72
|
}
|
|
71
73
|
|
|
@@ -78,6 +80,11 @@ export class Client {
|
|
|
78
80
|
unsignedBase64Tx: string,
|
|
79
81
|
userRequestId: string,
|
|
80
82
|
): Promise<string> {
|
|
83
|
+
if (this.dryRun) {
|
|
84
|
+
// for debugging purposes only
|
|
85
|
+
console.log("unsigedBase64Tx", unsignedBase64Tx);
|
|
86
|
+
}
|
|
87
|
+
|
|
81
88
|
// deserialize into tx obj
|
|
82
89
|
const txBytes = Buffer.from(unsignedBase64Tx, "base64");
|
|
83
90
|
const tx = web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
@@ -98,7 +105,11 @@ export class Client {
|
|
|
98
105
|
};
|
|
99
106
|
|
|
100
107
|
// send to api
|
|
101
|
-
|
|
108
|
+
if (!this.dryRun) {
|
|
109
|
+
await handleApiCall(() => this.http.post(`send`, sendRequest));
|
|
110
|
+
} else {
|
|
111
|
+
console.warn("dry run enabled, did not send tx");
|
|
112
|
+
}
|
|
102
113
|
|
|
103
114
|
// return txsig
|
|
104
115
|
return encode.encode(txSig);
|