Skip to content

Commit

Permalink
correctly fetched contract code expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
aristidesstaffieri committed Sep 21, 2023
1 parent 736cc1d commit 881f8c4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/atomic-swap/exchange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const Exchange = (props: ExchangeProps) => {
return;
}

setTxResultXDR(result.toXDR().toString());
setTxResultXDR(result.toString());
setStepCount((stepCount + 1) as StepCount);
} catch (error) {
console.log(error);
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/sign-auth-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export async function authorizeEntry(
}),
);

console.log(preimage.toXDR());
console.log(hash(preimage.toXDR()));
const signature = await signer(preimage.toXDR());
const publicKey = Address.fromScAddress(addrAuth.address()).toString();

Expand All @@ -63,6 +61,6 @@ export async function authorizeEntry(
},
);

addrAuth.signature(sigScVal);
addrAuth.signature(xdr.ScVal.scvVec([sigScVal]));
return entry;
}
11 changes: 7 additions & 4 deletions src/helpers/soroban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
scValToBigInt,
ScInt,
assembleTransaction,
hash,
} from "soroban-client";
import BigNumber from "bignumber.js";
import { StellarWalletsKit } from "stellar-wallets-kit";
Expand Down Expand Up @@ -241,18 +242,20 @@ export const buildContractAuth = async (
}),
);

const expirationKey = xdr.LedgerKey.expiration(
new xdr.LedgerKeyExpiration({ keyHash: hash(key.toXDR()) }),
);

// Fetch the current contract ledger seq
// eslint-disable-next-line no-await-in-loop
const entryRes = await server.getLedgerEntries(key);
const entryRes = await server.getLedgerEntries(expirationKey);
if (entryRes.entries && entryRes.entries.length) {
const parsed = xdr.LedgerEntryData.fromXDR(
entryRes.entries[0].xdr,
"base64",
);
// set auth entry to expire when contract data expires, but could any number of blocks in the future
console.log(parsed);
// expirationLedgerSeq = parsed.expiration().expirationLedgerSeq();
expirationLedgerSeq = 81365 + 1000000;
expirationLedgerSeq = parsed.expiration().expirationLedgerSeq();
} else {
throw new Error(ERRORS.CANNOT_FETCH_LEDGER_ENTRY);
}
Expand Down

0 comments on commit 881f8c4

Please sign in to comment.