Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
oxf71 committed Jan 6, 2024
1 parent 6315c87 commit 9305aab
Show file tree
Hide file tree
Showing 5 changed files with 791 additions and 0 deletions.
109 changes: 109 additions & 0 deletions example/inscribewithoutnoderpc/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
"encoding/hex"
"fmt"
"log"

"github.com/oxf71/musig2-demo/lib/go-ord-tx/pkg/btcapi/mempool"
"github.com/oxf71/musig2-demo/lib/go-ord-tx/pkg/ord"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
)

func main() {
netParams := &chaincfg.SigNetParams
btcApiClient := mempool.NewClient(netParams)

utxoPrivateKeyHex := "440bb3ec56d213e90d006d344d74f6478db4f7fa4cdd388095d8f4edef0c5156"
utxoPrivateKeyBytes, err := hex.DecodeString(utxoPrivateKeyHex)
if err != nil {
log.Fatal(err)
}
utxoPrivateKey, _ := btcec.PrivKeyFromBytes(utxoPrivateKeyBytes)

utxoPublicKey := utxoPrivateKey.PubKey()

utxoTaprootAddress, err := btcutil.NewAddressTaproot(schnorr.SerializePubKey(txscript.ComputeTaprootKeyNoScript(utxoPublicKey)), netParams)
if err != nil {
log.Fatal(err)
}

fmt.Println("utxoTaprootAddress:", utxoTaprootAddress.EncodeAddress())

unspentList, err := btcApiClient.ListUnspent(utxoTaprootAddress)

if err != nil {
log.Fatalf("list unspent err %v", err)
}

if len(unspentList) == 0 {
log.Fatal("no unspent")
}

commitTxOutPointList := make([]*wire.OutPoint, 0)
commitTxPrivateKeyList := make([]*btcec.PrivateKey, 0)
for i := range unspentList {
commitTxOutPointList = append(commitTxOutPointList, unspentList[i].Outpoint)
commitTxPrivateKeyList = append(commitTxPrivateKeyList, utxoPrivateKey)
fmt.Println("unspentList:", unspentList[i].Outpoint)
}

// panic("err")

dataList := make([]ord.InscriptionData, 0)

dataList = append(dataList, ord.InscriptionData{
ContentType: "text/plain;charset=utf-8",
Body: []byte("Create Without full Node "),
Destination: "tb1p3m6qfu0mzkxsmaue0hwekrxm2nxfjjrmv4dvy94gxs8c3s7zns6qcgf8ef",
})

request := ord.InscriptionRequest{
CommitTxOutPointList: commitTxOutPointList,
CommitTxPrivateKeyList: commitTxPrivateKeyList,
CommitFeeRate: 18,
FeeRate: 19,
DataList: dataList,
SingleRevealTxOnly: false,
}

tool, err := ord.NewInscriptionToolWithBtcApiClient(netParams, btcApiClient, &request)
if err != nil {
log.Fatalf("Failed to create inscription tool: %v", err)
}
recoveryKeyWIFList := tool.GetRecoveryKeyWIFList()
for i, recoveryKeyWIF := range recoveryKeyWIFList {
log.Printf("recoveryKeyWIF %d %s \n", i, recoveryKeyWIF)
}

commitTxHex, err := tool.GetCommitTxHex()
if err != nil {
log.Fatalf("get commit tx hex err, %v", err)
}
log.Printf("commitTxHex %s \n", commitTxHex)
revealTxHexList, err := tool.GetRevealTxHexList()
if err != nil {
log.Fatalf("get reveal tx hex err, %v", err)
}
for i, revealTxHex := range revealTxHexList {
log.Printf("revealTxHex %d %s \n", i, revealTxHex)
}
commitTxHash, revealTxHashList, inscriptions, fees, err := tool.Inscribe()
if err != nil {
log.Fatalf("send tx errr, %v", err)
}
log.Println("commitTxHash, " + commitTxHash.String())
for i := range revealTxHashList {
log.Println("revealTxHash, " + revealTxHashList[i].String())
}
for i := range inscriptions {
log.Println("inscription, " + inscriptions[i])
}
log.Println("fees: ", fees)
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ require (
)

require (
github.com/aead/siphash v1.0.1 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed // indirect
)
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
Expand Down Expand Up @@ -41,6 +42,7 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand All @@ -51,6 +53,7 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 h1:FOOIBWrEkLgmlgGfMuZT83xIwfPDxEI2OHu6xUmJMFE=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand All @@ -71,6 +74,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
Loading

0 comments on commit 9305aab

Please sign in to comment.