Skip to content

Commit fb88a65

Browse files
committed
feat: Add cmd example
--story=1
1 parent abaf3a5 commit fb88a65

File tree

3 files changed

+140
-3
lines changed

3 files changed

+140
-3
lines changed

README.md

+80-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,91 @@
22

33
Bitcoin Rune protocol golang implement library.
44

5-
### How to use
5+
## How to use
66

77
```go
88
go get github.com/bxelab/runestone@latest
99
```
1010

11+
### Etching
12+
13+
Define a new Rune named *STUDYZY.GMAIL.COM*
14+
15+
```go
16+
func testEtching() {
17+
runeName := "STUDYZY.GMAIL.COM"
18+
symbol := ''
19+
myRune, err := runestone.SpacedRuneFromString(runeName)
20+
if err != nil {
21+
fmt.Println(err)
22+
return
23+
}
24+
amt := uint128.From64(666666)
25+
ca := uint128.From64(21000000)
26+
etching := &runestone.Etching{
27+
Rune: &myRune.Rune,
28+
Spacers: &myRune.Spacers,
29+
Symbol: &symbol,
30+
Terms: &runestone.Terms{
31+
Amount: &amt,
32+
Cap: &ca,
33+
},
34+
}
35+
r := runestone.Runestone{Etching: etching}
36+
data, err := r.Encipher()
37+
if err != nil {
38+
fmt.Println(err)
39+
}
40+
fmt.Printf("Etching data: 0x%x\n", data)
41+
dataString, _ := txscript.DisasmString(data)
42+
fmt.Printf("Etching Script: %s\n", dataString)
43+
}
44+
```
45+
46+
### Mint
47+
48+
```go
49+
func testMint() {
50+
runeIdStr := "2609649:946"
51+
runeId, _ := runestone.RuneIdFromString(runeIdStr)
52+
r := runestone.Runestone{Mint: runeId}
53+
data, err := r.Encipher()
54+
if err != nil {
55+
fmt.Println(err)
56+
}
57+
fmt.Printf("Mint Rune[%s] data: 0x%x\n", runeIdStr, data)
58+
dataString, _ := txscript.DisasmString(data)
59+
fmt.Printf("Mint Script: %s\n", dataString)
60+
}
61+
```
62+
63+
### Decode
64+
65+
```go
66+
func testDecode() {
67+
data, _ := hex.DecodeString("140114001600") //Mint UNCOMMON•GOODS
68+
var tx wire.MsgTx
69+
builder := txscript.NewScriptBuilder()
70+
// Push opcode OP_RETURN
71+
builder.AddOp(txscript.OP_RETURN)
72+
// Push MAGIC_NUMBER
73+
builder.AddOp(runestone.MAGIC_NUMBER)
74+
// Push payload
75+
builder.AddData(data)
76+
pkScript, _ := builder.Script()
77+
txOut := wire.NewTxOut(0, pkScript)
78+
tx.AddTxOut(txOut)
79+
r := &runestone.Runestone{}
80+
artifact, err := r.Decipher(&tx)
81+
if err != nil {
82+
fmt.Println(err)
83+
return
84+
}
85+
a, _ := json.Marshal(artifact)
86+
fmt.Printf("Artifact: %s\n", string(a))
87+
}
88+
```
89+
1190
### Reference:
1291

1392
* https://docs.ordinals.com/runes/specification.html

cmd/runestonecli/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ require (
1616
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed // indirect
1717
lukechampine.com/uint128 v1.3.0 // indirect
1818
)
19+
replace (
20+
github.com/bxelab/runestone => ../../
21+
)

cmd/runestonecli/main.go

+57-2
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,80 @@
11
package main
22

33
import (
4+
"encoding/hex"
5+
"encoding/json"
46
"fmt"
57

8+
"github.com/btcsuite/btcd/txscript"
9+
"github.com/btcsuite/btcd/wire"
610
"github.com/bxelab/runestone"
11+
"lukechampine.com/uint128"
712
)
813

914
func main() {
15+
testEtching()
16+
testMint()
17+
testDecode()
18+
}
19+
func testEtching() {
1020
runeName := "STUDYZY.GMAIL.COM"
21+
symbol := '曾'
1122
myRune, err := runestone.SpacedRuneFromString(runeName)
1223
if err != nil {
1324
fmt.Println(err)
1425
return
1526
}
27+
amt := uint128.From64(666666)
28+
ca := uint128.From64(21000000)
1629
etching := &runestone.Etching{
17-
Rune: &myRune.Rune,
30+
Rune: &myRune.Rune,
31+
Spacers: &myRune.Spacers,
32+
Symbol: &symbol,
33+
Terms: &runestone.Terms{
34+
Amount: &amt,
35+
Cap: &ca,
36+
},
1837
}
1938
r := runestone.Runestone{Etching: etching}
2039
data, err := r.Encipher()
2140
if err != nil {
2241
fmt.Println(err)
2342
}
24-
fmt.Printf("Enciphered Etching data: %x\n", data)
43+
fmt.Printf("Etching data: 0x%x\n", data)
44+
dataString, _ := txscript.DisasmString(data)
45+
fmt.Printf("Etching Script: %s\n", dataString)
46+
}
47+
func testMint() {
48+
runeIdStr := "2609649:946"
49+
runeId, _ := runestone.RuneIdFromString(runeIdStr)
50+
r := runestone.Runestone{Mint: runeId}
51+
data, err := r.Encipher()
52+
if err != nil {
53+
fmt.Println(err)
54+
}
55+
fmt.Printf("Mint Rune[%s] data: 0x%x\n", runeIdStr, data)
56+
dataString, _ := txscript.DisasmString(data)
57+
fmt.Printf("Mint Script: %s\n", dataString)
58+
}
59+
func testDecode() {
60+
data, _ := hex.DecodeString("140114001600") //Mint UNCOMMON•GOODS
61+
var tx wire.MsgTx
62+
builder := txscript.NewScriptBuilder()
63+
// Push opcode OP_RETURN
64+
builder.AddOp(txscript.OP_RETURN)
65+
// Push MAGIC_NUMBER
66+
builder.AddOp(runestone.MAGIC_NUMBER)
67+
// Push payload
68+
builder.AddData(data)
69+
pkScript, _ := builder.Script()
70+
txOut := wire.NewTxOut(0, pkScript)
71+
tx.AddTxOut(txOut)
72+
r := &runestone.Runestone{}
73+
artifact, err := r.Decipher(&tx)
74+
if err != nil {
75+
fmt.Println(err)
76+
return
77+
}
78+
a, _ := json.Marshal(artifact)
79+
fmt.Printf("Artifact: %s\n", string(a))
2580
}

0 commit comments

Comments
 (0)