forked from yug49/PyPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-order-state.js
More file actions
140 lines (130 loc) · 5.04 KB
/
test-order-state.js
File metadata and controls
140 lines (130 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const { createPublicClient, http } = require("viem");
const { worldchainSepolia } = require("viem/chains");
async function checkOrderState() {
console.log("🔍 Checking Order State on Blockchain");
console.log("====================================");
const rpcUrl = "https://testnet.evm.nodes.onflow.org";
const contractAddress = "0x756523eDF6FfC690361Df3c61Ec3719F77e9Aa1a";
// This is the orderId from our test
const orderId =
"0x7751f54d9c95c000000000000000000000000000000000000000000000000000";
const publicClient = createPublicClient({
chain: worldchainSepolia,
transport: http(rpcUrl),
});
// OrderProtocol contract ABI for reading orders
const contractABI = [
{
inputs: [
{
internalType: "bytes32",
name: "_orderId",
type: "bytes32",
},
],
name: "getOrder",
outputs: [
{
components: [
{
internalType: "address",
name: "maker",
type: "address",
},
{
internalType: "address",
name: "taker",
type: "address",
},
{
internalType: "uint256",
name: "amount",
type: "uint256",
},
{
internalType: "address",
name: "tokenAddress",
type: "address",
},
{
internalType: "uint256",
name: "startPrice",
type: "uint256",
},
{
internalType: "uint256",
name: "endPrice",
type: "uint256",
},
{
internalType: "string",
name: "recipientUpiAddress",
type: "string",
},
{
internalType: "enum OrderProtocol.OrderStatus",
name: "status",
type: "uint8",
},
{
internalType: "uint256",
name: "acceptedPrice",
type: "uint256",
},
{
internalType: "address",
name: "acceptedBy",
type: "address",
},
],
internalType: "struct OrderProtocol.Order",
name: "",
type: "tuple",
},
],
stateMutability: "view",
type: "function",
},
];
try {
console.log(`📖 Reading order ${orderId} from contract...`);
const orderData = await publicClient.readContract({
address: contractAddress,
abi: contractABI,
functionName: "getOrder",
args: [orderId],
});
console.log("✅ Order found on blockchain:");
console.log(` Maker: ${orderData[0]}`);
console.log(` Taker: ${orderData[1]}`);
console.log(` Amount: ${orderData[2].toString()}`);
console.log(` Token: ${orderData[3]}`);
console.log(` Start Price: ${orderData[4].toString()}`);
console.log(` End Price: ${orderData[5].toString()}`);
console.log(` UPI: ${orderData[6]}`);
console.log(
` Status: ${orderData[7]} (0=Active, 1=Accepted, 2=Fulfilled, 3=Cancelled)`
);
console.log(` Accepted Price: ${orderData[8].toString()}`);
console.log(` Accepted By: ${orderData[9]}`);
if (orderData[7] === 0) {
console.log("✅ Order is ACTIVE - ready for acceptance");
} else if (orderData[7] === 1) {
console.log("❌ Order is already ACCEPTED");
} else if (orderData[7] === 2) {
console.log("❌ Order is already FULFILLED");
} else if (orderData[7] === 3) {
console.log("❌ Order is CANCELLED");
}
} catch (error) {
if (error.message.includes("OrderProtocol__OrderNotFound")) {
console.log("❌ Order NOT found on blockchain");
console.log(
" This means the order was created in the database but never posted to the blockchain"
);
} else {
console.error("❌ Error reading order:", error.message);
}
}
}
checkOrderState().catch(console.error);