Skip to content

Commit

Permalink
refactor: try make better
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonstudio committed May 14, 2024
1 parent 59faec5 commit efda2d5
Show file tree
Hide file tree
Showing 21 changed files with 515 additions and 399 deletions.
52 changes: 25 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ serde_json = "1.0.116"
serde-wasm-bindgen = "0.6.5"
serde_with = "3.7.0"
js-sys = "0.3.69"
tsify = "0.4.5"
gloo-utils = { version = "0.2", features = ["serde"] }
tsify = { version = "0.4.5", features = ["js"] }
anyhow = { version = "1.0.56", features = ["backtrace"] }
23 changes: 13 additions & 10 deletions examples/etching.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { SpacedRune, Terms, Etching } from '../runestone/index.js';
import { SpacedRune, Terms, Etching, Rune } from '../runestone/index.js';

const spacedRune = SpacedRune.fromString('Z•Z•Z•Z•Z•FEHU•Z•Z•Z•Z•Z');
const etching = new Etching(spacedRune);
console.log(JSON.stringify(etching));

etching.terms = new Terms(420n, 2n);
etching.divisibility = 2;
etching.premine = 100n;
etching.symbol = '?';
etching.turbo = false;
console.log(JSON.stringify(etching));
const terms = new Terms({ amount: 420n, cap: 2n });
console.log(spacedRune.rune);
const etching = new Etching({
rune: spacedRune.rune,
spacers: spacedRune.spacers,
premine: 100n,
terms: new Terms({ amount: 420n, cap: 2n }),
divisibility: 2,
symbol: '?',
turbo: true,
});
console.log(etching.toJSON());
6 changes: 4 additions & 2 deletions examples/rune.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Rune } from '../runestone/index.js';

const rune = new Rune(67090369340599840949n);

console.log('value:', rune.value);
rune.value = 67090369340599840950n;
console.log('value:', rune.value, rune.toString());

console.log('isReserved:', rune.isReserved());
console.log('name:', rune.toString());
console.log('commitment:', rune.commitment());
console.log('json:', JSON.stringify(rune));
console.log('json:', rune.toJSON());

console.log(Rune.firstRuneHeight('main'));
console.log(Rune.fromString('ZZZZZFEHUZZZZZ').value);
4 changes: 4 additions & 0 deletions examples/rune_id.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { RuneId } from '../runestone/index.js';

const runeId = new RuneId(840000n, 1);
console.log('json:', JSON.stringify(runeId));

runeId.tx = 2;
console.log('json:', JSON.stringify(runeId));

console.log('runeId:', runeId.toString(), runeId.block, runeId.tx);
console.log('delta:', runeId.delta(new RuneId(840001n, 10000)).start);
console.log('next:', runeId.next(1n, 1).toString());
Expand Down
75 changes: 35 additions & 40 deletions examples/runestone.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,55 @@ const tx = {
value: 0,
},
],
// input: [],
};

const runestone = Runestone.decipher(tx);

console.log('runestone etching:', JSON.stringify(runestone, null, 2));
console.log('runestone etching:', runestone.toJSON());
console.log(runestone.encipher());

console.log(
'runestone mint:',
JSON.stringify(
Runestone.decipher({
output: [
{
script_pubkey:
'51206da59bfd6b08756375d62e8e38e55db6edaaf20a12b3e6e7f3aa36afcfc3c931',
value: 0,
},
{
script_pubkey: '6a5d0914f8a83314f0031600',
value: 0,
},
],
}),
null,
2
)
Runestone.decipher({
output: [
{
script_pubkey:
'51206da59bfd6b08756375d62e8e38e55db6edaaf20a12b3e6e7f3aa36afcfc3c931',
value: 0,
},
{
script_pubkey: '6a5d0914f8a83314f0031600',
value: 0,
},
],
}).toJSON()
);

console.log(
'runestone edicts:',
JSON.stringify(
Runestone.decipher({
output: [
{
script_pubkey: '6a5d0800c0a23301d00f00',
value: 0,
},
],
}),
null,
2
)
Runestone.decipher({
output: [
{
script_pubkey: '6a5d0800c0a23301d00f00',
value: 0,
},
],
}).toJSON()
);

const rs = new Runestone();

const terms = new Terms(69n, 420n);
const etching = new Etching(SpacedRune.fromString('HI•JEASON'));
etching.premine = 100n;
etching.terms = terms;
rs.etching = etching;
const spacedRune = SpacedRune.fromString('HI•JEASON');
const etching = new Etching({
rune: 1n,
spacers: 2,
premine: 100n,
// terms: new Terms({ amount: 69n, cap: 420n }),
});
const rs = new Runestone({
etching,
});
console.log(rs.toJSON());

const edict = new Edict(new RuneId(840000n, 1), 10000n, 0);
rs.edicts = [edict];
console.log(JSON.stringify(rs, null, 2));
console.log(rs.encipher());
console.log(rs.toJSON());
console.log(rs.encipher());
7 changes: 5 additions & 2 deletions examples/spaced_rune.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { SpacedRune, Rune } from '../runestone/index.js';
const rune = new Rune(67090369340599840949n);
const spacedRune = new SpacedRune(rune, 7967);

console.log('spaced rune:', spacedRune.toString());
console.log('spaced rune:', JSON.stringify(spacedRune));
console.log('spaced rune:', spacedRune.name);
console.log('spaced rune:', spacedRune.toJSON());
console.log(
'rune value:',
SpacedRune.fromString('Z•Z•Z•Z•Z•FEHU•Z•Z•Z•Z•Z').rune.value
Expand All @@ -13,3 +13,6 @@ console.log(
'rune spacers:',
SpacedRune.fromString('Z•Z•Z•Z•Z•FEHU•Z•Z•Z•Z•Z').spacers
);

spacedRune.spacers = 8888;
console.log('spaced rune:', spacedRune.name);
12 changes: 10 additions & 2 deletions examples/terms.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { Range, Terms } from '../runestone/index.js';

const terms = new Terms(420n, 2n);
console.log(JSON.stringify(new Terms()));
const terms = new Terms({
amount: 420n,
cap: 2n,
offset: { start: 1n },
});
console.log(JSON.stringify(terms));

terms.amount = 20202n;
console.log(JSON.stringify(terms));

terms.height = new Range(1n, 2n);
console.log(JSON.stringify(terms));

terms.offset = new Range(1n, 2n);
console.log(JSON.stringify(terms));
console.log(JSON.stringify(terms));
10 changes: 2 additions & 8 deletions src/create_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@ use super::ord::{
fee_rate::FeeRate, inscription_id::InscriptionId, transaction_builder::Target,
transaction_builder::TransactionBuilder,
};
use super::transaction::Transaction;
use super::*;
use bitcoin::{
address::{Address, NetworkUnchecked},
Amount, OutPoint, TxOut,
};
use ordinals::SatPoint;
use serde::{Deserialize, Serialize};
use std::{
collections::{BTreeMap, BTreeSet},
str::FromStr,
};
use tsify::Tsify;
use wasm_bindgen::prelude::*;
use std::collections::{BTreeMap, BTreeSet};
use wasm_bindgen::throw_str;

#[derive(Default, Serialize, Deserialize, Tsify)]
Expand Down
Loading

0 comments on commit efda2d5

Please sign in to comment.