Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
559f6eff0e | ||
|
|
34da5cfae8 | ||
|
|
9043c19d87 | ||
|
|
0560e1d30d | ||
|
|
541a8512cc | ||
|
|
5f2c12c1cc | ||
|
|
1b02f0c2c7 | ||
|
|
d706594fc9 | ||
|
|
acd8435ef6 | ||
|
|
39e7ed142d | ||
|
|
429ee21dfb | ||
|
|
da541d446c | ||
|
|
d0868cb9dd | ||
|
|
21eec96266 | ||
|
|
73987178ac | ||
|
|
0230b97a7b | ||
|
|
b1697c8ff2 | ||
|
|
f1491a24ef | ||
|
|
50436a4822 | ||
|
|
a63c69d618 | ||
|
|
4ef582f76b | ||
|
|
690ab16488 | ||
|
|
9b5a201c34 | ||
|
|
18c4c36aae |
No files matched your search
@@ -0,0 +1,89 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
pull_request:
|
||||
branches:
|
||||
- "*"
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
env:
|
||||
# go needs absolute directories, using the $HOME variable doesn't work here.
|
||||
GOCACHE: /home/runner/work/go/pkg/build
|
||||
GOPATH: /home/runner/work/go
|
||||
GO111MODULE: on
|
||||
|
||||
GO_VERSION: '^1.17.0'
|
||||
|
||||
jobs:
|
||||
########################
|
||||
# Format, compileation and lint check
|
||||
########################
|
||||
lint-check:
|
||||
name: Format, compilation and lint check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: git checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: setup go ${{ env.GO_VERSION }}
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '${{ env.GO_VERSION }}'
|
||||
|
||||
- name: run format
|
||||
run: make fmt
|
||||
|
||||
- name: compile code
|
||||
run: go install -v ./...
|
||||
|
||||
- name: run lint
|
||||
run: make lint
|
||||
|
||||
########################
|
||||
# run unit tests
|
||||
########################
|
||||
unit-test:
|
||||
name: run unit tests
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
# Allow other tests in the matrix to continue if one fails.
|
||||
fail-fast: false
|
||||
matrix:
|
||||
unit_type:
|
||||
- unit-race
|
||||
- unit-cover
|
||||
steps:
|
||||
- name: git checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: go cache
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: /home/runner/work/go
|
||||
key: btcwallet-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
btcwallet-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
|
||||
btcwallet-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-
|
||||
btcwallet-${{ runner.os }}-go-${{ env.GO_VERSION }}-
|
||||
btcwallet-${{ runner.os }}-go-
|
||||
|
||||
- name: setup go ${{ env.GO_VERSION }}
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '${{ env.GO_VERSION }}'
|
||||
|
||||
- name: run ${{ matrix.unit_type }}
|
||||
run: make ${{ matrix.unit_type }}
|
||||
|
||||
- name: Send coverage
|
||||
uses: shogo82148/actions-goveralls@v1
|
||||
if: matrix.unit_type == 'unit-cover'
|
||||
with:
|
||||
path-to-profile: coverage.txt
|
||||
parallel: true
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
language: go
|
||||
go:
|
||||
- "1.15.x"
|
||||
sudo: false
|
||||
install:
|
||||
- GO111MODULE=on go install -v ./...
|
||||
script:
|
||||
- export PATH=$PATH:$HOME/gopath/bin
|
||||
- export GO111MODULE=on
|
||||
- make fmt
|
||||
- make lint
|
||||
|
||||
# Extend unit test timeout with travis_wait
|
||||
- travis_wait make unit-race
|
||||
|
||||
- make unit-cover
|
||||
@@ -417,10 +417,12 @@ func filterNodeAddrs(nodeAddrs []btcjson.GetNodeAddressesResult) []string {
|
||||
}
|
||||
|
||||
// satisfiesRequiredServices determines whether the services signaled by a peer
|
||||
// satisfy our requirements for retrieving pruned blocks from them.
|
||||
// satisfy our requirements for retrieving pruned blocks from them. We need the
|
||||
// full chain, and witness data as well. Note that we ignore the limited
|
||||
// (pruned bit) as nodes can have the full data and set that as well. Pure
|
||||
// pruned nodes won't set the network bit.
|
||||
func satisfiesRequiredServices(services wire.ServiceFlag) bool {
|
||||
return services&requiredServices == requiredServices &&
|
||||
services&prunedNodeService != prunedNodeService
|
||||
return services&requiredServices == requiredServices
|
||||
}
|
||||
|
||||
// newQueryPeer creates a new peer instance configured to relay any received
|
||||
|
||||
@@ -620,3 +620,40 @@ func TestPrunedBlockDispatcherInvalidBlock(t *testing.T) {
|
||||
h.assertPeerQueried()
|
||||
h.assertPeerReplied(blockChan, errChan, true)
|
||||
}
|
||||
|
||||
func TestSatisfiesRequiredServices(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
services wire.ServiceFlag
|
||||
ok bool
|
||||
}{
|
||||
{
|
||||
name: "full node, segwit",
|
||||
services: wire.SFNodeWitness | wire.SFNodeNetwork,
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
name: "full node segwit, signals limited",
|
||||
services: wire.SFNodeWitness | wire.SFNodeNetwork | prunedNodeService,
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
name: "full node, no segwit",
|
||||
services: wire.SFNodeNetwork,
|
||||
ok: false,
|
||||
},
|
||||
{
|
||||
name: "segwit, pure pruned",
|
||||
services: wire.SFNodeWitness | prunedNodeService,
|
||||
ok: false,
|
||||
},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
ok := satisfiesRequiredServices(testCase.services)
|
||||
require.Equal(
|
||||
t, testCase.ok, ok, fmt.Sprintf("test case: %v", testCase.name),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ require (
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
|
||||
github.com/btcsuite/btcutil/psbt v1.0.3-0.20201208143702-a53e38424cce
|
||||
github.com/btcsuite/btcwallet/wallet/txauthor v1.0.1-0.20210329233242-e0607006dce6
|
||||
github.com/btcsuite/btcwallet/wallet/txrules v1.0.0
|
||||
github.com/btcsuite/btcwallet/wallet/txsizes v1.0.1-0.20210519225359-6ab9b615576f
|
||||
github.com/btcsuite/btcwallet/wallet/txauthor v1.1.0
|
||||
github.com/btcsuite/btcwallet/wallet/txrules v1.1.0
|
||||
github.com/btcsuite/btcwallet/wallet/txsizes v1.1.0
|
||||
github.com/btcsuite/btcwallet/walletdb v1.3.5
|
||||
github.com/btcsuite/btcwallet/wtxmgr v1.3.0
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792
|
||||
@@ -42,4 +42,4 @@ replace github.com/btcsuite/btcwallet/wallet/txsizes => ./wallet/txsizes
|
||||
// version.
|
||||
replace github.com/onsi/ginkgo => github.com/onsi/ginkgo v1.14.2
|
||||
|
||||
go 1.13
|
||||
go 1.16
|
||||
@@ -4,8 +4,6 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA
|
||||
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
|
||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||
github.com/btcsuite/btcd v0.21.0-beta.0.20201208033208-6bd4c64a54fa/go.mod h1:Sv4JPQ3/M+teHz9Bo5jBpkNcP0x6r7rdihlNL/7tTAs=
|
||||
github.com/btcsuite/btcd v0.21.0-beta.0.20210426180113-7eba688b65e5 h1:Y0v9TA1ZLSs2TNFRSrpcGk00GWq1fenVL6FsuD3dCKI=
|
||||
github.com/btcsuite/btcd v0.21.0-beta.0.20210426180113-7eba688b65e5/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
|
||||
github.com/btcsuite/btcd v0.22.0-beta.0.20210803133449-f5a1fb9965e4 h1:EmyLrldY44jDVa3dQ2iscj1S6ExuVJhRzCZBOXo93r0=
|
||||
github.com/btcsuite/btcd v0.22.0-beta.0.20210803133449-f5a1fb9965e4/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
|
||||
@@ -26,7 +24,6 @@ github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJ
|
||||
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc=
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
||||
github.com/btcsuite/winsvc v1.0.0 h1:J9B4L7e3oqhXOcm+2IuNApwzQec85lE+QaikUcCs+dk=
|
||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -38,7 +35,6 @@ github.com/decred/dcrd/lru v1.0.0 h1:Kbsb1SFDsIlaupWPwsPp+dkxiBY1frcS07PCPgotKz8
|
||||
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
|
||||
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
@@ -81,13 +77,10 @@ github.com/lightningnetwork/lnd/queue v1.0.1 h1:jzJKcTy3Nj5lQrooJ3aaw9Lau3I0IwvQ
|
||||
github.com/lightningnetwork/lnd/queue v1.0.1/go.mod h1:vaQwexir73flPW43Mrm7JOgJHmcEFBWWSl9HlyASoms=
|
||||
github.com/lightningnetwork/lnd/ticker v1.0.0 h1:S1b60TEGoTtCe2A0yeB+ecoj/kkS4qpwh6l+AkQEZwU=
|
||||
github.com/lightningnetwork/lnd/ticker v1.0.0/go.mod h1:iaLXJiVgI1sPANIF2qYYUJXjoksPNvGNYowB8aRbpX0=
|
||||
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/onsi/ginkgo v1.14.2 h1:8mVmC9kjFFmA8H4pKMUhcblgifdkOIXPvbhN1T36q1M=
|
||||
github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
||||
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
@@ -155,7 +148,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !windows && !plan9
|
||||
// +build !windows,!plan9
|
||||
|
||||
package rename
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !js
|
||||
// +build !js
|
||||
|
||||
package prompt
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//+build generate
|
||||
//go:build generate
|
||||
// +build generate
|
||||
|
||||
package main
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//+build !generate
|
||||
//go:build !generate
|
||||
// +build !generate
|
||||
|
||||
package rpchelp
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//+build !generate
|
||||
//go:build !generate
|
||||
// +build !generate
|
||||
|
||||
package rpchelp
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||
|
||||
package main
|
||||
|
||||
@@ -27,6 +27,8 @@ var (
|
||||
0xb6, 0xc4, 0x40, 0xc0, 0x64,
|
||||
}
|
||||
|
||||
rootKey, _ = hdkeychain.NewMaster(seed, &chaincfg.MainNetParams)
|
||||
|
||||
pubPassphrase = []byte("_DJr{fL4H0O}*-0\n:V1izc)(6BomK")
|
||||
privPassphrase = []byte("81lUHXnOMZ@?XXd7O9xyDIWIbXX-lj")
|
||||
pubPassphrase2 = []byte("-0NV4P~VSJBWbunw}%<Z]fuGpbN[ZI")
|
||||
@@ -285,7 +287,7 @@ func setupManager(t *testing.T) (tearDownFunc func(), db walletdb.DB, mgr *Manag
|
||||
return err
|
||||
}
|
||||
err = Create(
|
||||
ns, seed, pubPassphrase, privPassphrase,
|
||||
ns, rootKey, pubPassphrase, privPassphrase,
|
||||
&chaincfg.MainNetParams, fastScrypt, time.Time{},
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -139,6 +139,10 @@ const (
|
||||
// ErrBlockNotFound is returned when we attempt to retrieve the hash for
|
||||
// a block that we do not know of.
|
||||
ErrBlockNotFound
|
||||
|
||||
// ErrAccountNotCached is returned when we attempt to perform an
|
||||
// operation that relies on an account begin cached but it isn't.
|
||||
ErrAccountNotCached
|
||||
)
|
||||
|
||||
// Map of ErrorCode values back to their constant names for pretty printing.
|
||||
@@ -165,6 +169,7 @@ var errorCodeStrings = map[ErrorCode]string{
|
||||
ErrCallBackBreak: "ErrCallBackBreak",
|
||||
ErrEmptyPassphrase: "ErrEmptyPassphrase",
|
||||
ErrScopeNotFound: "ErrScopeNotFound",
|
||||
ErrAccountNotCached: "ErrAccountNotCached",
|
||||
}
|
||||
|
||||
// String returns the ErrorCode as a human-readable name.
|
||||
|
||||
+15
-19
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/btcsuite/btcwallet/internal/zero"
|
||||
"github.com/btcsuite/btcwallet/snacl"
|
||||
"github.com/btcsuite/btcwallet/walletdb"
|
||||
"github.com/lightninglabs/neutrino/cache/lru"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -602,11 +603,12 @@ func (m *Manager) NewScopedKeyManager(ns walletdb.ReadWriteBucket,
|
||||
// Finally, we'll register this new scoped manager with the root
|
||||
// manager.
|
||||
m.scopedManagers[scope] = &ScopedKeyManager{
|
||||
scope: scope,
|
||||
addrSchema: addrSchema,
|
||||
rootManager: m,
|
||||
addrs: make(map[addrKey]ManagedAddress),
|
||||
acctInfo: make(map[uint32]*accountInfo),
|
||||
scope: scope,
|
||||
addrSchema: addrSchema,
|
||||
rootManager: m,
|
||||
addrs: make(map[addrKey]ManagedAddress),
|
||||
acctInfo: make(map[uint32]*accountInfo),
|
||||
privKeyCache: lru.NewCache(defaultPrivKeyCacheSize),
|
||||
}
|
||||
m.externalAddrSchemas[addrSchema.ExternalAddrType] = append(
|
||||
m.externalAddrSchemas[addrSchema.ExternalAddrType], scope,
|
||||
@@ -1620,10 +1622,11 @@ func loadManager(ns walletdb.ReadBucket, pubPassphrase []byte,
|
||||
}
|
||||
|
||||
scopedManagers[scope] = &ScopedKeyManager{
|
||||
scope: scope,
|
||||
addrSchema: *scopeSchema,
|
||||
addrs: make(map[addrKey]ManagedAddress),
|
||||
acctInfo: make(map[uint32]*accountInfo),
|
||||
scope: scope,
|
||||
addrSchema: *scopeSchema,
|
||||
addrs: make(map[addrKey]ManagedAddress),
|
||||
acctInfo: make(map[uint32]*accountInfo),
|
||||
privKeyCache: lru.NewCache(defaultPrivKeyCacheSize),
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -1800,13 +1803,13 @@ func createManagerKeyScope(ns walletdb.ReadWriteBucket,
|
||||
// A ManagerError with an error code of ErrAlreadyExists will be
|
||||
// returned the address manager already exists in the specified
|
||||
// namespace.
|
||||
func Create(ns walletdb.ReadWriteBucket,
|
||||
seed, pubPassphrase, privPassphrase []byte,
|
||||
func Create(ns walletdb.ReadWriteBucket, rootKey *hdkeychain.ExtendedKey,
|
||||
pubPassphrase, privPassphrase []byte,
|
||||
chainParams *chaincfg.Params, config *ScryptOptions,
|
||||
birthday time.Time) error {
|
||||
|
||||
// If the seed argument is nil we create in watchingOnly mode.
|
||||
isWatchingOnly := seed == nil
|
||||
isWatchingOnly := rootKey == nil
|
||||
|
||||
// Return an error if the manager has already been created in
|
||||
// the given database namespace.
|
||||
@@ -1922,13 +1925,6 @@ func Create(ns walletdb.ReadWriteBucket,
|
||||
// Generate the BIP0044 HD key structure to ensure the
|
||||
// provided seed can generate the required structure with no
|
||||
// issues.
|
||||
|
||||
// Derive the master extended key from the seed.
|
||||
rootKey, err := hdkeychain.NewMaster(seed, chainParams)
|
||||
if err != nil {
|
||||
str := "failed to derive master extended key"
|
||||
return managerError(ErrKeyChain, str, err)
|
||||
}
|
||||
rootPubKey, err := rootKey.Neuter()
|
||||
if err != nil {
|
||||
str := "failed to neuter master extended key"
|
||||
|
||||
+110
-12
@@ -14,6 +14,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcutil"
|
||||
@@ -21,6 +22,7 @@ import (
|
||||
"github.com/btcsuite/btcwallet/snacl"
|
||||
"github.com/btcsuite/btcwallet/walletdb"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// failingCryptoKey is an implementation of the EncryptorDecryptor interface
|
||||
@@ -1816,32 +1818,35 @@ func TestManager(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
createdWatchingOnly bool
|
||||
seed []byte
|
||||
rootKey *hdkeychain.ExtendedKey
|
||||
privPassphrase []byte
|
||||
}{
|
||||
{
|
||||
name: "created with seed",
|
||||
createdWatchingOnly: false,
|
||||
seed: seed,
|
||||
rootKey: rootKey,
|
||||
privPassphrase: privPassphrase,
|
||||
},
|
||||
{
|
||||
name: "created watch-only",
|
||||
createdWatchingOnly: true,
|
||||
seed: nil,
|
||||
rootKey: nil,
|
||||
privPassphrase: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
// Need to wrap in a call so the defers work correctly.
|
||||
testManagerCase(t, test.name, test.createdWatchingOnly,
|
||||
test.seed, test.privPassphrase)
|
||||
testManagerCase(
|
||||
t, test.name, test.createdWatchingOnly,
|
||||
test.privPassphrase, test.rootKey,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func testManagerCase(t *testing.T, caseName string,
|
||||
caseCreatedWatchingOnly bool, caseSeed, casePrivPassphrase []byte) {
|
||||
caseCreatedWatchingOnly bool, casePrivPassphrase []byte,
|
||||
caseKey *hdkeychain.ExtendedKey) {
|
||||
|
||||
teardown, db := emptyDB(t)
|
||||
defer teardown()
|
||||
@@ -1867,7 +1872,7 @@ func testManagerCase(t *testing.T, caseName string,
|
||||
return err
|
||||
}
|
||||
err = Create(
|
||||
ns, caseSeed, pubPassphrase, casePrivPassphrase,
|
||||
ns, caseKey, pubPassphrase, casePrivPassphrase,
|
||||
&chaincfg.MainNetParams, fastScrypt, time.Time{},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -1897,7 +1902,7 @@ func testManagerCase(t *testing.T, caseName string,
|
||||
err = walletdb.Update(db, func(tx walletdb.ReadWriteTx) error {
|
||||
ns := tx.ReadWriteBucket(waddrmgrNamespaceKey)
|
||||
return Create(
|
||||
ns, caseSeed, pubPassphrase, casePrivPassphrase,
|
||||
ns, caseKey, pubPassphrase, casePrivPassphrase,
|
||||
&chaincfg.MainNetParams, fastScrypt, time.Time{},
|
||||
)
|
||||
})
|
||||
@@ -2193,7 +2198,7 @@ func TestScopedKeyManagerManagement(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
err = Create(
|
||||
ns, seed, pubPassphrase, privPassphrase,
|
||||
ns, rootKey, pubPassphrase, privPassphrase,
|
||||
&chaincfg.MainNetParams, fastScrypt, time.Time{},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -2442,7 +2447,7 @@ func TestRootHDKeyNeutering(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
err = Create(
|
||||
ns, seed, pubPassphrase, privPassphrase,
|
||||
ns, rootKey, pubPassphrase, privPassphrase,
|
||||
&chaincfg.MainNetParams, fastScrypt, time.Time{},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -2534,7 +2539,7 @@ func TestNewRawAccount(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
err = Create(
|
||||
ns, seed, pubPassphrase, privPassphrase,
|
||||
ns, rootKey, pubPassphrase, privPassphrase,
|
||||
&chaincfg.MainNetParams, fastScrypt, time.Time{},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -2660,7 +2665,7 @@ func TestNewRawAccountHybrid(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
err = Create(
|
||||
ns, seed, pubPassphrase, privPassphrase,
|
||||
ns, rootKey, pubPassphrase, privPassphrase,
|
||||
&chaincfg.MainNetParams, fastScrypt, time.Time{},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -2761,3 +2766,96 @@ func testNewRawAccount(t *testing.T, _ *Manager, db walletdb.DB,
|
||||
accountTargetAddr.AddrHash())
|
||||
}
|
||||
}
|
||||
|
||||
// TestDeriveFromKeyPathCache tests that the DeriveFromKeyPathCache method will
|
||||
// properly cache items in the cache, and return corresponding errors if the
|
||||
// account isn't properly cached.
|
||||
func TestDeriveFromKeyPathCache(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
teardown, db := emptyDB(t)
|
||||
defer teardown()
|
||||
|
||||
// We'll start the test by creating a new root manager that will be
|
||||
// used for the duration of the test.
|
||||
var mgr *Manager
|
||||
err := walletdb.Update(db, func(tx walletdb.ReadWriteTx) error {
|
||||
ns, err := tx.CreateTopLevelBucket(waddrmgrNamespaceKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = Create(
|
||||
ns, rootKey, pubPassphrase, privPassphrase,
|
||||
&chaincfg.MainNetParams, fastScrypt, time.Time{},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mgr, err = Open(ns, pubPassphrase, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return mgr.Unlock(ns, privPassphrase)
|
||||
})
|
||||
require.NoError(t, err, "create/open: unexpected error: %v", err)
|
||||
|
||||
defer mgr.Close()
|
||||
|
||||
// Now that we have the manager created, we'll fetch one of the default
|
||||
// scopes for usage within this test.
|
||||
scopedMgr, err := mgr.FetchScopedKeyManager(KeyScopeBIP0044)
|
||||
require.NoError(
|
||||
t, err, "unable to fetch scope %v: %v", KeyScopeBIP0044, err,
|
||||
)
|
||||
|
||||
keyPath := DerivationPath{
|
||||
InternalAccount: 0,
|
||||
Account: hdkeychain.HardenedKeyStart,
|
||||
Branch: 10,
|
||||
Index: 1,
|
||||
}
|
||||
|
||||
// Our test starts here, we'll attempt to derive a new key using the
|
||||
// cached method. This should fail at first since the account itself
|
||||
// isn't cached.
|
||||
_, err = scopedMgr.DeriveFromKeyPathCache(keyPath)
|
||||
if !IsError(err, ErrAccountNotCached) {
|
||||
t.Fatalf("didn't get account not cached error: %v", err)
|
||||
}
|
||||
|
||||
// Now we'll attempt to derive the key using the normal method that
|
||||
// requires a database transaction.
|
||||
var derivedKey *btcec.PrivateKey
|
||||
err = walletdb.Update(db, func(tx walletdb.ReadWriteTx) error {
|
||||
ns := tx.ReadWriteBucket(waddrmgrNamespaceKey)
|
||||
|
||||
managedAddr, err := scopedMgr.DeriveFromKeyPath(
|
||||
ns, keyPath,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
derivedKey, err = managedAddr.(ManagedPubKeyAddress).PrivKey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err, "unable to derive addr: %v", err)
|
||||
|
||||
// Next attempt to read the key again from the cache, it should succeed
|
||||
// this time.
|
||||
cachedKey, err := scopedMgr.DeriveFromKeyPathCache(keyPath)
|
||||
require.NoError(t, err, "account wasn't cached")
|
||||
|
||||
// We should be able to read the key again.
|
||||
cachedKey2, err := scopedMgr.DeriveFromKeyPathCache(keyPath)
|
||||
require.NoError(t, err, "account wasn't cached")
|
||||
|
||||
// All three keys we have now should match exactly.
|
||||
require.Equal(t, cachedKey.Serialize(), cachedKey2.Serialize())
|
||||
require.Equal(t, derivedKey.Serialize(), cachedKey2.Serialize())
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/btcsuite/btcwallet/internal/zero"
|
||||
"github.com/btcsuite/btcwallet/netparams"
|
||||
"github.com/btcsuite/btcwallet/walletdb"
|
||||
"github.com/lightninglabs/neutrino/cache/lru"
|
||||
)
|
||||
|
||||
// HDVersion represents the different supported schemes of hierarchical
|
||||
@@ -51,6 +52,14 @@ const (
|
||||
HDVersionSimNetBIP0044 HDVersion = 0x0420bd3a // spub
|
||||
)
|
||||
|
||||
const (
|
||||
// privKeyCacheSize is the default size of the LRU cache that we'll use
|
||||
// to cache private keys to avoid DB and EC operations within the
|
||||
// wallet. With the default sisize, we'll allocate up to 320 KB to
|
||||
// caching private keys (ignoring pointer overhead, etc).
|
||||
defaultPrivKeyCacheSize = 10_000
|
||||
)
|
||||
|
||||
// DerivationPath represents a derivation path from a particular key manager's
|
||||
// scope. Each ScopedKeyManager starts key derivation from the end of their
|
||||
// cointype hardened key: m/purpose'/cointype'. The fields in this struct allow
|
||||
@@ -220,7 +229,7 @@ type ScopedKeyManager struct {
|
||||
rootManager *Manager
|
||||
|
||||
// addrs is a cached map of all the addresses that we currently
|
||||
// manager.
|
||||
// manage.
|
||||
addrs map[addrKey]ManagedAddress
|
||||
|
||||
// acctInfo houses information about accounts including what is needed
|
||||
@@ -234,6 +243,11 @@ type ScopedKeyManager struct {
|
||||
// order to encrypt it.
|
||||
deriveOnUnlock []*unlockDeriveInfo
|
||||
|
||||
// privKeyCache stores the set of private keys that have been marked as
|
||||
// items to be cached to allow us to avoid the database and EC
|
||||
// operations each time a key need to be obtained.
|
||||
privKeyCache *lru.Cache
|
||||
|
||||
mtx sync.RWMutex
|
||||
}
|
||||
|
||||
@@ -504,8 +518,8 @@ func (s *ScopedKeyManager) loadAccountInfo(ns walletdb.ReadBucket,
|
||||
func (s *ScopedKeyManager) AccountProperties(ns walletdb.ReadBucket,
|
||||
account uint32) (*AccountProperties, error) {
|
||||
|
||||
defer s.mtx.RUnlock()
|
||||
s.mtx.RLock()
|
||||
s.mtx.Lock()
|
||||
defer s.mtx.Unlock()
|
||||
|
||||
props := &AccountProperties{
|
||||
AccountNumber: account,
|
||||
@@ -579,6 +593,77 @@ func (s *ScopedKeyManager) AccountProperties(ns walletdb.ReadBucket,
|
||||
return props, nil
|
||||
}
|
||||
|
||||
// cachedKey is an entry within the LRU map that stores private keys that are
|
||||
// to be used frequently. We use this wrapper struct to be able too report the
|
||||
// size of a given element to the cache.
|
||||
type cachedKey struct {
|
||||
key *btcec.PrivateKey
|
||||
}
|
||||
|
||||
// Size returns the size of this element. Rather than have the cache limit
|
||||
// based on bytes, we simply report that each element is of size 1, meaning we
|
||||
// can set our cached based on the amount of keys we want to store, rather than
|
||||
// the total size of all the keys.
|
||||
func (c *cachedKey) Size() (uint64, error) {
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
// DeriveFromKeyPathCache is identical to DeriveFromKeyPath, however it'll fail
|
||||
// if the account refracted in the DerivationPath isn't already in the
|
||||
// in-memory cache. Callers looking for faster private key retrieval can opt to
|
||||
// call this method, which may fail if things aren't in the cache, then fall
|
||||
// back to the normal variant. The account can information can be drawn into
|
||||
// the cache if the normal DeriveFromKeyPath method is used, or the account is
|
||||
// looked up via any other means.
|
||||
func (s *ScopedKeyManager) DeriveFromKeyPathCache(
|
||||
kp DerivationPath) (*btcec.PrivateKey, error) {
|
||||
|
||||
s.mtx.Lock()
|
||||
defer s.mtx.Unlock()
|
||||
|
||||
// First, try to look up the key itself in the proper cache, if the key
|
||||
// is here, then we don't need to do anything further.
|
||||
privKeyVal, err := s.privKeyCache.Get(kp)
|
||||
if err == nil {
|
||||
return privKeyVal.(*cachedKey).key, nil
|
||||
}
|
||||
|
||||
// If the key isn't already in the cache, then we'll try to look up the
|
||||
// account info in the cache, if this fails, then we exit here as we
|
||||
// can't move forward without creating a DB transaction, and the point
|
||||
// of this method is to avoid that.
|
||||
acctInfo, ok := s.acctInfo[kp.InternalAccount]
|
||||
if !ok {
|
||||
return nil, managerError(
|
||||
ErrAccountNotCached,
|
||||
"", fmt.Errorf("acct %v not cached", kp.InternalAccount),
|
||||
)
|
||||
}
|
||||
|
||||
watchOnly := s.rootManager.WatchOnly()
|
||||
private := !s.rootManager.IsLocked() && !watchOnly
|
||||
|
||||
// Now that we have the account information, we can derive the key
|
||||
// directly.
|
||||
addrKey, err := s.deriveKey(acctInfo, kp.Branch, kp.Index, private)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Now that we have the key, we'll attempt to insert it into the cache,
|
||||
// and return it as is.
|
||||
privKey, err := addrKey.ECPrivKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = s.privKeyCache.Put(kp, &cachedKey{key: privKey})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return privKey, nil
|
||||
}
|
||||
|
||||
// DeriveFromKeyPath attempts to derive a maximal child key (under the BIP0044
|
||||
// scheme) from a given key path. If key derivation isn't possible, then an
|
||||
// error will be returned.
|
||||
|
||||
+43
-1
@@ -204,6 +204,30 @@ func (w *Wallet) ImportAccount(name string, accountPubKey *hdkeychain.ExtendedKe
|
||||
return accountProps, err
|
||||
}
|
||||
|
||||
// ImportAccountWithScope imports an account backed by an account extended
|
||||
// public key for a specific key scope which is known in advance.
|
||||
// The master key fingerprint denotes the fingerprint of the root key
|
||||
// corresponding to the account public key (also known as the key with
|
||||
// derivation path m/). This may be required by some hardware wallets for proper
|
||||
// identification and signing.
|
||||
func (w *Wallet) ImportAccountWithScope(name string,
|
||||
accountPubKey *hdkeychain.ExtendedKey, masterKeyFingerprint uint32,
|
||||
keyScope waddrmgr.KeyScope, addrSchema waddrmgr.ScopeAddrSchema) (
|
||||
*waddrmgr.AccountProperties, error) {
|
||||
|
||||
var accountProps *waddrmgr.AccountProperties
|
||||
err := walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error {
|
||||
ns := tx.ReadWriteBucket(waddrmgrNamespaceKey)
|
||||
var err error
|
||||
accountProps, err = w.importAccountScope(
|
||||
ns, name, accountPubKey, masterKeyFingerprint, keyScope,
|
||||
&addrSchema,
|
||||
)
|
||||
return err
|
||||
})
|
||||
return accountProps, err
|
||||
}
|
||||
|
||||
// importAccount is the internal implementation of ImportAccount -- one should
|
||||
// reference its documentation for this method.
|
||||
func (w *Wallet) importAccount(ns walletdb.ReadWriteBucket, name string,
|
||||
@@ -221,9 +245,27 @@ func (w *Wallet) importAccount(ns walletdb.ReadWriteBucket, name string,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return w.importAccountScope(
|
||||
ns, name, accountPubKey, masterKeyFingerprint, keyScope,
|
||||
addrSchema,
|
||||
)
|
||||
}
|
||||
|
||||
// importAccountScope imports a watch-only account for a given scope.
|
||||
func (w *Wallet) importAccountScope(ns walletdb.ReadWriteBucket, name string,
|
||||
accountPubKey *hdkeychain.ExtendedKey, masterKeyFingerprint uint32,
|
||||
keyScope waddrmgr.KeyScope, addrSchema *waddrmgr.ScopeAddrSchema) (
|
||||
*waddrmgr.AccountProperties, error) {
|
||||
|
||||
scopedMgr, err := w.Manager.FetchScopedKeyManager(keyScope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
scopedMgr, err = w.Manager.NewScopedKeyManager(
|
||||
ns, keyScope, *addrSchema,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
account, err := scopedMgr.NewAccountWatchingOnly(
|
||||
|
||||
+40
-4
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcutil/hdkeychain"
|
||||
"github.com/btcsuite/btcwallet/internal/prompt"
|
||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||
"github.com/btcsuite/btcwallet/walletdb"
|
||||
@@ -145,8 +146,42 @@ func (l *Loader) OnWalletCreated(fn func(walletdb.ReadWriteTx) error) {
|
||||
func (l *Loader) CreateNewWallet(pubPassphrase, privPassphrase, seed []byte,
|
||||
bday time.Time) (*Wallet, error) {
|
||||
|
||||
var (
|
||||
rootKey *hdkeychain.ExtendedKey
|
||||
err error
|
||||
)
|
||||
|
||||
// If a seed was specified, we check its length now. If no seed is
|
||||
// passed, the wallet will create a new random one.
|
||||
if seed != nil {
|
||||
if len(seed) < hdkeychain.MinSeedBytes ||
|
||||
len(seed) > hdkeychain.MaxSeedBytes {
|
||||
|
||||
return nil, hdkeychain.ErrInvalidSeedLen
|
||||
}
|
||||
|
||||
// Derive the master extended key from the seed.
|
||||
rootKey, err = hdkeychain.NewMaster(seed, l.chainParams)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to derive master " +
|
||||
"extended key")
|
||||
}
|
||||
}
|
||||
|
||||
return l.createNewWallet(
|
||||
pubPassphrase, privPassphrase, seed, bday, false,
|
||||
pubPassphrase, privPassphrase, rootKey, bday, false,
|
||||
)
|
||||
}
|
||||
|
||||
// CreateNewWalletExtendedKey creates a new wallet from an extended master root
|
||||
// key using the provided public and private passphrases. The root key is
|
||||
// optional. If non-nil, addresses are derived from this root key. If nil, a
|
||||
// secure random seed is generated and the root key is derived from that.
|
||||
func (l *Loader) CreateNewWalletExtendedKey(pubPassphrase, privPassphrase []byte,
|
||||
rootKey *hdkeychain.ExtendedKey, bday time.Time) (*Wallet, error) {
|
||||
|
||||
return l.createNewWallet(
|
||||
pubPassphrase, privPassphrase, rootKey, bday, false,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -161,8 +196,9 @@ func (l *Loader) CreateNewWatchingOnlyWallet(pubPassphrase []byte,
|
||||
)
|
||||
}
|
||||
|
||||
func (l *Loader) createNewWallet(pubPassphrase, privPassphrase,
|
||||
seed []byte, bday time.Time, isWatchingOnly bool) (*Wallet, error) {
|
||||
func (l *Loader) createNewWallet(pubPassphrase, privPassphrase []byte,
|
||||
rootKey *hdkeychain.ExtendedKey, bday time.Time,
|
||||
isWatchingOnly bool) (*Wallet, error) {
|
||||
|
||||
defer l.mu.Unlock()
|
||||
l.mu.Lock()
|
||||
@@ -206,7 +242,7 @@ func (l *Loader) createNewWallet(pubPassphrase, privPassphrase,
|
||||
}
|
||||
} else {
|
||||
err := CreateWithCallback(
|
||||
l.db, pubPassphrase, privPassphrase, seed,
|
||||
l.db, pubPassphrase, privPassphrase, rootKey,
|
||||
l.chainParams, bday, l.walletCreated,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
+2
-2
@@ -41,7 +41,7 @@ import (
|
||||
// selected/validated inputs by this method. It is in the caller's
|
||||
// responsibility to lock the inputs before handing the partial transaction out.
|
||||
func (w *Wallet) FundPsbt(packet *psbt.Packet, keyScope *waddrmgr.KeyScope,
|
||||
account uint32, feeSatPerKB btcutil.Amount,
|
||||
minConfs int32, account uint32, feeSatPerKB btcutil.Amount,
|
||||
coinSelectionStrategy CoinSelectionStrategy) (int32, error) {
|
||||
|
||||
// Make sure the packet is well formed. We only require there to be at
|
||||
@@ -138,7 +138,7 @@ func (w *Wallet) FundPsbt(packet *psbt.Packet, keyScope *waddrmgr.KeyScope,
|
||||
// includes everything we need, specifically fee estimation and
|
||||
// change address creation.
|
||||
tx, err = w.CreateSimpleTx(
|
||||
keyScope, account, packet.UnsignedTx.TxOut, 1,
|
||||
keyScope, account, packet.UnsignedTx.TxOut, minConfs,
|
||||
feeSatPerKB, coinSelectionStrategy, false,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
+1
-1
@@ -234,7 +234,7 @@ func TestFundPsbt(t *testing.T) {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
changeIndex, err := w.FundPsbt(
|
||||
tc.packet, nil, 0, tc.feeRateSatPerKB,
|
||||
tc.packet, nil, 1, 0, tc.feeRateSatPerKB,
|
||||
CoinSelectionLargest,
|
||||
)
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ module github.com/btcsuite/btcwallet/wallet/txauthor
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
|
||||
github.com/btcsuite/btcd v0.22.0-beta.0.20210803133449-f5a1fb9965e4
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
|
||||
github.com/btcsuite/btcwallet/wallet/txrules v1.0.0
|
||||
github.com/btcsuite/btcwallet/wallet/txsizes v1.0.0
|
||||
)
|
||||
|
||||
+18
-5
@@ -1,10 +1,14 @@
|
||||
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.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0=
|
||||
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
|
||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||
github.com/btcsuite/btcd v0.22.0-beta.0.20210803133449-f5a1fb9965e4 h1:EmyLrldY44jDVa3dQ2iscj1S6ExuVJhRzCZBOXo93r0=
|
||||
github.com/btcsuite/btcd v0.22.0-beta.0.20210803133449-f5a1fb9965e4/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ=
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o=
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
||||
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
|
||||
github.com/btcsuite/goleveldb v1.0.0 h1:Tvd0BfvqX9o823q1j2UZ/epQo09eJh6dTcRp79ilIN4=
|
||||
@@ -15,8 +19,10 @@ github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
@@ -24,7 +30,9 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
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/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
@@ -37,18 +45,23 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
|
||||
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44 h1:9lP3x0pW80sDI6t1UMSLA4to18W7R7imwAI/sWS9S8Q=
|
||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
|
||||
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 h1:bfLnR+k0tq5Lqt6dflRLcZiz6UaXCMt3vhYJ1l4FQ80=
|
||||
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
||||
@@ -3,6 +3,6 @@ module github.com/btcsuite/btcwallet/wallet/txrules
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
|
||||
github.com/btcsuite/btcd v0.22.0-beta.0.20210803133449-f5a1fb9965e4
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
|
||||
)
|
||||
+38
-5
@@ -1,33 +1,66 @@
|
||||
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.0.0-20190824003749-130ea5bddde3 h1:A/EVblehb75cUgXA5njHPn0kLAsykn6mJGz7rnmW5W0=
|
||||
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
|
||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||
github.com/btcsuite/btcd v0.22.0-beta.0.20210803133449-f5a1fb9965e4 h1:EmyLrldY44jDVa3dQ2iscj1S6ExuVJhRzCZBOXo93r0=
|
||||
github.com/btcsuite/btcd v0.22.0-beta.0.20210803133449-f5a1fb9965e4/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ=
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o=
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
||||
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
|
||||
github.com/btcsuite/goleveldb v1.0.0 h1:Tvd0BfvqX9o823q1j2UZ/epQo09eJh6dTcRp79ilIN4=
|
||||
github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I=
|
||||
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
||||
github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJGQE=
|
||||
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495 h1:6IyqGr3fnd0tM3YxipK27TUskaOVUjU2nG45yzwcQKY=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
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/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44 h1:9lP3x0pW80sDI6t1UMSLA4to18W7R7imwAI/sWS9S8Q=
|
||||
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=
|
||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
+62
-31
@@ -72,6 +72,10 @@ var (
|
||||
// to true.
|
||||
ErrTxLabelExists = errors.New("transaction already labelled")
|
||||
|
||||
// ErrTxUnsigned is returned when a transaction is created in the
|
||||
// watch-only mode where we can select coins but not sign any inputs.
|
||||
ErrTxUnsigned = errors.New("watch-only wallet, transaction not signed")
|
||||
|
||||
// Namespace bucket keys.
|
||||
waddrmgrNamespaceKey = []byte("waddrmgr")
|
||||
wtxmgrNamespaceKey = []byte("wtxmgr")
|
||||
@@ -1169,17 +1173,27 @@ out:
|
||||
for {
|
||||
select {
|
||||
case txr := <-w.createTxRequests:
|
||||
heldUnlock, err := w.holdUnlock()
|
||||
if err != nil {
|
||||
txr.resp <- createTxResponse{nil, err}
|
||||
continue
|
||||
// If the wallet can be locked because it contains
|
||||
// private key material, we need to prevent it from
|
||||
// doing so while we are assembling the transaction.
|
||||
release := func() {}
|
||||
if !w.Manager.WatchOnly() {
|
||||
heldUnlock, err := w.holdUnlock()
|
||||
if err != nil {
|
||||
txr.resp <- createTxResponse{nil, err}
|
||||
continue
|
||||
}
|
||||
|
||||
release = heldUnlock.release
|
||||
}
|
||||
|
||||
tx, err := w.txToOutputs(
|
||||
txr.outputs, txr.keyScope, txr.account,
|
||||
txr.minconf, txr.feeSatPerKB,
|
||||
txr.coinSelectionStrategy, txr.dryRun,
|
||||
)
|
||||
heldUnlock.release()
|
||||
|
||||
release()
|
||||
txr.resp <- createTxResponse{tx, err}
|
||||
case <-quit:
|
||||
break out
|
||||
@@ -3199,6 +3213,13 @@ func (w *Wallet) SendOutputs(outputs []*wire.TxOut, keyScope *waddrmgr.KeyScope,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// If our wallet is read-only, we'll get a transaction with coins
|
||||
// selected but no witness data. In such a case we need to inform our
|
||||
// caller that they'll actually need to go ahead and sign the TX.
|
||||
if w.Manager.WatchOnly() {
|
||||
return createdTx.Tx, ErrTxUnsigned
|
||||
}
|
||||
|
||||
txHash, err := w.reliablyPublishTransaction(createdTx.Tx, label)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -3686,12 +3707,12 @@ func (w *Wallet) Database() walletdb.DB {
|
||||
|
||||
// CreateWithCallback is the same as Create with an added callback that will be
|
||||
// called in the same transaction the wallet structure is initialized.
|
||||
func CreateWithCallback(db walletdb.DB, pubPass, privPass, seed []byte,
|
||||
params *chaincfg.Params, birthday time.Time,
|
||||
cb func(walletdb.ReadWriteTx) error) error {
|
||||
func CreateWithCallback(db walletdb.DB, pubPass, privPass []byte,
|
||||
rootKey *hdkeychain.ExtendedKey, params *chaincfg.Params,
|
||||
birthday time.Time, cb func(walletdb.ReadWriteTx) error) error {
|
||||
|
||||
return create(
|
||||
db, pubPass, privPass, seed, params, birthday, false, cb,
|
||||
db, pubPass, privPass, rootKey, params, birthday, false, cb,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3708,18 +3729,19 @@ func CreateWatchingOnlyWithCallback(db walletdb.DB, pubPass []byte,
|
||||
}
|
||||
|
||||
// Create creates an new wallet, writing it to an empty database. If the passed
|
||||
// seed is non-nil, it is used. Otherwise, a secure random seed of the
|
||||
// root key is non-nil, it is used. Otherwise, a secure random seed of the
|
||||
// recommended length is generated.
|
||||
func Create(db walletdb.DB, pubPass, privPass, seed []byte,
|
||||
params *chaincfg.Params, birthday time.Time) error {
|
||||
func Create(db walletdb.DB, pubPass, privPass []byte,
|
||||
rootKey *hdkeychain.ExtendedKey, params *chaincfg.Params,
|
||||
birthday time.Time) error {
|
||||
|
||||
return create(
|
||||
db, pubPass, privPass, seed, params, birthday, false, nil,
|
||||
db, pubPass, privPass, rootKey, params, birthday, false, nil,
|
||||
)
|
||||
}
|
||||
|
||||
// CreateWatchingOnly creates an new watch-only wallet, writing it to
|
||||
// an empty database. No seed can be provided as this wallet will be
|
||||
// an empty database. No root key can be provided as this wallet will be
|
||||
// watching only. Likewise no private passphrase may be provided
|
||||
// either.
|
||||
func CreateWatchingOnly(db walletdb.DB, pubPass []byte,
|
||||
@@ -3730,28 +3752,36 @@ func CreateWatchingOnly(db walletdb.DB, pubPass []byte,
|
||||
)
|
||||
}
|
||||
|
||||
func create(db walletdb.DB, pubPass, privPass, seed []byte,
|
||||
params *chaincfg.Params, birthday time.Time, isWatchingOnly bool,
|
||||
func create(db walletdb.DB, pubPass, privPass []byte,
|
||||
rootKey *hdkeychain.ExtendedKey, params *chaincfg.Params,
|
||||
birthday time.Time, isWatchingOnly bool,
|
||||
cb func(walletdb.ReadWriteTx) error) error {
|
||||
|
||||
if !isWatchingOnly {
|
||||
// If a seed was provided, ensure that it is of valid length. Otherwise,
|
||||
// we generate a random seed for the wallet with the recommended seed
|
||||
// length.
|
||||
if seed == nil {
|
||||
hdSeed, err := hdkeychain.GenerateSeed(
|
||||
hdkeychain.RecommendedSeedLen)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
seed = hdSeed
|
||||
// If no root key was provided, we create one now from a random seed.
|
||||
// But only if this is not a watching-only wallet where the accounts are
|
||||
// created individually from their xpubs.
|
||||
if !isWatchingOnly && rootKey == nil {
|
||||
hdSeed, err := hdkeychain.GenerateSeed(
|
||||
hdkeychain.RecommendedSeedLen,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(seed) < hdkeychain.MinSeedBytes ||
|
||||
len(seed) > hdkeychain.MaxSeedBytes {
|
||||
return hdkeychain.ErrInvalidSeedLen
|
||||
|
||||
// Derive the master extended key from the seed.
|
||||
rootKey, err = hdkeychain.NewMaster(hdSeed, params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to derive master extended " +
|
||||
"key")
|
||||
}
|
||||
}
|
||||
|
||||
// We need a private key if this isn't a watching only wallet.
|
||||
if !isWatchingOnly && rootKey != nil && !rootKey.IsPrivate() {
|
||||
return fmt.Errorf("need extended private key for wallet that " +
|
||||
"is not watching only")
|
||||
}
|
||||
|
||||
return walletdb.Update(db, func(tx walletdb.ReadWriteTx) error {
|
||||
addrmgrNs, err := tx.CreateTopLevelBucket(waddrmgrNamespaceKey)
|
||||
if err != nil {
|
||||
@@ -3763,7 +3793,8 @@ func create(db walletdb.DB, pubPass, privPass, seed []byte,
|
||||
}
|
||||
|
||||
err = waddrmgr.Create(
|
||||
addrmgrNs, seed, pubPass, privPass, params, nil, birthday,
|
||||
addrmgrNs, rootKey, pubPass, privPass, params, nil,
|
||||
birthday,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user