Comments (7)
@tuminzee i can't, but it's enough for my purposes: to run some txs on the contracts i deployed and await their completion and since im the only one interacting with them, it is enough, tho i also await until the target contract's data changes to the expected to confirm operation
from blueprint.
Might as well post these here:
export async function getSeqNo(provider: NetworkProvider, address: Address) {
if (await provider.isContractDeployed(address)) {
let res = await provider.api().runMethod((await provider.api().getLastBlock()).last.seqno, address, 'seqno');
return res.reader.readNumber();
} else {
return 0;
}
}
export async function waitSeqNoChange(provider: NetworkProvider, target: Address, previousSeqno: number) {
console.log(` - Waiting up to 45 seconds to confirm transaction`);
let successFlag = 0;
for (let attempt = 0; attempt < 45; attempt++) {
await sleep(1000);
const seqnoAfter = await getSeqNo(provider, target);
if (seqnoAfter > previousSeqno) {
successFlag = 1;
break;
};
}
if (successFlag) {
console.log(` - Sent transaction done successfully`);
return true;
} else {
console.log(` - Sent transaction didn't go through`);
return false;
}
}
export async function awaitConfirmation(fn: () => Promise<boolean>) {
console.log(` - Waiting up to 45 seconds to confirm operation`);
let successFlag = 0;
for (let attempt = 0; attempt < 45; attempt++) {
await sleep(1000);
let res = false
try {
res = await fn()
} catch {}
if (res) {
successFlag = 1
break
}
}
if (!successFlag) {
console.log(` - Error confirming operation`);
return false;
}
return true;
}
// example
const seqno = await getSeqNo(provider, provider.sender().address);
// ---------
// send tx here
// ---------
if (await waitSeqNoChange(provider, provider.sender().address, seqno)) {
if (await awaitConfirmation(async () => {
const data = await ctr.getData() // target ctr data
return data.stuff === 1 // what we expect to see
})) {
console.log(` - Successfully confirmed tx`)
} else {
console.log(` - Error confirming tx`)
}
}
from blueprint.
solved it by getting seqno
through provider.api().runMethod(address, 'seqno')
and waiting until it changes, nevertheless, it would be nice to have a more straightforward approach
from blueprint.
1/ these functions is under script
folder?
2/ should we add this in Blueprint in dafult?
from blueprint.
but how can you be sure that the seqno is mapped to your txs?
@sikvelsigma
from blueprint.
@sikvelsigma thank you for sharing the code, very helpful 👍🏼
from blueprint.
@howardpen9 having it by default would be a good option, also it makes sense to add it in the interactive menu? so user can select if they want it or not?
what do you think about it?
from blueprint.
Related Issues (20)
- stdlib template comment error
- how to update wrappers' files
- Test the Blueprint itself HOT 7
- Add testing in CI HOT 3
- Pass (sub)walletId in Mnemonic provider
- Rewrite Blueprint Framework Using Deno
- [email protected] HOT 1
- 9
- Document how to upgrade Tact version
- `blueprint build` wizard should have 'All Contracts' option
- Make it easier to understand when a contract execution fails with an exit code
- In cases of Cell underflow/overflow or other similar exit codes, contract's debug output doesn't show anything HOT 1
- ES modules support
- Referencing func code with 'import' in tact does not compile
- Add mathlib.fc library by default
- What TypeScript API is expected from Tact compiler?
- Make Tact a peer dependency in the generated package.json files for Blueprint projects HOT 1
- It seems updating FunC version using `blueprint set func` command won't work
- Fully support `tact.config.json` in Tact projects and move away from `wrappers/` (`compilables/`)
- Exception when running "blueprint run" command in version 0.22 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blueprint.