Skip to content

Commit

Permalink
solana tool
Browse files Browse the repository at this point in the history
  • Loading branch information
v1xingyue committed Dec 19, 2023
1 parent a65c6c8 commit 7046aa0
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 64 deletions.
135 changes: 133 additions & 2 deletions examples/solana-tool/contract/solana-counter/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/solana-tool/contract/solana-counter/tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ error: not a directory: '/home/chandan/.local/share/solana/install/releases/1.10
清理 缓存框架

rm -rf ~/.cache/solana/*



https://docs.solana.com/developing/clients/javascript-api
43 changes: 27 additions & 16 deletions examples/solana-tool/src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
Connection,
Keypair,
sendAndConfirmRawTransaction,
sendAndConfirmTransaction,
Transaction
Transaction,
TransactionMessage
} from "@solana/web3.js"

// import nacl from "tweetnacl"
import nacl from "tweetnacl"

// https://docs.solana.com/developing/clients/javascript-reference

Expand All @@ -30,26 +31,36 @@ chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
if (message.action === "executeTransaction") {
let connection = new Connection(rpcUrl, "confirmed")
// const client = new SuiClient({ url: getFullnodeUrl("testnet") })
const transactionBuffer = message.transactionBytes as Buffer
console.log("transactionBytes -> ", transactionBuffer)
const v1MessageBuffer = message.transactionBytes as Uint8Array
console.log("transactionBytes -> ", v1MessageBuffer)
// const txb = TransactionBlock.from(transactionBytes)
const privateKeyStr = await storage.get("secret")
const privateKeyBytes = Buffer.from(privateKeyStr, "hex")

const signer = Keypair.fromSecretKey(privateKeyBytes)
// const signature = nacl.sign.detached(
// Buffer.from(transactionBuffer),
// signer.secretKey
// )
// console.log("signature->", signature)

const transaction = Transaction.from(Buffer.from(transactionBuffer))
console.log("reload transaction: ", transaction)
// transaction.addSignature(signer.publicKey, Buffer.from("jellyfish"))
// const messageV0 = TransactionMessage.decompile(v1MessageBuffer)
// // const transaction = Transaction.from(Buffer.from(transactionBuffer))
// console.log("reload transaction: ", transaction)
// transaction.addSignature(signer.publicKey, Buffer.from(signature))
// console.log("signed transaction: ", transaction)

// // TODO: sign transaction and send it to solana
// // https://docs.solana.com/developing/clients/javascript-reference
// const tx = await connection.sendRawTransaction(
// transaction.serialize({
// verifySignatures: true,
// requireAllSignatures: true
// }),
// {
// skipPreflight: true
// }
// )
// console.log(tx)

const tx = await sendAndConfirmTransaction(connection, transaction, [
signer
])
// const tx = await sendAndConfirmTransaction(connection, transaction, [
// signer
// ])
// console.log("transaction detail : ", tx)

// // sendResponse({ privateKeyBytes })
Expand Down
Loading

0 comments on commit 7046aa0

Please sign in to comment.