mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 18:02:54 +01:00
Make imports in chain.md invisible (#1213)
* Make imports in chain.md invisible * Hide imports in wallet.md * Make all core module md files imports hidden * Cleanup imports on rpc markdown docs * Try and figure weird travis behavior * Get rid of uneeded nest qualifiers on mdoc
This commit is contained in:
parent
237e61cccc
commit
65ddeb6798
@ -16,15 +16,21 @@ we demonstrate how to do this, while persisting it to disk. We should be
|
|||||||
able to read this chain on subsequent runs, assuming we are connected
|
able to read this chain on subsequent runs, assuming we are connected
|
||||||
to the same `bitcoind` instance.
|
to the same `bitcoind` instance.
|
||||||
|
|
||||||
```scala mdoc:compile-only
|
```scala mdoc:invisible
|
||||||
import org.bitcoins.chain.blockchain._
|
import org.bitcoins.chain.blockchain._
|
||||||
import org.bitcoins.chain.blockchain.sync._
|
import org.bitcoins.chain.blockchain.sync._
|
||||||
import org.bitcoins.chain.models._
|
import org.bitcoins.chain.models._
|
||||||
|
import org.bitcoins.chain.config.ChainAppConfig
|
||||||
|
import org.bitcoins.rpc.config.BitcoindInstance
|
||||||
|
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||||
import org.bitcoins.rpc.client.common._
|
import org.bitcoins.rpc.client.common._
|
||||||
import org.bitcoins.testkit.chain._
|
import org.bitcoins.testkit.chain._
|
||||||
|
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
|
import java.nio.file.Files
|
||||||
|
```
|
||||||
|
|
||||||
|
```scala mdoc:compile-only
|
||||||
|
|
||||||
implicit val ec = ExecutionContext.global
|
implicit val ec = ExecutionContext.global
|
||||||
|
|
||||||
@ -32,9 +38,6 @@ implicit val ec = ExecutionContext.global
|
|||||||
// You can see our `bitcoind` guides to see how to connect
|
// You can see our `bitcoind` guides to see how to connect
|
||||||
// to a local or remote `bitcoind` node.
|
// to a local or remote `bitcoind` node.
|
||||||
|
|
||||||
import org.bitcoins.rpc.config.BitcoindInstance
|
|
||||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
|
||||||
|
|
||||||
val bitcoindInstance = BitcoindInstance.fromDatadir()
|
val bitcoindInstance = BitcoindInstance.fromDatadir()
|
||||||
val rpcCli = BitcoindRpcClient(bitcoindInstance)
|
val rpcCli = BitcoindRpcClient(bitcoindInstance)
|
||||||
|
|
||||||
@ -44,9 +47,7 @@ val getBestBlockHash = ChainTestUtil.bestBlockHashFnRpc(Future.successful(rpcCli
|
|||||||
|
|
||||||
val getBlockHeader = ChainTestUtil.getBlockHeaderFnRpc(Future.successful(rpcCli))
|
val getBlockHeader = ChainTestUtil.getBlockHeaderFnRpc(Future.successful(rpcCli))
|
||||||
|
|
||||||
|
|
||||||
// set a data directory
|
// set a data directory
|
||||||
import java.nio.file.Files
|
|
||||||
val datadir = Files.createTempDirectory("bitcoin-s-test")
|
val datadir = Files.createTempDirectory("bitcoin-s-test")
|
||||||
|
|
||||||
// set the currenet network to regtest
|
// set the currenet network to regtest
|
||||||
@ -59,7 +60,6 @@ val config = ConfigFactory.parseString {
|
|||||||
|""".stripMargin
|
|""".stripMargin
|
||||||
}
|
}
|
||||||
|
|
||||||
import org.bitcoins.chain.config.ChainAppConfig
|
|
||||||
implicit val chainConfig = ChainAppConfig(datadir, config)
|
implicit val chainConfig = ChainAppConfig(datadir, config)
|
||||||
|
|
||||||
// Initialize the needed database tables if they don't exist:
|
// Initialize the needed database tables if they don't exist:
|
||||||
@ -77,7 +77,6 @@ val syncedChainApiF = for {
|
|||||||
synced <- ChainSync.sync(handler, getBlockHeader, getBestBlockHash)
|
synced <- ChainSync.sync(handler, getBlockHeader, getBestBlockHash)
|
||||||
} yield synced
|
} yield synced
|
||||||
|
|
||||||
|
|
||||||
val syncResultF = syncedChainApiF.flatMap { chainApi =>
|
val syncResultF = syncedChainApiF.flatMap { chainApi =>
|
||||||
chainApi.getBlockCount.map(count => println(s"chain api blockcount=${count}"))
|
chainApi.getBlockCount.map(count => println(s"chain api blockcount=${count}"))
|
||||||
|
|
||||||
|
@ -40,10 +40,36 @@ UTXOs with popular database like Postgres, SQLite, etc.
|
|||||||
This code snippet you have a running `bitcoind` instance, locally
|
This code snippet you have a running `bitcoind` instance, locally
|
||||||
on regtest.
|
on regtest.
|
||||||
|
|
||||||
|
```scala mdoc:invisible
|
||||||
|
|
||||||
|
import org.bitcoins.chain.blockchain.ChainHandler
|
||||||
|
import org.bitcoins.chain.blockchain.sync.ChainSync
|
||||||
|
import org.bitcoins.chain.config.ChainAppConfig
|
||||||
|
import org.bitcoins.chain.api.ChainApi
|
||||||
|
import org.bitcoins.chain.models._
|
||||||
|
|
||||||
|
import org.bitcoins.core.api._
|
||||||
|
import ChainQueryApi._
|
||||||
|
import org.bitcoins.core.crypto._
|
||||||
|
import org.bitcoins.core.protocol._
|
||||||
|
import org.bitcoins.core.protocol.transaction._
|
||||||
|
import org.bitcoins.core.currency._
|
||||||
|
import org.bitcoins.keymanager.bip39._
|
||||||
|
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||||
|
import org.bitcoins.rpc.config.BitcoindInstance
|
||||||
|
import org.bitcoins.wallet.config.WalletAppConfig
|
||||||
|
import org.bitcoins.wallet.api.LockedWalletApi
|
||||||
|
import org.bitcoins.wallet.Wallet
|
||||||
|
|
||||||
|
import com.typesafe.config.ConfigFactory
|
||||||
|
import java.nio.file.Files
|
||||||
|
import scala.concurrent._
|
||||||
|
```
|
||||||
|
|
||||||
```scala mdoc:compile-only
|
```scala mdoc:compile-only
|
||||||
implicit val ec = scala.concurrent.ExecutionContext.global
|
implicit val ec = scala.concurrent.ExecutionContext.global
|
||||||
|
|
||||||
import com.typesafe.config.ConfigFactory
|
|
||||||
val config = ConfigFactory.parseString {
|
val config = ConfigFactory.parseString {
|
||||||
"""
|
"""
|
||||||
| bitcoin-s {
|
| bitcoin-s {
|
||||||
@ -52,49 +78,41 @@ val config = ConfigFactory.parseString {
|
|||||||
""".stripMargin
|
""".stripMargin
|
||||||
}
|
}
|
||||||
|
|
||||||
import java.nio.file.Files
|
|
||||||
val datadir = Files.createTempDirectory("bitcoin-s-wallet")
|
val datadir = Files.createTempDirectory("bitcoin-s-wallet")
|
||||||
|
|
||||||
import org.bitcoins.wallet.config.WalletAppConfig
|
|
||||||
implicit val walletConfig = WalletAppConfig(datadir, config)
|
implicit val walletConfig = WalletAppConfig(datadir, config)
|
||||||
|
|
||||||
// we also need to store chain state for syncing purposes
|
// we also need to store chain state for syncing purposes
|
||||||
import org.bitcoins.chain.config.ChainAppConfig
|
|
||||||
implicit val chainConfig = ChainAppConfig(datadir, config)
|
implicit val chainConfig = ChainAppConfig(datadir, config)
|
||||||
|
|
||||||
// when this future completes, we have
|
// when this future completes, we have
|
||||||
// created the necessary directories and
|
// created the necessary directories and
|
||||||
// databases for managing both chain state
|
// databases for managing both chain state
|
||||||
// and wallet state
|
// and wallet state
|
||||||
import scala.concurrent._
|
|
||||||
val configF: Future[Unit] = for {
|
val configF: Future[Unit] = for {
|
||||||
_ <- walletConfig.initialize()
|
_ <- walletConfig.initialize()
|
||||||
_ <- chainConfig.initialize()
|
_ <- chainConfig.initialize()
|
||||||
} yield ()
|
} yield ()
|
||||||
|
|
||||||
import org.bitcoins.rpc.config.BitcoindInstance
|
|
||||||
val bitcoindInstance = BitcoindInstance.fromDatadir()
|
val bitcoindInstance = BitcoindInstance.fromDatadir()
|
||||||
|
|
||||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
|
||||||
val bitcoind = BitcoindRpcClient(bitcoindInstance)
|
val bitcoind = BitcoindRpcClient(bitcoindInstance)
|
||||||
|
|
||||||
// when this future completes, we have
|
// when this future completes, we have
|
||||||
// synced our chain handler to our bitcoind
|
// synced our chain handler to our bitcoind
|
||||||
// peer
|
// peer
|
||||||
import org.bitcoins.chain.api.ChainApi
|
|
||||||
val syncF: Future[ChainApi] = configF.flatMap { _ =>
|
val syncF: Future[ChainApi] = configF.flatMap { _ =>
|
||||||
val getBestBlockHashFunc = { () =>
|
val getBestBlockHashFunc = { () =>
|
||||||
bitcoind.getBestBlockHash
|
bitcoind.getBestBlockHash
|
||||||
}
|
}
|
||||||
|
|
||||||
import org.bitcoins.core.crypto.DoubleSha256DigestBE
|
|
||||||
val getBlockHeaderFunc = { hash: DoubleSha256DigestBE =>
|
val getBlockHeaderFunc = { hash: DoubleSha256DigestBE =>
|
||||||
bitcoind.getBlockHeader(hash).map(_.blockHeader)
|
bitcoind.getBlockHeader(hash).map(_.blockHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
import org.bitcoins.chain.models._
|
|
||||||
import org.bitcoins.chain.blockchain.ChainHandler
|
|
||||||
val blockHeaderDAO = BlockHeaderDAO()
|
val blockHeaderDAO = BlockHeaderDAO()
|
||||||
val compactFilterHeaderDAO = CompactFilterHeaderDAO()
|
val compactFilterHeaderDAO = CompactFilterHeaderDAO()
|
||||||
val compactFilterDAO = CompactFilterDAO()
|
val compactFilterDAO = CompactFilterDAO()
|
||||||
@ -105,12 +123,10 @@ val syncF: Future[ChainApi] = configF.flatMap { _ =>
|
|||||||
blockchains = Vector.empty,
|
blockchains = Vector.empty,
|
||||||
blockFilterCheckpoints = Map.empty)
|
blockFilterCheckpoints = Map.empty)
|
||||||
|
|
||||||
import org.bitcoins.chain.blockchain.sync.ChainSync
|
|
||||||
ChainSync.sync(chainHandler, getBlockHeaderFunc, getBestBlockHashFunc)
|
ChainSync.sync(chainHandler, getBlockHeaderFunc, getBestBlockHashFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
//initialize our key manager, where we store our keys
|
//initialize our key manager, where we store our keys
|
||||||
import org.bitcoins.keymanager.bip39._
|
|
||||||
//you can add a password here if you want
|
//you can add a password here if you want
|
||||||
//val bip39PasswordOpt = Some("my-password-here")
|
//val bip39PasswordOpt = Some("my-password-here")
|
||||||
val bip39PasswordOpt = None
|
val bip39PasswordOpt = None
|
||||||
@ -120,16 +136,9 @@ val keyManager = BIP39KeyManager.initialize(walletConfig.kmParams, bip39Password
|
|||||||
|
|
||||||
// once this future completes, we have a initialized
|
// once this future completes, we have a initialized
|
||||||
// wallet
|
// wallet
|
||||||
|
|
||||||
import org.bitcoins.wallet.api.LockedWalletApi
|
|
||||||
import org.bitcoins.wallet.Wallet
|
|
||||||
import org.bitcoins.core.api._
|
|
||||||
import org.bitcoins.core.crypto._
|
|
||||||
import org.bitcoins.core.protocol._
|
|
||||||
val wallet = Wallet(keyManager, new NodeApi {
|
val wallet = Wallet(keyManager, new NodeApi {
|
||||||
override def downloadBlocks(blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = Future.successful(())
|
override def downloadBlocks(blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = Future.successful(())
|
||||||
}, new ChainQueryApi {
|
}, new ChainQueryApi {
|
||||||
import org.bitcoins.core.api.ChainQueryApi._
|
|
||||||
override def getBlockHeight(blockHash: DoubleSha256DigestBE): Future[Option[Int]] = Future.successful(None)
|
override def getBlockHeight(blockHash: DoubleSha256DigestBE): Future[Option[Int]] = Future.successful(None)
|
||||||
override def getBestBlockHash(): Future[DoubleSha256DigestBE] = Future.successful(DoubleSha256DigestBE.empty)
|
override def getBestBlockHash(): Future[DoubleSha256DigestBE] = Future.successful(DoubleSha256DigestBE.empty)
|
||||||
override def getNumberOfConfirmations(blockHashOpt: DoubleSha256DigestBE): Future[Option[Int]] = Future.successful(None)
|
override def getNumberOfConfirmations(blockHashOpt: DoubleSha256DigestBE): Future[Option[Int]] = Future.successful(None)
|
||||||
@ -143,9 +152,6 @@ val walletF: Future[LockedWalletApi] = configF.flatMap { _ =>
|
|||||||
|
|
||||||
// when this future completes, ww have sent a transaction
|
// when this future completes, ww have sent a transaction
|
||||||
// from bitcoind to the Bitcoin-S wallet
|
// from bitcoind to the Bitcoin-S wallet
|
||||||
import org.bitcoins.core.crypto._
|
|
||||||
import org.bitcoins.core.protocol.transaction._
|
|
||||||
import org.bitcoins.core.currency._
|
|
||||||
val transactionF: Future[(Transaction, Option[DoubleSha256DigestBE])] = for {
|
val transactionF: Future[(Transaction, Option[DoubleSha256DigestBE])] = for {
|
||||||
wallet <- walletF
|
wallet <- walletF
|
||||||
address <- wallet.getNewAddress()
|
address <- wallet.getNewAddress()
|
||||||
|
@ -20,18 +20,17 @@ you can generate bech32 addresses in four(!) lines of code
|
|||||||
(not counting comments and imports), so now there's no
|
(not counting comments and imports), so now there's no
|
||||||
reason to keep using legacy transaction formats.
|
reason to keep using legacy transaction formats.
|
||||||
|
|
||||||
```scala mdoc:to-string
|
```scala mdoc:invisible
|
||||||
import org.bitcoins.core.{crypto, protocol, config}
|
import org.bitcoins.core.{crypto, protocol, config}
|
||||||
// if you want to get addresses for mainnet, just import
|
|
||||||
// config.MainNet here instead
|
|
||||||
import config.TestNet3
|
import config.TestNet3
|
||||||
import crypto.ECPrivateKey
|
import crypto.ECPrivateKey
|
||||||
|
|
||||||
// this gets all addresses into scope
|
|
||||||
import protocol._
|
import protocol._
|
||||||
|
|
||||||
// this gets all scriptPubKeys into scope
|
|
||||||
import protocol.script._
|
import protocol.script._
|
||||||
|
import org.bitcoins.core.protocol.P2PKHAddress
|
||||||
|
```
|
||||||
|
|
||||||
|
```scala mdoc:to-string
|
||||||
|
|
||||||
// this generates a random private key
|
// this generates a random private key
|
||||||
val privkey = ECPrivateKey()
|
val privkey = ECPrivateKey()
|
||||||
@ -44,6 +43,8 @@ val segwitAddress = {
|
|||||||
val scriptPubKey = P2WPKHWitnessSPKV0(pubkey)
|
val scriptPubKey = P2WPKHWitnessSPKV0(pubkey)
|
||||||
Bech32Address(scriptPubKey, TestNet3)
|
Bech32Address(scriptPubKey, TestNet3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println(segwitAddress.toString)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Generating legacy (base58) addresses
|
## Generating legacy (base58) addresses
|
||||||
@ -53,10 +54,10 @@ compatability reasons, that's also a walk in the park.
|
|||||||
Take a look:
|
Take a look:
|
||||||
|
|
||||||
```scala mdoc:to-string
|
```scala mdoc:to-string
|
||||||
// pay-to-pubkey-hash address
|
|
||||||
import org.bitcoins.core.protocol.P2PKHAddress
|
|
||||||
|
|
||||||
// we're reusing the same private/public key pair
|
// we're reusing the same private/public key pair
|
||||||
// from before. don't do this in an actual application!
|
// from before. don't do this in an actual application!
|
||||||
val legacyAddress = P2PKHAddress(pubkey, TestNet3)
|
val legacyAddress = P2PKHAddress(pubkey, TestNet3)
|
||||||
|
|
||||||
|
println(legacyAddress.toString)
|
||||||
```
|
```
|
||||||
|
@ -76,7 +76,7 @@ Transactions are run through the interpreter to check their validity. These are
|
|||||||
|
|
||||||
Here is an example of a transaction spending a `scriptPubKey` which is correctly evaluated with our interpreter implementation:
|
Here is an example of a transaction spending a `scriptPubKey` which is correctly evaluated with our interpreter implementation:
|
||||||
|
|
||||||
```scala mdoc:silent:reset
|
```scala mdoc:invisible
|
||||||
import org.bitcoins.core.protocol.script._
|
import org.bitcoins.core.protocol.script._
|
||||||
import org.bitcoins.core.protocol.transaction._
|
import org.bitcoins.core.protocol.transaction._
|
||||||
import org.bitcoins.core.script._
|
import org.bitcoins.core.script._
|
||||||
@ -85,6 +85,9 @@ import org.bitcoins.core.policy._
|
|||||||
import org.bitcoins.core.number._
|
import org.bitcoins.core.number._
|
||||||
import org.bitcoins.core.crypto._
|
import org.bitcoins.core.crypto._
|
||||||
import org.bitcoins.core.currency._
|
import org.bitcoins.core.currency._
|
||||||
|
```
|
||||||
|
|
||||||
|
```scala mdoc:to-string
|
||||||
|
|
||||||
val spendingTx = Transaction.fromHex("0100000001ccf318f0cbac588a680bbad075aebdda1f211c94ba28125b0f627f9248310db3000000006b4830450221008337ce3ce0c6ac0ab72509f889c1d52701817a2362d6357457b63e3bdedc0c0602202908963b9cf1a095ab3b34b95ce2bc0d67fb0f19be1cc5f7b3de0b3a325629bf01210241d746ca08da0a668735c3e01c1fa02045f2f399c5937079b6434b5a31dfe353ffffffff0210335d05000000001976a914b1d7591b69e9def0feb13254bace942923c7922d88ac48030000000000001976a9145e690c865c2f6f7a9710a474154ab1423abb5b9288ac00000000")
|
val spendingTx = Transaction.fromHex("0100000001ccf318f0cbac588a680bbad075aebdda1f211c94ba28125b0f627f9248310db3000000006b4830450221008337ce3ce0c6ac0ab72509f889c1d52701817a2362d6357457b63e3bdedc0c0602202908963b9cf1a095ab3b34b95ce2bc0d67fb0f19be1cc5f7b3de0b3a325629bf01210241d746ca08da0a668735c3e01c1fa02045f2f399c5937079b6434b5a31dfe353ffffffff0210335d05000000001976a914b1d7591b69e9def0feb13254bace942923c7922d88ac48030000000000001976a9145e690c865c2f6f7a9710a474154ab1423abb5b9288ac00000000")
|
||||||
|
|
||||||
@ -97,8 +100,8 @@ val inputIndex = UInt32.zero
|
|||||||
val btxsc = BaseTxSigComponent(spendingTx,inputIndex,output,Policy.standardScriptVerifyFlags)
|
val btxsc = BaseTxSigComponent(spendingTx,inputIndex,output,Policy.standardScriptVerifyFlags)
|
||||||
|
|
||||||
val preExecution = PreExecutionScriptProgram(btxsc)
|
val preExecution = PreExecutionScriptProgram(btxsc)
|
||||||
```
|
|
||||||
|
|
||||||
```scala mdoc
|
|
||||||
val result = ScriptInterpreter.run(preExecution)
|
val result = ScriptInterpreter.run(preExecution)
|
||||||
|
|
||||||
|
println(s"Script execution result=${result}")
|
||||||
```
|
```
|
@ -16,8 +16,7 @@ creation, updating, combining, signing, finalizing,
|
|||||||
and transaction extraction.
|
and transaction extraction.
|
||||||
|
|
||||||
An example on a typical PSBT workflow:
|
An example on a typical PSBT workflow:
|
||||||
|
```scala mdoc:invisible
|
||||||
```scala mdoc:to-string
|
|
||||||
import org.bitcoins.core.crypto.ECPrivateKey
|
import org.bitcoins.core.crypto.ECPrivateKey
|
||||||
import org.bitcoins.core.protocol.script.ScriptPubKey
|
import org.bitcoins.core.protocol.script.ScriptPubKey
|
||||||
import org.bitcoins.core.protocol.transaction.{BaseTransaction, Transaction}
|
import org.bitcoins.core.protocol.transaction.{BaseTransaction, Transaction}
|
||||||
@ -25,6 +24,9 @@ import org.bitcoins.core.psbt.PSBT
|
|||||||
import org.bitcoins.core.script.crypto.HashType
|
import org.bitcoins.core.script.crypto.HashType
|
||||||
import scodec.bits._
|
import scodec.bits._
|
||||||
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
|
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
|
||||||
|
```
|
||||||
|
|
||||||
|
```scala mdoc:to-string
|
||||||
implicit val ec: ExecutionContextExecutor = ExecutionContext.global
|
implicit val ec: ExecutionContextExecutor = ExecutionContext.global
|
||||||
|
|
||||||
// First you need an unsigned transaction,
|
// First you need an unsigned transaction,
|
||||||
|
@ -6,7 +6,7 @@ title: TxBuilder example
|
|||||||
Bitcoin-S features a transaction builder that constructs and signs Bitcoin
|
Bitcoin-S features a transaction builder that constructs and signs Bitcoin
|
||||||
transactions. Here's an example of how to use it
|
transactions. Here's an example of how to use it
|
||||||
|
|
||||||
```scala mdoc:silent
|
```scala mdoc:invisible
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
|
|
||||||
@ -23,6 +23,10 @@ import wallet.builder._
|
|||||||
import wallet.fee._
|
import wallet.fee._
|
||||||
import wallet.utxo._
|
import wallet.utxo._
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
```scala mdoc:to-string
|
||||||
|
|
||||||
implicit val ec: ExecutionContext = ExecutionContext.Implicits.global
|
implicit val ec: ExecutionContext = ExecutionContext.Implicits.global
|
||||||
|
|
||||||
// generate a fresh private key that we are going to use in the scriptpubkey
|
// generate a fresh private key that we are going to use in the scriptpubkey
|
||||||
@ -124,7 +128,7 @@ val signedTx: Transaction = {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```scala mdoc
|
```scala mdoc:to-string
|
||||||
signedTx.inputs.length
|
signedTx.inputs.length
|
||||||
|
|
||||||
signedTx.outputs.length
|
signedTx.outputs.length
|
||||||
|
@ -26,7 +26,7 @@ A popular way for bitcoin wallet's to represent entropy is [BIP39](https://githu
|
|||||||
|
|
||||||
You can generate a `MnemonicCode` in bitcoin-s with the following code
|
You can generate a `MnemonicCode` in bitcoin-s with the following code
|
||||||
|
|
||||||
```scala mdoc
|
```scala mdoc:to-string
|
||||||
import org.bitcoins.core.crypto._
|
import org.bitcoins.core.crypto._
|
||||||
|
|
||||||
//get 256 bits of random entropy
|
//get 256 bits of random entropy
|
||||||
@ -48,12 +48,10 @@ generate specific kinds of addresses for wallets.
|
|||||||
3. [`network`](../../core/src/main/scala/org/bitcoins/core/config/NetworkParameters.scala) what cryptocurrency network this key manager is associated with
|
3. [`network`](../../core/src/main/scala/org/bitcoins/core/config/NetworkParameters.scala) what cryptocurrency network this key manager is associated with
|
||||||
|
|
||||||
|
|
||||||
This controls how the root key is defined. The combination of `purpose` and `network` determine how the root `ExtKey` is serialized. For more information on how this works please see [hd-keys](hd-keys.md)
|
This controls how the root key is defined. The combination of `purpose` and `network` determine how the root `ExtKey` is serialized. For more information on how this works please see [hd-keys](../core/hd-keys.md)
|
||||||
|
|
||||||
Now we can construct a native segwit key manager for the regtest network!
|
Now we can construct a native segwit key manager for the regtest network!
|
||||||
|
```scala mdoc:invisible
|
||||||
```scala mdoc
|
|
||||||
|
|
||||||
import org.bitcoins.core.crypto._
|
import org.bitcoins.core.crypto._
|
||||||
|
|
||||||
import org.bitcoins.core.config._
|
import org.bitcoins.core.config._
|
||||||
@ -66,6 +64,10 @@ import org.bitcoins.keymanager.bip39._
|
|||||||
|
|
||||||
import java.nio.file._
|
import java.nio.file._
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
```scala mdoc:to-string
|
||||||
|
|
||||||
//this will create a temp directory with the prefix 'key-manager-example` that will
|
//this will create a temp directory with the prefix 'key-manager-example` that will
|
||||||
//have a file in it called "encrypted-bitcoin-s-seed.json"
|
//have a file in it called "encrypted-bitcoin-s-seed.json"
|
||||||
val seedPath = Files.createTempDirectory("key-manager-example").resolve(WalletStorage.ENCRYPTED_SEED_FILE_NAME)
|
val seedPath = Files.createTempDirectory("key-manager-example").resolve(WalletStorage.ENCRYPTED_SEED_FILE_NAME)
|
||||||
@ -94,13 +96,13 @@ which is a native segwit `ExtPubKey` for the regtest network!
|
|||||||
You can always change the `network` or `purpose` to support different things. You do _not_ need to initialize the key manager
|
You can always change the `network` or `purpose` to support different things. You do _not_ need to initialize the key manager
|
||||||
again after initializing it once. You can use the same `mnemonic` for different networks, which you control `KeyManagerParams`.
|
again after initializing it once. You can use the same `mnemonic` for different networks, which you control `KeyManagerParams`.
|
||||||
|
|
||||||
```scala
|
```scala mdoc:to-string
|
||||||
|
|
||||||
//let's create a nested segwit key manager for mainnet
|
//let's create a nested segwit key manager for mainnet
|
||||||
val mainnetKmParams = KeyManagerParams(seedPath, HDPurposes.SegWit, MainNet)
|
val mainnetKmParams = KeyManagerParams(seedPath, HDPurposes.SegWit, MainNet)
|
||||||
|
|
||||||
//we do not need to all `initializeWithMnemonic()` again as we have saved the seed to dis
|
//we do not need to all `initializeWithMnemonic()` again as we have saved the seed to dis
|
||||||
val mainnetKeyManager = KeyManager(mnemonic, mainnetKmParams)
|
val mainnetKeyManager = BIP39KeyManager(mnemonic, mainnetKmParams, None)
|
||||||
|
|
||||||
val mainnetXpub = mainnetKeyManager.getRootXPub
|
val mainnetXpub = mainnetKeyManager.getRootXPub
|
||||||
|
|
||||||
|
@ -8,17 +8,37 @@ title: bitcoind/Bitcoin Core
|
|||||||
The Bitcoin Core RPC client in Bitcoin-S currently supports the Bitcoin Core 0.16, 0.17, 0.18, and 0.19
|
The Bitcoin Core RPC client in Bitcoin-S currently supports the Bitcoin Core 0.16, 0.17, 0.18, and 0.19
|
||||||
version lines. It can be set up to work with both local and remote Bitcoin Core servers.
|
version lines. It can be set up to work with both local and remote Bitcoin Core servers.
|
||||||
|
|
||||||
|
You can fetch them using bitcoin-s by running the following sbt command
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sbt downloadBitcoind
|
||||||
|
```
|
||||||
|
|
||||||
|
The binaries will be stored in `$HOME/.bitcoin-s/binaries/bitcoind/`
|
||||||
|
|
||||||
## Connecting to a local `bitcoind` instance
|
## Connecting to a local `bitcoind` instance
|
||||||
|
|
||||||
### Getting started quickly, with default options:
|
### Getting started quickly, with default options:
|
||||||
|
```scala mdoc:invisible
|
||||||
```scala mdoc:compile-only
|
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
|
|
||||||
import org.bitcoins.{rpc, core}
|
import org.bitcoins.{rpc, core}
|
||||||
import core.currency.Bitcoins
|
|
||||||
import rpc.client.common._
|
import rpc.client.common._
|
||||||
import java.io._
|
import java.io._
|
||||||
|
import java.net.URI
|
||||||
|
|
||||||
|
import org.bitcoins.core.config._
|
||||||
|
import org.bitcoins.rpc.config._
|
||||||
|
import org.bitcoins.rpc.client.common._
|
||||||
|
|
||||||
|
import org.bitcoins.rpc.BitcoindWalletException
|
||||||
|
import org.bitcoins.core.crypto._
|
||||||
|
import org.bitcoins.core.protocol._
|
||||||
|
import org.bitcoins.core.currency._
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
```scala mdoc:compile-only
|
||||||
|
|
||||||
implicit val ec: ExecutionContext = ExecutionContext.global
|
implicit val ec: ExecutionContext = ExecutionContext.global
|
||||||
|
|
||||||
@ -50,12 +70,8 @@ Now that we have a secure connection between our remote `bitcoind`, we're
|
|||||||
ready to create the connection with our RPC client
|
ready to create the connection with our RPC client
|
||||||
|
|
||||||
```scala mdoc:compile-only
|
```scala mdoc:compile-only
|
||||||
import java.net.URI
|
|
||||||
import scala.concurrent._
|
|
||||||
|
|
||||||
import org.bitcoins.core.config._
|
implicit val ec: ExecutionContext = ExecutionContext.global
|
||||||
import org.bitcoins.rpc.config._
|
|
||||||
import org.bitcoins.rpc.client.common._
|
|
||||||
|
|
||||||
val username = "FILL_ME_IN" //this username comes from 'rpcuser' in your bitcoin.conf file
|
val username = "FILL_ME_IN" //this username comes from 'rpcuser' in your bitcoin.conf file
|
||||||
val password = "FILL_ME_IN" //this password comes from your 'rpcpassword' in your bitcoin.conf file
|
val password = "FILL_ME_IN" //this password comes from your 'rpcpassword' in your bitcoin.conf file
|
||||||
@ -74,8 +90,6 @@ val bitcoindInstance = {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit val ec: ExecutionContext = ExecutionContext.global
|
|
||||||
|
|
||||||
val rpcCli = BitcoindRpcClient(bitcoindInstance)
|
val rpcCli = BitcoindRpcClient(bitcoindInstance)
|
||||||
|
|
||||||
rpcCli.getBalance.onComplete { case balance =>
|
rpcCli.getBalance.onComplete { case balance =>
|
||||||
@ -94,14 +108,6 @@ class is only intended to cover errors returned by Bitcoin Core. An example of h
|
|||||||
handling could look:
|
handling could look:
|
||||||
|
|
||||||
```scala mdoc:compile-only
|
```scala mdoc:compile-only
|
||||||
import org.bitcoins.rpc.client.common._
|
|
||||||
import org.bitcoins.rpc.BitcoindWalletException
|
|
||||||
import org.bitcoins.core.crypto._
|
|
||||||
import org.bitcoins.core.protocol._
|
|
||||||
import org.bitcoins.core.currency._
|
|
||||||
import java.io._
|
|
||||||
|
|
||||||
import scala.concurrent._
|
|
||||||
|
|
||||||
implicit val ec = ExecutionContext.global
|
implicit val ec = ExecutionContext.global
|
||||||
|
|
||||||
|
@ -33,11 +33,14 @@ We will default to using the `binary` field first when trying to start the jar,
|
|||||||
|
|
||||||
Here is an example of how to start eclair:
|
Here is an example of how to start eclair:
|
||||||
|
|
||||||
```scala mdoc:compile-only
|
```scala mdoc:invisible
|
||||||
import akka.actor.ActorSystem
|
import akka.actor.ActorSystem
|
||||||
import org.bitcoins.eclair.rpc.client.EclairRpcClient
|
import org.bitcoins.eclair.rpc.client.EclairRpcClient
|
||||||
import org.bitcoins.eclair.rpc.config.EclairInstance
|
import org.bitcoins.eclair.rpc.config.EclairInstance
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
```
|
||||||
|
|
||||||
|
```scala mdoc:compile-only
|
||||||
|
|
||||||
implicit val system = ActorSystem(s"eclair-rpc-${System.currentTimeMillis}")
|
implicit val system = ActorSystem(s"eclair-rpc-${System.currentTimeMillis}")
|
||||||
implicit val ec = system.dispatcher
|
implicit val ec = system.dispatcher
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
"applications/dlc": {
|
"applications/dlc": {
|
||||||
"title": "Executing A DLC with Bitcoin-S"
|
"title": "Executing A DLC with Bitcoin-S"
|
||||||
},
|
},
|
||||||
|
"applications/filter-sync": {
|
||||||
|
"title": "Syncing Blockfilters"
|
||||||
|
},
|
||||||
"applications/node": {
|
"applications/node": {
|
||||||
"title": "Light client"
|
"title": "Light client"
|
||||||
},
|
},
|
||||||
@ -32,6 +35,9 @@
|
|||||||
"contributing": {
|
"contributing": {
|
||||||
"title": "Contributing"
|
"title": "Contributing"
|
||||||
},
|
},
|
||||||
|
"core/adding-spks": {
|
||||||
|
"title": "Adding New Script Types"
|
||||||
|
},
|
||||||
"core/addresses": {
|
"core/addresses": {
|
||||||
"title": "Generating addresses"
|
"title": "Generating addresses"
|
||||||
},
|
},
|
||||||
@ -47,6 +53,9 @@
|
|||||||
"core/sign": {
|
"core/sign": {
|
||||||
"title": "Sign api"
|
"title": "Sign api"
|
||||||
},
|
},
|
||||||
|
"core/spending-info": {
|
||||||
|
"title": "Signing Transactions"
|
||||||
|
},
|
||||||
"core/txbuilder": {
|
"core/txbuilder": {
|
||||||
"title": "TxBuilder example"
|
"title": "TxBuilder example"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user