Skip to content

Commit 84c4196

Browse files
committed
feat: type agnostic seq endpoint
1 parent 1cc568d commit 84c4196

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,31 @@ export async function handle(state, action) {
8282
}
8383
```
8484

85+
## Lambda Sequencer
86+
87+
8588
#### Testnet sequencer endpoint: https://wvm-lambda-0755acbdae90.herokuapp.com/
8689

90+
### Methods
91+
92+
#### Transaction Type 1: deploy contract
93+
94+
```bash
95+
curl -X POST https://wvm-lambda-0755acbdae90.herokuapp.com/deploy -H "Content-Type: application/json" -d '{"txid":"$CONTRACT_ADDRESS"}'
96+
```
97+
98+
#### Transaction Type 2: send interaction
99+
```bash
100+
curl -X POST https://wvm-lambda-0755acbdae90.herokuapp.com/transactions -H "Content-Type: application/json" -d '{"txid":"$INTERACTION_TXID"}'
101+
```
102+
103+
#### Type Agnostic Method: handles both types 1 and 2 automatically
104+
105+
106+
```bash
107+
curl -X POST https://wvm-lambda-0755acbdae90.herokuapp.com/tx -H "Content-Type: application/json" -d '{"txid":"$TXID"}'
108+
```
109+
87110
For more code examples on how to interact with the Lambda sequencer (deploying contracts, sending interactions, reading state), check the code snippets available in [examples](./examples).
88111

89112
## License

sequencer/server.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cors from "cors";
55
import { deployContract } from "./utils/deploy.js";
66
import { evaluateTx } from "./utils/tx.js";
77
import { psGetState } from "./utils/planetscale.js";
8+
import { handleTx } from "./utils/auto-tx-handler.js";
89

910
const app = express();
1011
const port = process.env.PORT || 3000;
@@ -71,5 +72,19 @@ app.post("/transactions", async (req, res) => {
7172
}
7273
});
7374

75+
// auto tx handler, type agnostic (handles both type 1 and 2)
76+
app.post("/tx", async (req, res) => {
77+
try {
78+
const { txid } = req.body;
79+
80+
const tx = await handleTx(txid);
81+
82+
res.send(tx);
83+
} catch (error) {
84+
console.log(error);
85+
return {result: false}
86+
}
87+
});
88+
7489

7590
app.listen(port, () => console.log("Server started"));

sequencer/utils/auto-tx-handler.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { evaluateTx } from "./tx.js";
2+
import { deployContract } from "./deploy.js";
3+
import { decodeCalldata } from "./web3-utils.js";
4+
5+
export async function handleTx(txid) {
6+
try {
7+
const tx = await decodeCalldata(txid);
8+
const data = tx.data;
9+
10+
if (data.type == 2) {
11+
await evaluateTx(txid);
12+
return;
13+
} else if (data.type == 1) {
14+
await deployContract(txid);
15+
return;
16+
}
17+
} catch (err) {
18+
return { result: false };
19+
}
20+
}

0 commit comments

Comments
 (0)