2020-09-15 23:30:59 +02:00
|
|
|
// Copyright (c) 2020 The btcsuite developers
|
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-08-24 20:53:04 +02:00
|
|
|
package rpcclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-10-15 07:45:32 +02:00
|
|
|
|
|
|
|
"github.com/lbryio/lbcd/btcjson"
|
2020-08-24 20:53:04 +02:00
|
|
|
)
|
|
|
|
|
2020-08-24 20:53:41 +02:00
|
|
|
var connCfg = &ConnConfig{
|
2021-11-04 02:11:58 +01:00
|
|
|
Host: "localhost:9244",
|
2020-10-09 22:20:49 +02:00
|
|
|
User: "user",
|
|
|
|
Pass: "pass",
|
2020-08-24 20:53:41 +02:00
|
|
|
HTTPPostMode: true,
|
|
|
|
DisableTLS: true,
|
|
|
|
}
|
|
|
|
|
2020-08-24 20:53:04 +02:00
|
|
|
func ExampleClient_GetDescriptorInfo() {
|
|
|
|
client, err := New(connCfg, nil)
|
|
|
|
if err != nil {
|
2020-08-24 20:53:41 +02:00
|
|
|
panic(err)
|
2020-08-24 20:53:04 +02:00
|
|
|
}
|
|
|
|
defer client.Shutdown()
|
|
|
|
|
|
|
|
descriptorInfo, err := client.GetDescriptorInfo(
|
|
|
|
"wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)")
|
|
|
|
if err != nil {
|
2020-08-24 20:53:41 +02:00
|
|
|
panic(err)
|
2020-08-24 20:53:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%+v\n", descriptorInfo)
|
|
|
|
// &{Descriptor:wpkh([d34db33f/84'/0'/0']0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)#n9g43y4k Checksum:qwlqgth7 IsRange:false IsSolvable:true HasPrivateKeys:false}
|
|
|
|
}
|
2020-08-24 20:53:41 +02:00
|
|
|
|
|
|
|
func ExampleClient_ImportMulti() {
|
|
|
|
client, err := New(connCfg, nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer client.Shutdown()
|
|
|
|
|
|
|
|
requests := []btcjson.ImportMultiRequest{
|
|
|
|
{
|
|
|
|
Descriptor: btcjson.String(
|
|
|
|
"pkh([f34db33f/44'/0'/0']xpub6Cc939fyHvfB9pPLWd3bSyyQFvgKbwhidca49jGCM5Hz5ypEPGf9JVXB4NBuUfPgoHnMjN6oNgdC9KRqM11RZtL8QLW6rFKziNwHDYhZ6Kx/0/*)#ed7px9nu"),
|
|
|
|
Range: &btcjson.DescriptorRange{Value: []int{0, 100}},
|
|
|
|
Timestamp: btcjson.TimestampOrNow{Value: 0}, // scan from genesis
|
|
|
|
WatchOnly: btcjson.Bool(true),
|
|
|
|
KeyPool: btcjson.Bool(false),
|
|
|
|
Internal: btcjson.Bool(false),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
opts := &btcjson.ImportMultiOptions{Rescan: true}
|
|
|
|
|
|
|
|
resp, err := client.ImportMulti(requests, opts)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(resp[0].Success)
|
|
|
|
// true
|
|
|
|
}
|
2020-09-13 09:47:39 +02:00
|
|
|
|
|
|
|
func ExampleClient_DeriveAddresses() {
|
|
|
|
client, err := New(connCfg, nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer client.Shutdown()
|
|
|
|
|
|
|
|
addrs, err := client.DeriveAddresses(
|
|
|
|
"pkh([f34db33f/44'/0'/0']xpub6Cc939fyHvfB9pPLWd3bSyyQFvgKbwhidca49jGCM5Hz5ypEPGf9JVXB4NBuUfPgoHnMjN6oNgdC9KRqM11RZtL8QLW6rFKziNwHDYhZ6Kx/0/*)#ed7px9nu",
|
|
|
|
&btcjson.DescriptorRange{Value: []int{0, 2}})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%+v\n", addrs)
|
|
|
|
// &[14NjenDKkGGq1McUgoSkeUHJpW3rrKLbPW 1Pn6i3cvdGhqbdgNjXHfbaYfiuviPiymXj 181x1NbgGYKLeMXkDdXEAqepG75EgU8XtG]
|
|
|
|
}
|
2020-09-15 23:30:59 +02:00
|
|
|
|
|
|
|
func ExampleClient_GetAddressInfo() {
|
|
|
|
client, err := New(connCfg, nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer client.Shutdown()
|
|
|
|
|
|
|
|
info, err := client.GetAddressInfo("2NF1FbxtUAsvdU4uW1UC2xkBVatp6cYQuJ3")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(info.Address) // 2NF1FbxtUAsvdU4uW1UC2xkBVatp6cYQuJ3
|
|
|
|
fmt.Println(info.ScriptType.String()) // witness_v0_keyhash
|
|
|
|
fmt.Println(*info.HDKeyPath) // m/49'/1'/0'/0/4
|
|
|
|
fmt.Println(info.Embedded.Address) // tb1q3x2h2kh57wzg7jz00jhwn0ycvqtdk2ane37j27
|
|
|
|
}
|
2020-09-20 15:46:32 +02:00
|
|
|
|
|
|
|
func ExampleClient_GetWalletInfo() {
|
|
|
|
client, err := New(connCfg, nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer client.Shutdown()
|
|
|
|
|
|
|
|
info, err := client.GetWalletInfo()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(info.WalletVersion) // 169900
|
|
|
|
fmt.Println(info.TransactionCount) // 22
|
|
|
|
fmt.Println(*info.HDSeedID) // eb44e4e9b864ef17e7ba947da746375b000f5d94
|
|
|
|
fmt.Println(info.Scanning.Value) // false
|
|
|
|
}
|
2020-09-28 14:42:18 +02:00
|
|
|
|
|
|
|
func ExampleClient_GetTxOutSetInfo() {
|
|
|
|
client, err := New(connCfg, nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer client.Shutdown()
|
|
|
|
|
|
|
|
r, err := client.GetTxOutSetInfo()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(r.TotalAmount.String()) // 20947654.56996054 BTC
|
|
|
|
fmt.Println(r.BestBlock.String()) // 000000000000005f94116250e2407310463c0a7cf950f1af9ebe935b1c0687ab
|
|
|
|
fmt.Println(r.TxOuts) // 24280607
|
|
|
|
fmt.Println(r.Transactions) // 9285603
|
|
|
|
fmt.Println(r.DiskSize) // 1320871611
|
|
|
|
}
|
2020-10-09 22:20:49 +02:00
|
|
|
|
|
|
|
func ExampleClient_CreateWallet() {
|
|
|
|
client, err := New(connCfg, nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer client.Shutdown()
|
|
|
|
|
|
|
|
r, err := client.CreateWallet(
|
|
|
|
"mywallet",
|
|
|
|
WithCreateWalletBlank(),
|
|
|
|
WithCreateWalletPassphrase("secret"),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(r.Name) // mywallet
|
|
|
|
}
|