Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sat functions #5

Open
elocremarc opened this issue Mar 2, 2024 · 0 comments
Open

Add sat functions #5

elocremarc opened this issue Mar 2, 2024 · 0 comments

Comments

@elocremarc
Copy link
Member

elocremarc commented Mar 2, 2024

It would be nice if this library also had sat functions like going between number, name, degree, percentile. Also calculating sat ranges and rarity if its a block 9 etc.

Once we have sat functions we can update the sat endpoint functions to take any value of sat. When we made the sat endpoint I suggested to raph we should take away the ability to pass it notation and sat name so explorers won't have the potential to not support them and break inscriptions. ordinals/ord#2732

If we implement this logic on this library then we simplify the logic of ordinals explorers while still getting the ability to interact with the sat endpoint with sat names/notation/degree.

Here is a Sat class I started

     
class Sat {
static SUPPLY = BigInt(2099999997690000);

constructor(value) {
    this.value = BigInt(value);
}

name() {
    let x = Sat.SUPPLY - this.value;
    let name = '';
    while (x > 0) {
    name += 'abcdefghijklmnopqrstuvwxyz'[
        Number((x - BigInt(1)) % BigInt(26))
    ].toString();
    x = (x - BigInt(1)) / BigInt(26);
    }
    return name.split('').reverse().join('');
}

static fromName(s) {
    let x = BigInt(0);
    for (let i = 0; i < s.length; i++) {
    const c = s[i];
    if (c >= 'a' && c <= 'z') {
        x = x * BigInt(26) + BigInt(c.codePointAt(0) - 'a'.codePointAt(0) + 1);
    } else {
        throw new Error(`invalid character in sat name: ${c}`);
    }
    }
    if (x > Sat.SUPPLY) {
    throw new Error('sat name out of range');
    }
    return new Sat(Sat.SUPPLY - x);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant