Skip to content

Commit

Permalink
feat: Add cmd example
Browse files Browse the repository at this point in the history
--story=1
  • Loading branch information
studyzy committed Apr 25, 2024
1 parent abaf3a5 commit fb88a65
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 3 deletions.
81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,91 @@

Bitcoin Rune protocol golang implement library.

### How to use
## How to use

```go
go get github.com/bxelab/runestone@latest
```

### Etching

Define a new Rune named *STUDYZY.GMAIL.COM*

```go
func testEtching() {
runeName := "STUDYZY.GMAIL.COM"
symbol := ''
myRune, err := runestone.SpacedRuneFromString(runeName)
if err != nil {
fmt.Println(err)
return
}
amt := uint128.From64(666666)
ca := uint128.From64(21000000)
etching := &runestone.Etching{
Rune: &myRune.Rune,
Spacers: &myRune.Spacers,
Symbol: &symbol,
Terms: &runestone.Terms{
Amount: &amt,
Cap: &ca,
},
}
r := runestone.Runestone{Etching: etching}
data, err := r.Encipher()
if err != nil {
fmt.Println(err)
}
fmt.Printf("Etching data: 0x%x\n", data)
dataString, _ := txscript.DisasmString(data)
fmt.Printf("Etching Script: %s\n", dataString)
}
```

### Mint

```go
func testMint() {
runeIdStr := "2609649:946"
runeId, _ := runestone.RuneIdFromString(runeIdStr)
r := runestone.Runestone{Mint: runeId}
data, err := r.Encipher()
if err != nil {
fmt.Println(err)
}
fmt.Printf("Mint Rune[%s] data: 0x%x\n", runeIdStr, data)
dataString, _ := txscript.DisasmString(data)
fmt.Printf("Mint Script: %s\n", dataString)
}
```

### Decode

```go
func testDecode() {
data, _ := hex.DecodeString("140114001600") //Mint UNCOMMON•GOODS
var tx wire.MsgTx
builder := txscript.NewScriptBuilder()
// Push opcode OP_RETURN
builder.AddOp(txscript.OP_RETURN)
// Push MAGIC_NUMBER
builder.AddOp(runestone.MAGIC_NUMBER)
// Push payload
builder.AddData(data)
pkScript, _ := builder.Script()
txOut := wire.NewTxOut(0, pkScript)
tx.AddTxOut(txOut)
r := &runestone.Runestone{}
artifact, err := r.Decipher(&tx)
if err != nil {
fmt.Println(err)
return
}
a, _ := json.Marshal(artifact)
fmt.Printf("Artifact: %s\n", string(a))
}
```

### Reference:

* https://docs.ordinals.com/runes/specification.html
Expand Down
3 changes: 3 additions & 0 deletions cmd/runestonecli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ require (
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed // indirect
lukechampine.com/uint128 v1.3.0 // indirect
)
replace (
github.com/bxelab/runestone => ../../
)
59 changes: 57 additions & 2 deletions cmd/runestonecli/main.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,80 @@
package main

import (
"encoding/hex"
"encoding/json"
"fmt"

"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/bxelab/runestone"
"lukechampine.com/uint128"
)

func main() {
testEtching()
testMint()
testDecode()
}
func testEtching() {
runeName := "STUDYZY.GMAIL.COM"
symbol := '曾'
myRune, err := runestone.SpacedRuneFromString(runeName)
if err != nil {
fmt.Println(err)
return
}
amt := uint128.From64(666666)
ca := uint128.From64(21000000)
etching := &runestone.Etching{
Rune: &myRune.Rune,
Rune: &myRune.Rune,
Spacers: &myRune.Spacers,
Symbol: &symbol,
Terms: &runestone.Terms{
Amount: &amt,
Cap: &ca,
},
}
r := runestone.Runestone{Etching: etching}
data, err := r.Encipher()
if err != nil {
fmt.Println(err)
}
fmt.Printf("Enciphered Etching data: %x\n", data)
fmt.Printf("Etching data: 0x%x\n", data)
dataString, _ := txscript.DisasmString(data)
fmt.Printf("Etching Script: %s\n", dataString)
}
func testMint() {
runeIdStr := "2609649:946"
runeId, _ := runestone.RuneIdFromString(runeIdStr)
r := runestone.Runestone{Mint: runeId}
data, err := r.Encipher()
if err != nil {
fmt.Println(err)
}
fmt.Printf("Mint Rune[%s] data: 0x%x\n", runeIdStr, data)
dataString, _ := txscript.DisasmString(data)
fmt.Printf("Mint Script: %s\n", dataString)
}
func testDecode() {
data, _ := hex.DecodeString("140114001600") //Mint UNCOMMON•GOODS
var tx wire.MsgTx
builder := txscript.NewScriptBuilder()
// Push opcode OP_RETURN
builder.AddOp(txscript.OP_RETURN)
// Push MAGIC_NUMBER
builder.AddOp(runestone.MAGIC_NUMBER)
// Push payload
builder.AddData(data)
pkScript, _ := builder.Script()
txOut := wire.NewTxOut(0, pkScript)
tx.AddTxOut(txOut)
r := &runestone.Runestone{}
artifact, err := r.Decipher(&tx)
if err != nil {
fmt.Println(err)
return
}
a, _ := json.Marshal(artifact)
fmt.Printf("Artifact: %s\n", string(a))
}

0 comments on commit fb88a65

Please sign in to comment.