-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (35 loc) · 1.42 KB
/
index.js
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
const solanaWeb3 = require('@solana/web3.js');
const nacl=require("tweetnacl")
const bs58=require("bs58")
module.exports = {
id: "solana",
setup: async () => {
const connection = new solanaWeb3.Connection(global.config.gateways.solanaRpc);
return {
async verifySignature(signerAddress, message, signature) {
return await nacl
.sign
.detached
.verify(
new TextEncoder().encode(message),
bs58.decode(signature),
bs58.decode(signerAddress)
)
},
async readTxById(id) {
const transaction = await connection.getParsedTransaction(id, "finalized");
const transferInstruction = (transaction?.transaction?.message?.instructions || []).find(
(instruction) => instruction?.program == "system" && instruction?.parsed?.type == "transfer"
);
if (!transferInstruction) { return null }
return {
coin: "SOL",
timestamp: transaction?.blockTime,
amount: transferInstruction?.parsed?.info?.lamports,
from: transferInstruction?.parsed.info?.source,
to: transferInstruction?.parsed?.info?.destination,
}
}
}
}
}