Skip to content

Instantly share code, notes, and snippets.

@shesek
Last active May 23, 2020 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shesek/9c82c0e50f3d2f44f36078dd8daed280 to your computer and use it in GitHub Desktop.
Save shesek/9c82c0e50f3d2f44f36078dd8daed280 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -x
shopt -s expand_aliases
trap 'bcli stop' SIGINT SIGTERM EXIT
DIR=`mktemp -d`
mkdir $DIR/bitcoin
alias bcli="bitcoin-cli -regtest -datadir=$DIR/bitcoin"
alias miner="bcli -rpcwallet=miner"
alias wallet="bcli -rpcwallet=wallet"
addr=myxGTSbZdRZdCTtYP4gYHekzAkKhQrJH6L
bitcoind -version
bitcoind -regtest -datadir=$DIR/bitcoin -wallet=miner -daemon
bcli -rpcwait createwallet wallet true
miner generatetoaddress 101 `miner getnewaddress` > /dev/null
# doesn't show up when sent before importing
txid=`miner sendtoaddress $addr 1`
wallet importaddress $addr "" true
wallet listtransactions '*' 10 0 true # empty
wallet gettransaction $txid # Invalid or non-wallet transaction id
# does show up on the sender side
miner listtransactions | jq '.[] | select(.category == "send")'
# does show up when sent after importing
miner sendtoaddress $addr 2
wallet listtransactions '*' 10 0 true # 1 entry
# now both show up
miner generatetoaddress 1 `miner getnewaddress`
wallet listtransactions '*' 10 0 true
@shesek
Copy link
Author

shesek commented May 23, 2020

+ bitcoind -version
Bitcoin Core version v0.19.1
Copyright (C) 2009-2019 The Bitcoin Core developers

+ bitcoind -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -wallet=miner -daemon
+ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwait createwallet wallet true
{
  "name": "wallet",
  "warning": ""
}
++ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=miner getnewaddress
+ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=miner generatetoaddress 101 2MvxUCx96jjyCmk5XuC49po4ZaQNusm1XdJ
++ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=miner sendtoaddress myxGTSbZdRZdCTtYP4gYHekzAkKhQrJH6L 1
+ txid=ad236b87031ed312537a7275470f24f67eff730f7560a14ab24f7c4fa9019bcb
+ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=wallet importaddress myxGTSbZdRZdCTtYP4gYHekzAkKhQrJH6L '' true
+ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=wallet listtransactions '*' 10 0 true
[
]
+ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=wallet gettransaction ad236b87031ed312537a7275470f24f67eff730f7560a14ab24f7c4fa9019bcb
error code: -5
error message:
Invalid or non-wallet transaction id
+ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=miner listtransactions
+ jq '.[] | select(.category == "send")'
{
  "address": "myxGTSbZdRZdCTtYP4gYHekzAkKhQrJH6L",
  "category": "send",
  "amount": -1,
  "vout": 1,
  "fee": -3.36e-05,
  "confirmations": 0,
  "trusted": true,
  "txid": "ad236b87031ed312537a7275470f24f67eff730f7560a14ab24f7c4fa9019bcb",
  "walletconflicts": [],
  "time": 1590209268,
  "timereceived": 1590209268,
  "bip125-replaceable": "no",
  "abandoned": false
}
+ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=miner sendtoaddress myxGTSbZdRZdCTtYP4gYHekzAkKhQrJH6L 2
3f03cafc5c72a5d3dc20584153802d4dbd3250f867e4e65e8de57fac85e9362e
+ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=wallet listtransactions '*' 10 0 true
[
  {
    "involvesWatchonly": true,
    "address": "myxGTSbZdRZdCTtYP4gYHekzAkKhQrJH6L",
    "category": "receive",
    "amount": 2.00000000,
    "label": "",
    "vout": 0,
    "confirmations": 0,
    "trusted": false,
    "txid": "3f03cafc5c72a5d3dc20584153802d4dbd3250f867e4e65e8de57fac85e9362e",
    "walletconflicts": [
    ],
    "time": 1590209269,
    "timereceived": 1590209269,
    "bip125-replaceable": "no"
  }
]
++ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=miner getnewaddress
+ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=miner generatetoaddress 1 2N8Ph3RYgXHgtbPjbkQXEuco6cBRhWFEs1B
[
  "4535c3154ab6a66c30a2a2bc922d394be4e78b065c85ef155576c129f46358dc"
]
+ bitcoin-cli -regtest -datadir=/tmp/tmp.gcE6Tx3LDs/bitcoin -rpcwallet=wallet listtransactions '*' 10 0 true
[
  {
    "involvesWatchonly": true,
    "address": "myxGTSbZdRZdCTtYP4gYHekzAkKhQrJH6L",
    "category": "receive",
    "amount": 2.00000000,
    "label": "",
    "vout": 0,
    "confirmations": 1,
    "blockhash": "4535c3154ab6a66c30a2a2bc922d394be4e78b065c85ef155576c129f46358dc",
    "blockindex": 2,
    "blocktime": 1590209286,
    "txid": "3f03cafc5c72a5d3dc20584153802d4dbd3250f867e4e65e8de57fac85e9362e",
    "walletconflicts": [
    ],
    "time": 1590209269,
    "timereceived": 1590209269,
    "bip125-replaceable": "no"
  },
  {
    "involvesWatchonly": true,
    "address": "myxGTSbZdRZdCTtYP4gYHekzAkKhQrJH6L",
    "category": "receive",
    "amount": 1.00000000,
    "label": "",
    "vout": 1,
    "confirmations": 1,
    "blockhash": "4535c3154ab6a66c30a2a2bc922d394be4e78b065c85ef155576c129f46358dc",
    "blockindex": 1,
    "blocktime": 1590209286,
    "txid": "ad236b87031ed312537a7275470f24f67eff730f7560a14ab24f7c4fa9019bcb",
    "walletconflicts": [
    ],
    "time": 1590209269,
    "timereceived": 1590209269,
    "bip125-replaceable": "no"
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment