Skip to content

Add sat functions #5

@elocremarc

Description

@elocremarc

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);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions