Adapt transfer code for new message accounts

Change-Id: I11178c5ce1cb6c00f67eb815b67660f976c89067
This commit is contained in:
Hendrik Hofstadt 2021-08-09 21:33:08 +02:00
parent 924d9679d8
commit 78c5d343da
2 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,6 @@
import Wallet from "@project-serum/sol-wallet-adapter";
import {
Connection,
Connection, Keypair,
PublicKey,
SystemProgram,
Transaction,
@ -99,24 +99,22 @@ export async function attestFromSolana(
// TODO: pass in connection
// Add transfer instruction to transaction
const { attest_ix, emitter_address } = await import("token-bridge");
const messageKey = Keypair.generate();
const ix = ixFromRust(
attest_ix(
SOL_TOKEN_BRIDGE_ADDRESS,
SOL_BRIDGE_ADDRESS,
payerAddress,
mintAddress,
decimals,
messageKey.publicKey.toString(),
mintAddress, // TODO: mint_metadata: what address is this supposed to be?
mintAddress, // TODO: spl_metadata: what address is this supposed to be?
"", // TODO: lookup symbol
"", //: TODO: lookup name
nonce
nonce,
)
);
const transaction = new Transaction().add(transferIx, ix);
const { blockhash } = await connection.getRecentBlockhash();
transaction.recentBlockhash = blockhash;
transaction.feePayer = new PublicKey(payerAddress);
transaction.partialSign(messageKey);
// Sign transaction, broadcast, and confirm
const signed = await wallet.signTransaction(transaction);
console.log("SIGNED", signed);

View File

@ -1,7 +1,7 @@
import Wallet from "@project-serum/sol-wallet-adapter";
import { Token, TOKEN_PROGRAM_ID } from "@solana/spl-token";
import {
Connection,
Connection, Keypair,
PublicKey,
SystemProgram,
Transaction,
@ -163,11 +163,14 @@ export async function transferFromSolana(
[],
Number(amountParsed)
);
let messageKey = Keypair.generate();
const ix = ixFromRust(
transfer_native_ix(
SOL_TOKEN_BRIDGE_ADDRESS,
SOL_BRIDGE_ADDRESS,
payerAddress,
messageKey.publicKey.toString(),
fromAddress,
mintAddress,
nonce,
@ -181,6 +184,7 @@ export async function transferFromSolana(
const { blockhash } = await connection.getRecentBlockhash();
transaction.recentBlockhash = blockhash;
transaction.feePayer = new PublicKey(payerAddress);
transaction.partialSign(messageKey);
// Sign transaction, broadcast, and confirm
const signed = await wallet.signTransaction(transaction);
console.log("SIGNED", signed);