receive only once and correctly if registrar accidentally sends twice

also style fix
This commit is contained in:
stjet
2025-01-24 15:34:43 +00:00
parent 1bdd6c11f6
commit dfc3290837
3 changed files with 22 additions and 6 deletions

8
package-lock.json generated
View File

@@ -8,7 +8,7 @@
"name": "test",
"version": "0.0.1",
"dependencies": {
"banani": "^1.0.5",
"banani": "^1.0.7",
"banani-bns": "^0.0.9",
"mongodb": "^6.10.0",
"qrcode": "^1.5.4"
@@ -1120,9 +1120,9 @@
"license": "MIT"
},
"node_modules/banani": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/banani/-/banani-1.0.6.tgz",
"integrity": "sha512-wB4nijscW0g18aojQqOm4Lqghg9TDHGQe+AnravbZoH37c3fJXSgQV+pKzBqpT3VIzcASfOjFyAqmUsTDWREHA==",
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/banani/-/banani-1.0.8.tgz",
"integrity": "sha512-3yO8ywvWsEwI/r0Jvr9EhWN1pdLvw9D+W7gM4tBGnMs0mkug7jXsyCLX33F0jUOniAAJvDX8JXHe/WCq/RwwPA==",
"license": "MIT",
"dependencies": {
"blake2b": "^2.1.4"

View File

@@ -12,7 +12,22 @@
if (browser && resolve_to.startsWith("ban_") && resolve_to.length === 64) {
const rpc = new window.bns.banani.RPC("https://kaliumapi.appditto.com/api");
const wallet = new window.bns.banani.Wallet(rpc, seed);
await wallet.receive_all();
const hashes = (await wallet.get_account_receivable()).blocks;
const infos = (await rpc.get_blocks(hashes)).blocks;
//in case registrar accidentally sends the domain twice, only the first send (with lowest height) will be valid, so receive that
//BUT kalium rpc doesn't return height yet (augh) so we'll go for the one with the higher balance (since that was almost certainly sent first)
let to_receive;
for (const hash of hashes) {
const balance = BigInt(infos[hash].balance);
if (!to_receive || balance > to_receive?.balance) {
to_receive = {
hash,
balance,
};
}
console.log(to_receive, balance);
}
await wallet.receive(to_receive.hash);
const domain_manager = new window.bns.DomainAccountManager(rpc, wallet);
await domain_manager.declare_domain_resolve_to(resolve_to);
progress = Progress.Done;

View File

@@ -59,7 +59,8 @@
<style>
#main {
height: 100vh;
min-height: 100vh;
height: 100%;
box-sizing: border-box;
padding: 10px;
background-color: var(--green);