@magicblock-labs/ephemeral-rollups-sdk 0.3.3 → 0.3.4
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.
|
@@ -28,7 +28,7 @@ describe("Connection prototype methods", () => {
|
|
|
28
28
|
let connection;
|
|
29
29
|
let tx;
|
|
30
30
|
beforeEach(() => {
|
|
31
|
-
connection = new magic_router_js_1.
|
|
31
|
+
connection = new magic_router_js_1.ConnectionMagicRouter("http://localhost");
|
|
32
32
|
tx = new web3_js_1.Transaction();
|
|
33
33
|
tx.serialize = jest.fn(() => Buffer.from("mock"));
|
|
34
34
|
tx.sign = jest.fn();
|
|
@@ -70,17 +70,17 @@ describe("Connection prototype methods", () => {
|
|
|
70
70
|
});
|
|
71
71
|
it("prepareTransaction sets recentBlockhash", async () => {
|
|
72
72
|
jest
|
|
73
|
-
.spyOn(magic_router_js_1.
|
|
73
|
+
.spyOn(magic_router_js_1.ConnectionMagicRouter.prototype, "getLatestBlockhashForTransaction")
|
|
74
74
|
.mockResolvedValue({ blockhash: "hb", lastValidBlockHeight: 100 });
|
|
75
75
|
const result = await connection.prepareTransaction(tx);
|
|
76
76
|
expect(result.recentBlockhash).toBe("hb");
|
|
77
77
|
});
|
|
78
78
|
it("sendTransaction signs and sends transaction", async () => {
|
|
79
79
|
jest
|
|
80
|
-
.spyOn(magic_router_js_1.
|
|
80
|
+
.spyOn(magic_router_js_1.ConnectionMagicRouter.prototype, "getLatestBlockhashForTransaction")
|
|
81
81
|
.mockResolvedValue({ blockhash: "hb", lastValidBlockHeight: 100 });
|
|
82
82
|
jest
|
|
83
|
-
.spyOn(magic_router_js_1.
|
|
83
|
+
.spyOn(magic_router_js_1.ConnectionMagicRouter.prototype, "sendRawTransaction")
|
|
84
84
|
.mockResolvedValue("sig123");
|
|
85
85
|
const signers = [new web3_js_1.Keypair()];
|
|
86
86
|
const sendTx = connection.sendTransaction.bind(connection);
|
|
@@ -93,10 +93,10 @@ describe("Connection prototype methods", () => {
|
|
|
93
93
|
});
|
|
94
94
|
it("sendAndConfirmTransaction calls sendTransaction and returns signature", async () => {
|
|
95
95
|
jest
|
|
96
|
-
.spyOn(magic_router_js_1.
|
|
96
|
+
.spyOn(magic_router_js_1.ConnectionMagicRouter.prototype, "sendTransaction")
|
|
97
97
|
.mockResolvedValue("sig123");
|
|
98
98
|
jest
|
|
99
|
-
.spyOn(magic_router_js_1.
|
|
99
|
+
.spyOn(magic_router_js_1.ConnectionMagicRouter.prototype, "confirmTransaction")
|
|
100
100
|
.mockResolvedValue({ value: { err: null } });
|
|
101
101
|
const signature = await connection.sendAndConfirmTransaction(tx, [
|
|
102
102
|
new web3_js_1.Keypair(),
|
|
@@ -105,10 +105,10 @@ describe("Connection prototype methods", () => {
|
|
|
105
105
|
});
|
|
106
106
|
it("sendAndConfirmTransaction throws SendTransactionError if status has err", async () => {
|
|
107
107
|
jest
|
|
108
|
-
.spyOn(magic_router_js_1.
|
|
108
|
+
.spyOn(magic_router_js_1.ConnectionMagicRouter.prototype, "sendTransaction")
|
|
109
109
|
.mockResolvedValue("sig123");
|
|
110
110
|
jest
|
|
111
|
-
.spyOn(magic_router_js_1.
|
|
111
|
+
.spyOn(magic_router_js_1.ConnectionMagicRouter.prototype, "confirmTransaction")
|
|
112
112
|
.mockResolvedValue({ value: { err: { some: "error" } } });
|
|
113
113
|
await expect(connection.sendAndConfirmTransaction(tx, [new web3_js_1.Keypair()])).rejects.toThrow(web3_js_1.SendTransactionError);
|
|
114
114
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"magic-router.test.js","sourceRoot":"","sources":["../../src/__tests__/magic-router.test.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"magic-router.test.js","sourceRoot":"","sources":["../../src/__tests__/magic-router.test.ts"],"names":[],"mappings":";;AAAA,wDAAgF;AAChF,6CAKyB;AAGzB,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,EAAE,C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IAAI;aACD,KAAK,CAAC,uCAAqB,CAAC,SAAgB,EAAE,iBAAiB,CAAC;aAChE,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC/B,IAAI;aACD,KAAK,CAAC,uCAAqB,CAAC,SAAgB,EAAE,oBAAoB,CAAC;aACnE,iBAAiB,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;QAE5D,MAAM,MAAM,CACV,UAAU,CAAC,yBAAyB,CAAC,EAAE,EAAE,CAAC,IAAI,iBAAO,EAAE,CAAC,CAAC,CAC1D,CAAC,OAAO,CAAC,OAAO,CAAC,8BAAoB,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib/magic-router.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import { Connection, Transaction } from "@solana/web3.js";
|
|
1
|
+
import { Connection, Transaction, ConfirmOptions, TransactionSignature, Signer, BlockhashWithExpiryBlockHeight, SendOptions, PublicKey, VersionedTransaction } from "@solana/web3.js";
|
|
2
2
|
export declare function getWritableAccounts(transaction: Transaction): string[];
|
|
3
|
-
export
|
|
3
|
+
export declare class ConnectionMagicRouter extends Connection {
|
|
4
|
+
getClosestValidator(): Promise<{
|
|
5
|
+
identity: string;
|
|
6
|
+
fqdn?: string;
|
|
7
|
+
}>;
|
|
8
|
+
getDelegationStatus(account: PublicKey | string): Promise<{
|
|
9
|
+
isDelegated: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
getLatestBlockhashForTransaction(transaction: Transaction, options?: ConfirmOptions): Promise<BlockhashWithExpiryBlockHeight>;
|
|
12
|
+
prepareTransaction(transaction: Transaction, options?: ConfirmOptions): Promise<Transaction>;
|
|
13
|
+
sendTransaction(transaction: Transaction | VersionedTransaction, signersOrOptions?: Signer[] | SendOptions, options?: SendOptions): Promise<TransactionSignature>;
|
|
14
|
+
sendAndConfirmTransaction(transaction: Transaction, signers: Signer[], options?: ConfirmOptions & {
|
|
15
|
+
abortSignal?: AbortSignal;
|
|
16
|
+
}): Promise<TransactionSignature>;
|
|
17
|
+
}
|
|
4
18
|
//# sourceMappingURL=magic-router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"magic-router.d.ts","sourceRoot":"","sources":["../src/magic-router.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,
|
|
1
|
+
{"version":3,"file":"magic-router.d.ts","sourceRoot":"","sources":["../src/magic-router.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,MAAM,EACN,8BAA8B,EAC9B,WAAW,EACX,SAAS,EAET,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAOzB,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,YAgB3D;AAKD,qBAAa,qBAAsB,SAAQ,UAAU;IAK7C,mBAAmB,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAwBnE,mBAAmB,CACvB,OAAO,EAAE,SAAS,GAAG,MAAM,GAC1B,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAA;KAAE,CAAC;IAwB9B,gCAAgC,CACpC,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,8BAA8B,CAAC;IAwBpC,kBAAkB,CACtB,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,WAAW,CAAC;IAiBjB,eAAe,CACnB,WAAW,EAAE,WAAW,GAAG,oBAAoB,EAC/C,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAAG,WAAW,EACzC,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,oBAAoB,CAAC;IAiC1B,yBAAyB,CAC7B,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,cAAc,GAAG;QAAE,WAAW,CAAC,EAAE,WAAW,CAAA;KAAE,GACvD,OAAO,CAAC,oBAAoB,CAAC;CAoDjC"}
|
package/lib/magic-router.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ConnectionMagicRouter = void 0;
|
|
4
4
|
exports.getWritableAccounts = getWritableAccounts;
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return web3_js_1.Connection; } });
|
|
7
6
|
function getWritableAccounts(transaction) {
|
|
8
7
|
const writableAccounts = new Set();
|
|
9
8
|
if (transaction.feePayer) {
|
|
@@ -18,39 +17,39 @@ function getWritableAccounts(transaction) {
|
|
|
18
17
|
}
|
|
19
18
|
return Array.from(writableAccounts);
|
|
20
19
|
}
|
|
21
|
-
web3_js_1.Connection
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
class ConnectionMagicRouter extends web3_js_1.Connection {
|
|
21
|
+
async getClosestValidator() {
|
|
22
|
+
const response = await fetch(this.rpcEndpoint, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: { "Content-Type": "application/json" },
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
jsonrpc: "2.0",
|
|
27
|
+
id: 1,
|
|
28
|
+
method: "getIdentity",
|
|
29
|
+
params: [],
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
const identityData = (await response.json())?.result;
|
|
33
|
+
if (identityData === null || identityData.identity === undefined) {
|
|
34
|
+
throw new Error("Invalid response");
|
|
35
|
+
}
|
|
36
|
+
return identityData;
|
|
37
|
+
}
|
|
38
|
+
async getDelegationStatus(account) {
|
|
39
|
+
const accountAddress = typeof account === "string" ? account : account.toBase58();
|
|
40
|
+
const response = await fetch(`${this.rpcEndpoint}/getDelegationStatus`, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: { "Content-Type": "application/json" },
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
jsonrpc: "2.0",
|
|
45
|
+
id: 1,
|
|
46
|
+
method: "getDelegationStatus",
|
|
47
|
+
params: [accountAddress],
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
return (await response.json()).result;
|
|
35
51
|
}
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
web3_js_1.Connection.prototype.getDelegationStatus = async function (account) {
|
|
39
|
-
const accountAddress = typeof account === "string" ? account : account.toBase58();
|
|
40
|
-
const response = await fetch(`${this.rpcEndpoint}/getDelegationStatus`, {
|
|
41
|
-
method: "POST",
|
|
42
|
-
headers: { "Content-Type": "application/json" },
|
|
43
|
-
body: JSON.stringify({
|
|
44
|
-
jsonrpc: "2.0",
|
|
45
|
-
id: 1,
|
|
46
|
-
method: "getDelegationStatus",
|
|
47
|
-
params: [accountAddress],
|
|
48
|
-
}),
|
|
49
|
-
});
|
|
50
|
-
return (await response.json()).result;
|
|
51
|
-
};
|
|
52
|
-
web3_js_1.Connection.prototype.getLatestBlockhashForTransaction =
|
|
53
|
-
async function (transaction, options) {
|
|
52
|
+
async getLatestBlockhashForTransaction(transaction, options) {
|
|
54
53
|
const writableAccounts = getWritableAccounts(transaction);
|
|
55
54
|
const blockHashResponse = await fetch(this.rpcEndpoint, {
|
|
56
55
|
method: "POST",
|
|
@@ -64,60 +63,63 @@ web3_js_1.Connection.prototype.getLatestBlockhashForTransaction =
|
|
|
64
63
|
});
|
|
65
64
|
const blockHashData = await blockHashResponse.json();
|
|
66
65
|
return blockHashData.result;
|
|
67
|
-
};
|
|
68
|
-
web3_js_1.Connection.prototype.prepareTransaction = async function (transaction, options) {
|
|
69
|
-
const blockHashData = await this.getLatestBlockhashForTransaction(transaction, options);
|
|
70
|
-
transaction.recentBlockhash = blockHashData.blockhash;
|
|
71
|
-
return transaction;
|
|
72
|
-
};
|
|
73
|
-
web3_js_1.Connection.prototype.sendTransaction = async function (transaction, signersOrOptions, options) {
|
|
74
|
-
const sendOpts = Array.isArray(signersOrOptions)
|
|
75
|
-
? (options ?? undefined)
|
|
76
|
-
: (signersOrOptions ?? undefined);
|
|
77
|
-
const latestBlockhash = await this.getLatestBlockhashForTransaction(transaction, sendOpts);
|
|
78
|
-
transaction.recentBlockhash = latestBlockhash.blockhash;
|
|
79
|
-
transaction.lastValidBlockHeight =
|
|
80
|
-
latestBlockhash.lastValidBlockHeight;
|
|
81
|
-
if (Array.isArray(signersOrOptions)) {
|
|
82
|
-
transaction.sign(...signersOrOptions);
|
|
83
|
-
}
|
|
84
|
-
const wireTransaction = transaction.serialize();
|
|
85
|
-
return this.sendRawTransaction(wireTransaction, sendOpts);
|
|
86
|
-
};
|
|
87
|
-
web3_js_1.Connection.prototype.sendAndConfirmTransaction = async function (transaction, signers, options) {
|
|
88
|
-
const signature = await this.sendTransaction(transaction, signers, options);
|
|
89
|
-
let status;
|
|
90
|
-
const { recentBlockhash, lastValidBlockHeight, minNonceContextSlot, nonceInfo, } = transaction;
|
|
91
|
-
if (recentBlockhash !== undefined && lastValidBlockHeight !== undefined) {
|
|
92
|
-
status = (await this.confirmTransaction({
|
|
93
|
-
abortSignal: options?.abortSignal,
|
|
94
|
-
signature,
|
|
95
|
-
blockhash: recentBlockhash,
|
|
96
|
-
lastValidBlockHeight,
|
|
97
|
-
}, options?.commitment)).value;
|
|
98
66
|
}
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
abortSignal: options?.abortSignal,
|
|
104
|
-
minContextSlot: minNonceContextSlot,
|
|
105
|
-
nonceAccountPubkey,
|
|
106
|
-
nonceValue: nonceInfo.nonce,
|
|
107
|
-
signature,
|
|
108
|
-
}, options?.commitment)).value;
|
|
67
|
+
async prepareTransaction(transaction, options) {
|
|
68
|
+
const blockHashData = await this.getLatestBlockhashForTransaction(transaction, options);
|
|
69
|
+
transaction.recentBlockhash = blockHashData.blockhash;
|
|
70
|
+
return transaction;
|
|
109
71
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.
|
|
72
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
73
|
+
if (transaction instanceof web3_js_1.Transaction) {
|
|
74
|
+
const latestBlockhash = await this.getLatestBlockhashForTransaction(transaction);
|
|
75
|
+
transaction.recentBlockhash = latestBlockhash.blockhash;
|
|
76
|
+
transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
|
|
77
|
+
if (Array.isArray(signersOrOptions)) {
|
|
78
|
+
transaction.sign(...signersOrOptions);
|
|
79
|
+
}
|
|
80
|
+
const wireTx = transaction.serialize();
|
|
81
|
+
return this.sendRawTransaction(wireTx, options);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return super.sendTransaction(transaction, signersOrOptions);
|
|
85
|
+
}
|
|
113
86
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
87
|
+
async sendAndConfirmTransaction(transaction, signers, options) {
|
|
88
|
+
const signature = await this.sendTransaction(transaction, signers, options);
|
|
89
|
+
let status;
|
|
90
|
+
const { recentBlockhash, lastValidBlockHeight, minNonceContextSlot, nonceInfo, } = transaction;
|
|
91
|
+
if (recentBlockhash !== undefined && lastValidBlockHeight !== undefined) {
|
|
92
|
+
status = (await this.confirmTransaction({
|
|
93
|
+
abortSignal: options?.abortSignal,
|
|
94
|
+
signature,
|
|
95
|
+
blockhash: recentBlockhash,
|
|
96
|
+
lastValidBlockHeight,
|
|
97
|
+
}, options?.commitment)).value;
|
|
98
|
+
}
|
|
99
|
+
else if (minNonceContextSlot !== undefined && nonceInfo !== undefined) {
|
|
100
|
+
const { nonceInstruction } = nonceInfo;
|
|
101
|
+
const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
|
|
102
|
+
status = (await this.confirmTransaction({
|
|
103
|
+
abortSignal: options?.abortSignal,
|
|
104
|
+
minContextSlot: minNonceContextSlot,
|
|
105
|
+
nonceAccountPubkey,
|
|
106
|
+
nonceValue: nonceInfo.nonce,
|
|
107
|
+
signature,
|
|
108
|
+
}, options?.commitment)).value;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
status = (await this.confirmTransaction(signature, options?.commitment))
|
|
112
|
+
.value;
|
|
113
|
+
}
|
|
114
|
+
if (status.err != null) {
|
|
115
|
+
throw new web3_js_1.SendTransactionError({
|
|
116
|
+
action: "send",
|
|
117
|
+
signature,
|
|
118
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return signature;
|
|
120
122
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
}
|
|
124
|
+
exports.ConnectionMagicRouter = ConnectionMagicRouter;
|
|
123
125
|
//# sourceMappingURL=magic-router.js.map
|
package/lib/magic-router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"magic-router.js","sourceRoot":"","sources":["../src/magic-router.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"magic-router.js","sourceRoot":"","sources":["../src/magic-router.ts"],"names":[],"mappings":";;;AAkBA,kDAgBC;AAlCD,6CAWyB;AAOzB,SAAgB,mBAAmB,CAAC,WAAwB;IAC1D,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE3C,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;QACzB,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,MAAM,WAAW,IAAI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