Skip to content

Commit

Permalink
Merge pull request #8 from bitfinity-network/ordinalsV2
Browse files Browse the repository at this point in the history
Ordinals v2
  • Loading branch information
kobby-pentangeli authored Mar 7, 2024
2 parents 7ade8b0 + d9a8816 commit 0139d4e
Show file tree
Hide file tree
Showing 30 changed files with 1,154 additions and 228 deletions.
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: 'type: bug'
---

**Describe the bug**
A clear and concise description of what the bug is.

**Please provide the steps to reproduce and if possible a minimal demo of the problem.**

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots / logs**
If applicable, add screenshots and/or logs to help explain your problem.

**Relevant environment details:**

- OS: e.g. MacOS, Windows, etc.
- etc

**Additional context**
Add any other context about the problem here.
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: 'type: feature-proposal'
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when...

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
26 changes: 26 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Motivation
<!-- Please mention the issue fixed by this PR or detailed motivation -->
Closes #
<!-- `Closes #XXXX, closes #XXXX, ...` links mentioned issues to this PR and automatically closes them when it's merged -->

## Changes
<!-- Please describe in detail the changes made -->

## Test Plan
<!-- Please specify how these changes were tested
(e.g. unit tests, manual testing, etc.) -->

## TODO
<!-- This section should be removed when all items are complete -->
- [ ] Explain motivation or link existing issue(s)
- [ ] Test changes and document test plan
- [ ] Update documentation as needed

## DevOps Notes
<!-- Please uncheck these items as applicable to make DevOps aware of changes that may affect releases -->
- [x] This PR does not require configuration changes (e.g., environment variables, GitHub secrets, VM resources)
- [x] This PR does not affect public APIs
- [x] This PR does not rely on a new version of external services
- [x] This PR does not make changes to log messages (which monitoring infrastructure may rely on)

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
98 changes: 73 additions & 25 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,94 @@
name: build-test

on:
pull_request:
push:
branches:
- main
paths-ignore:
- "*.md"
pull_request:
types: [opened, reopened, synchronize]

env:
CARGO_TERM_COLOR: always

jobs:
build-test:
name: Build and Test
check:
name: Check with ${{matrix.features}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toolchain: [stable]
os: [ubuntu]
features: [--all-features, --no-default-features]
steps:
- uses: actions/checkout@v4

- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: actions/checkout@main
- name: Install rust
uses: actions-rs/toolchain@v1
with:
components: clippy, rustfmt
targets: i686-unknown-linux-gnu
toolchain: ${{matrix.toolchain}}
override: true
- name: Check
uses: actions-rs/cargo@v1
with:
command: check
args: --all-targets ${{matrix.features}}

- name: rustfmt
run: |
cargo fmt --all --check
test:
name: Test Rust ${{matrix.toolchain}} on ${{matrix.os}}
runs-on: ${{matrix.os}}-latest
strategy:
fail-fast: false
matrix:
toolchain: [stable, nightly]
os: [ubuntu]
steps:
- uses: actions/checkout@main
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{matrix.toolchain}}
override: true
- name: Test
uses: actions-rs/cargo@v1
with:
command: test

- name: clippy
run: |
cargo clippy --all-features --all-targets -- -D warnings
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Install minimal nightly with clippy
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: clippy
override: true

- name: build
run: |
cargo build
- name: Clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all -- -D clippy::all -D warnings

- name: test
run: |
./scripts/test.sh
rustfmt:
name: rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Install minimal nightly with rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt
override: true

- name: test i686-unknown-linux-gnu
run: |
sudo apt install gcc-multilib
./scripts/test.sh --target i686-unknown-linux-gnu
- name: rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ Cargo.lock
*.pdb

# IDE files
.idea
.idea
.DS_Store
.vscode
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ categories = ["cryptography::cryptocurrencies"]
license = "MIT"
version = "0.1.0"
authors = ["Finity Technologies"]
description = "A library for working with BRC-20 tokens."
description = "A library for working with Ordinal inscriptions."
repository = "https://github.com/bitfinity-network/ord-rs"
documentation = "https://docs.rs/ord-rs"
edition = "2021"

[dependencies]
async-trait = "0.1"
bitcoin = { version = "0.31", features = ["rand"] }
ciborium = "0.2"
http = "1"
log = "0.4"
rand = { version = "0.8" }
serde = { version = "1", features = ["derive"] }
Expand All @@ -26,7 +29,11 @@ env_logger = "0.11"
hex = "0.4"
hex-literal = "0.4"
rand = { version = "0.8" }
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls", "trust-dns"] }
reqwest = { version = "0.11", default-features = false, features = [
"json",
"rustls-tls",
"trust-dns",
] }
tokio = { version = "1", features = ["full"] }

[[example]]
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# ord-rs Rust
# ord-rs

A library for working with Ordinal inscriptions.

## Status

### Done

- [x] [inscription](src/inscription.rs): `Brc20` and `Nft` inscription types.
- [x] [wallet](src/wallet.rs): Transaction builder, signer, and parser.

### TODO

- [ ] [indexer](src/indexer.rs): Scans the Bitcoin blockchain to catalog, organize, and provide information about Ordinal inscriptions.

------------------------------------------------------------------------------------------------------------------------------

[![build-test](https://github.com/bitfinity-network/ord-rs/actions/workflows/build-test.yml/badge.svg)](https://github.com/bitfinity-network/ord-rs/actions/workflows/build-test.yml)

Expand Down Expand Up @@ -102,6 +117,11 @@ let inscription: Brc20 = OrdParser::parse(&transaction).unwrap().unwrap();
assert_eq!(inscription, Brc20::transfer("mona", 100));
```

## References

- [Ordinal Theory](https://docs.ordinals.com/inscriptions.html)
- [BRC-20 Standard](https://domo-2.gitbook.io/brc-20-experiment/)

## License

See license in [LICENSE](./LICENSE)
46 changes: 26 additions & 20 deletions examples/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use argh::FromArgs;
use bitcoin::secp256k1::Secp256k1;
use bitcoin::{Address, Network, PrivateKey};
use log::{debug, info};
use ord_rs::brc20::Brc20;
use ord_rs::transaction::{CreateCommitTransactionArgs, RevealTransactionArgs};
use ord_rs::OrdTransactionBuilder;
use ord_rs::wallet::{CreateCommitTransactionArgs, RevealTransactionArgs};
use ord_rs::{Brc20, OrdTransactionBuilder};
use utils::rpc_client;

use crate::utils::{calc_fees, Fees};
Expand Down Expand Up @@ -84,14 +83,19 @@ async fn main() -> anyhow::Result<()> {
_ => panic!("invalid script type"),
};

let commit_tx = builder.build_commit_transaction(CreateCommitTransactionArgs {
inputs,
inscription: Brc20::deploy(ticker, amount, Some(limit), None),
txin_script_pubkey: sender_address.script_pubkey(),
leftovers_recipient: sender_address.clone(),
commit_fee,
reveal_fee,
})?;
let commit_tx = builder
.build_commit_transaction(
network,
CreateCommitTransactionArgs {
inputs,
inscription: Brc20::deploy(ticker, amount, Some(limit), None),
txin_script_pubkey: sender_address.script_pubkey(),
leftovers_recipient: sender_address.clone(),
commit_fee,
reveal_fee,
},
)
.await?;
debug!("commit transaction: {commit_tx:?}");

let commit_txid = if args.dry_run {
Expand All @@ -103,15 +107,17 @@ async fn main() -> anyhow::Result<()> {
info!("Commit transaction broadcasted: {}", commit_txid);

debug!("getting reveal transaction...");
let reveal_transaction = builder.build_reveal_transaction(RevealTransactionArgs {
input: ord_rs::transaction::TxInput {
id: commit_txid,
index: 0,
amount: commit_tx.reveal_balance,
},
recipient_address: sender_address,
redeem_script: commit_tx.redeem_script,
})?;
let reveal_transaction = builder
.build_reveal_transaction(RevealTransactionArgs {
input: ord_rs::wallet::TxInput {
id: commit_txid,
index: 0,
amount: commit_tx.reveal_balance,
},
recipient_address: sender_address,
redeem_script: commit_tx.redeem_script,
})
.await?;
debug!("reveal transaction: {reveal_transaction:?}");

if !args.dry_run {
Expand Down
46 changes: 26 additions & 20 deletions examples/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use argh::FromArgs;
use bitcoin::secp256k1::Secp256k1;
use bitcoin::{Address, Network, PrivateKey};
use log::{debug, info};
use ord_rs::brc20::Brc20;
use ord_rs::transaction::{CreateCommitTransactionArgs, RevealTransactionArgs};
use ord_rs::OrdTransactionBuilder;
use ord_rs::wallet::{CreateCommitTransactionArgs, RevealTransactionArgs};
use ord_rs::{Brc20, OrdTransactionBuilder};

use self::utils::rpc_client;
use crate::utils::{calc_fees, Fees};
Expand Down Expand Up @@ -79,14 +78,19 @@ async fn main() -> anyhow::Result<()> {
_ => panic!("invalid script type"),
};

let commit_tx = builder.build_commit_transaction(CreateCommitTransactionArgs {
inputs,
inscription: Brc20::mint(ticker, amount),
txin_script_pubkey: sender_address.script_pubkey(),
leftovers_recipient: sender_address.clone(),
commit_fee,
reveal_fee,
})?;
let commit_tx = builder
.build_commit_transaction(
network,
CreateCommitTransactionArgs {
inputs,
inscription: Brc20::mint(ticker, amount),
txin_script_pubkey: sender_address.script_pubkey(),
leftovers_recipient: sender_address.clone(),
commit_fee,
reveal_fee,
},
)
.await?;
debug!("commit transaction: {commit_tx:?}");

let commit_txid = if args.dry_run {
Expand All @@ -98,15 +102,17 @@ async fn main() -> anyhow::Result<()> {
info!("Commit transaction broadcasted: {}", commit_txid);

debug!("getting reveal transaction...");
let reveal_transaction = builder.build_reveal_transaction(RevealTransactionArgs {
input: ord_rs::transaction::TxInput {
id: commit_txid,
index: 0,
amount: commit_tx.reveal_balance,
},
recipient_address: sender_address,
redeem_script: commit_tx.redeem_script,
})?;
let reveal_transaction = builder
.build_reveal_transaction(RevealTransactionArgs {
input: ord_rs::wallet::TxInput {
id: commit_txid,
index: 0,
amount: commit_tx.reveal_balance,
},
recipient_address: sender_address,
redeem_script: commit_tx.redeem_script,
})
.await?;
debug!("reveal transaction: {reveal_transaction:?}");

if !args.dry_run {
Expand Down
Loading

0 comments on commit 0139d4e

Please sign in to comment.