Browse Source

yuge but now bug with receiving messages

master
Loki Verloren 6 months ago
parent
commit
b9a4fa8230
70 changed files with 619 additions and 2086 deletions
  1. 3
    2
      addrmgr/addrmanager_internal_test.go
  2. 8
    5
      addrmgr/addrmanager_test.go
  3. 0
    0
      addrmgr/known/known_test.go
  4. 19
    19
      addrmgr/known/knownaddress_test.go
  5. 18
    17
      addrmgr/network_test.go
  6. 4
    4
      blockchain/bench_test.go
  7. 3
    3
      blockchain/chain.go
  8. 7
    6
      blockchain/chain_test.go
  9. 9
    9
      blockchain/chainio.go
  10. 23
    23
      blockchain/chainio_test.go
  11. 13
    10
      blockchain/common_test.go
  12. 2
    37
      blockchain/example_test.go
  13. 10
    8
      blockchain/fullblocks_test.go
  14. 1
    1
      blockchain/indexers/addrindex.go
  15. 4
    4
      blockchain/merkle_test.go
  16. 4
    4
      blockchain/scriptval.go
  17. 2
    2
      blockchain/scriptval_test.go
  18. 4
    4
      blockchain/upgrade.go
  19. 24
    24
      blockchain/upgrade_test.go
  20. 43
    43
      blockchain/utxoviewpoint.go
  21. 7
    7
      blockchain/validate.go
  22. 12
    10
      blockchain/validate_test.go
  23. 3
    3
      blockchain/weight.go
  24. 5
    2
      btcutil/bloom/merkleblock_test.go
  25. 2
    1
      btcutil/coinset/coins.go
  26. 3
    2
      btcutil/coinset/coins_test.go
  27. 6
    6
      btcutil/filter/example_test.go
  28. 8
    6
      btcutil/filter/filter_test.go
  29. 2
    2
      btcutil/gcs/builder/builder_test.go
  30. 8
    6
      btcutil/hdkeychain/extendedkey.go
  31. 9
    10
      btcutil/tx/tx_test.go
  32. 1
    1
      chaincfg/doc.go
  33. 4
    5
      cmd/addblock/config.go
  34. 8
    8
      cmd/addblock/import.go
  35. 4
    5
      cmd/findcheckpoint/config.go
  36. 5
    3
      cmd/gencerts/gencerts.go
  37. 4
    4
      database/cmd/dbtool/globalconfig.go
  38. 8
    7
      database/cmd/dbtool/insecureimport.go
  39. 6
    6
      database/example_test.go
  40. 3
    3
      database/ffldb/bench_test.go
  41. 2
    2
      database/ffldb/driver_test.go
  42. 8
    7
      database/ffldb/interface_test.go
  43. 8
    8
      database/ffldb/whitebox_test.go
  44. 3
    3
      docs/json_rpc_api.md
  45. 19
    16
      integration/rpctest/blockgen.go
  46. 17
    14
      integration/rpctest/memwallet.go
  47. 3
    3
      integration/rpctest/node.go
  48. 15
    11
      integration/rpctest/rpc_harness.go
  49. 1
    1
      mempool/estimator/mempool.go
  50. 2
    2
      mining/policy.go
  51. 3
    3
      node/rpc/rpchandlers.go
  52. 3
    1
      node/rpc/rpcserver.go
  53. 1
    1
      node/upgrade/upgrade.go
  54. 2
    0
      peer/example_test.go
  55. 5
    3
      peer/peer_test.go
  56. 0
    525
      rpcclient/chain.go
  57. 5
    3
      rpcclient/examples/btcdwebsockets/main.go
  58. 4
    3
      rpcclient/examples/btcwalletwebsockets/main.go
  59. 3
    278
      rpcclient/extensions.go
  60. 4
    4
      rpcclient/future/error.go
  61. 103
    103
      rpcclient/future/future.go
  62. 30
    67
      rpcclient/infrastructure.go
  63. 1
    1
      rpcclient/mining.go
  64. 0
    167
      rpcclient/net.go
  65. 16
    177
      rpcclient/notify.go
  66. 4
    16
      rpcclient/rawrequest.go
  67. 5
    342
      rpcclient/rawtransactions.go
  68. 2
    2
      rpcclient/wallet.go
  69. 40
    0
      util/diff/example.go
  70. 1
    1
      wire/invvect_test.go

+ 3
- 2
addrmgr/addrmanager_internal_test.go View File

@@ -8,6 +8,7 @@ import (
8 8
 	"testing"
9 9
 
10 10
 	"git.parallelcoin.io/dev/btcd/wire"
11
+	"git.parallelcoin.io/dev/btcd/wire/service"
11 12
 )
12 13
 
13 14
 // randAddr generates a *wire.NetAddress backed by a random IPv4/IPv6 address.
@@ -172,9 +173,9 @@ func TestAddrManagerV1ToV2(t *testing.T) {
172 173
 			t.Fatalf("expected to find address %v", addrStr)
173 174
 		}
174 175
 
175
-		if addr.Services != wire.SFNodeNetwork {
176
+		if addr.Services != service.NodeNetwork {
176 177
 			t.Fatalf("expected address services to be %v, got %v",
177
-				wire.SFNodeNetwork, addr.Services)
178
+				service.NodeNetwork, addr.Services)
178 179
 		}
179 180
 
180 181
 		addrMgr.SetServices(addr, expectedAddr.Services)

+ 8
- 5
addrmgr/addrmanager_test.go View File

@@ -12,8 +12,11 @@ import (
12 12
 	"testing"
13 13
 	"time"
14 14
 
15
+	"git.parallelcoin.io/dev/btcd/node/cnf"
16
+
15 17
 	"git.parallelcoin.io/dev/btcd/addrmgr"
16 18
 	"git.parallelcoin.io/dev/btcd/wire"
19
+	"git.parallelcoin.io/dev/btcd/wire/service"
17 20
 )
18 21
 
19 22
 // naTest is used to describe a test to be performed against the NetAddressKey
@@ -93,18 +96,18 @@ func addNaTests() {
93 96
 
94 97
 func addNaTest(ip string, port uint16, want string) {
95 98
 	nip := net.ParseIP(ip)
96
-	na := *wire.NewNetAddressIPPort(nip, port, wire.SFNodeNetwork)
99
+	na := *wire.NewNetAddressIPPort(nip, port, service.NodeNetwork)
97 100
 	test := naTest{na, want}
98 101
 	naTests = append(naTests, test)
99 102
 }
100 103
 
101
-func lookupFunc(host string) ([]net.IP, error) {
104
+func lookupFunc(_ *cnf.Config, host string) ([]net.IP, error) {
102 105
 	return nil, errors.New("not implemented")
103 106
 }
104 107
 
105 108
 func TestStartStop(t *testing.T) {
106 109
 	n := addrmgr.New("teststartstop", lookupFunc)
107
-	n.Start()
110
+	n.Start(&cnf.Config{})
108 111
 	err := n.Stop()
109 112
 	if err != nil {
110 113
 		t.Fatalf("Address Manager failed to stop: %v", err)
@@ -262,7 +265,7 @@ func TestNeedMoreAddresses(t *testing.T) {
262 265
 	var err error
263 266
 	for i := 0; i < addrsToAdd; i++ {
264 267
 		s := fmt.Sprintf("%d.%d.173.147:8333", i/128+60, i%128+60)
265
-		addrs[i], err = n.DeserializeNetAddress(s, wire.SFNodeNetwork)
268
+		addrs[i], err = n.DeserializeNetAddress(&cnf.Config{}, s, service.NodeNetwork)
266 269
 		if err != nil {
267 270
 			t.Errorf("Failed to turn %s into an address: %v", s, err)
268 271
 		}
@@ -290,7 +293,7 @@ func TestGood(t *testing.T) {
290 293
 	var err error
291 294
 	for i := 0; i < addrsToAdd; i++ {
292 295
 		s := fmt.Sprintf("%d.173.147.%d:8333", i/64+60, i%64+60)
293
-		addrs[i], err = n.DeserializeNetAddress(s, wire.SFNodeNetwork)
296
+		addrs[i], err = n.DeserializeNetAddress(&cnf.Config{}, s, service.NodeNetwork)
294 297
 		if err != nil {
295 298
 			t.Errorf("Failed to turn %s into an address: %v", s, err)
296 299
 		}

addrmgr/known/internal_test.go → addrmgr/known/known_test.go View File


addrmgr/knownaddress_test.go → addrmgr/known/knownaddress_test.go View File

@@ -2,46 +2,46 @@
2 2
 // Use of this source code is governed by an ISC
3 3
 // license that can be found in the LICENSE file.
4 4
 
5
-package addrmgr_test
5
+package known_test
6 6
 
7 7
 import (
8 8
 	"math"
9 9
 	"testing"
10 10
 	"time"
11 11
 
12
-	"git.parallelcoin.io/dev/btcd/addrmgr"
12
+	"git.parallelcoin.io/dev/btcd/addrmgr/known"
13 13
 	"git.parallelcoin.io/dev/btcd/wire"
14 14
 )
15 15
 
16 16
 func TestChance(t *testing.T) {
17 17
 	now := time.Unix(time.Now().Unix(), 0)
18 18
 	var tests = []struct {
19
-		addr     *addrmgr.KnownAddress
19
+		addr     *known.Address
20 20
 		expected float64
21 21
 	}{
22 22
 		{
23 23
 			//Test normal case
24
-			addrmgr.TstNewKnownAddress(&wire.NetAddress{Timestamp: now.Add(-35 * time.Second)},
24
+			known.TstNewAddress(&wire.NetAddress{Timestamp: now.Add(-35 * time.Second)},
25 25
 				0, time.Now().Add(-30*time.Minute), time.Now(), false, 0),
26 26
 			1.0,
27 27
 		}, {
28 28
 			//Test case in which lastseen < 0
29
-			addrmgr.TstNewKnownAddress(&wire.NetAddress{Timestamp: now.Add(20 * time.Second)},
29
+			known.TstNewAddress(&wire.NetAddress{Timestamp: now.Add(20 * time.Second)},
30 30
 				0, time.Now().Add(-30*time.Minute), time.Now(), false, 0),
31 31
 			1.0,
32 32
 		}, {
33 33
 			//Test case in which lastattempt < 0
34
-			addrmgr.TstNewKnownAddress(&wire.NetAddress{Timestamp: now.Add(-35 * time.Second)},
34
+			known.TstNewAddress(&wire.NetAddress{Timestamp: now.Add(-35 * time.Second)},
35 35
 				0, time.Now().Add(30*time.Minute), time.Now(), false, 0),
36 36
 			1.0 * .01,
37 37
 		}, {
38 38
 			//Test case in which lastattempt < ten minutes
39
-			addrmgr.TstNewKnownAddress(&wire.NetAddress{Timestamp: now.Add(-35 * time.Second)},
39
+			known.TstNewAddress(&wire.NetAddress{Timestamp: now.Add(-35 * time.Second)},
40 40
 				0, time.Now().Add(-5*time.Minute), time.Now(), false, 0),
41 41
 			1.0 * .01,
42 42
 		}, {
43 43
 			//Test case with several failed attempts.
44
-			addrmgr.TstNewKnownAddress(&wire.NetAddress{Timestamp: now.Add(-35 * time.Second)},
44
+			known.TstNewAddress(&wire.NetAddress{Timestamp: now.Add(-35 * time.Second)},
45 45
 				2, time.Now().Add(-30*time.Minute), time.Now(), false, 0),
46 46
 			1 / 1.5 / 1.5,
47 47
 		},
@@ -49,7 +49,7 @@ func TestChance(t *testing.T) {
49 49
 
50 50
 	err := .0001
51 51
 	for i, test := range tests {
52
-		chance := addrmgr.TstKnownAddressChance(test.addr)
52
+		chance := known.TstAddressChance(test.addr)
53 53
 		if math.Abs(test.expected-chance) >= err {
54 54
 			t.Errorf("case %d: got %f, expected %f", i, chance, test.expected)
55 55
 		}
@@ -71,44 +71,44 @@ func TestIsBad(t *testing.T) {
71 71
 	currentNa := &wire.NetAddress{Timestamp: secondsOld}
72 72
 
73 73
 	//Test addresses that have been tried in the last minute.
74
-	if addrmgr.TstKnownAddressIsBad(addrmgr.TstNewKnownAddress(futureNa, 3, secondsOld, zeroTime, false, 0)) {
74
+	if known.TstAddressIsBad(known.TstNewAddress(futureNa, 3, secondsOld, zeroTime, false, 0)) {
75 75
 		t.Errorf("test case 1: addresses that have been tried in the last minute are not bad.")
76 76
 	}
77
-	if addrmgr.TstKnownAddressIsBad(addrmgr.TstNewKnownAddress(monthOldNa, 3, secondsOld, zeroTime, false, 0)) {
77
+	if known.TstAddressIsBad(known.TstNewAddress(monthOldNa, 3, secondsOld, zeroTime, false, 0)) {
78 78
 		t.Errorf("test case 2: addresses that have been tried in the last minute are not bad.")
79 79
 	}
80
-	if addrmgr.TstKnownAddressIsBad(addrmgr.TstNewKnownAddress(currentNa, 3, secondsOld, zeroTime, false, 0)) {
80
+	if known.TstAddressIsBad(known.TstNewAddress(currentNa, 3, secondsOld, zeroTime, false, 0)) {
81 81
 		t.Errorf("test case 3: addresses that have been tried in the last minute are not bad.")
82 82
 	}
83
-	if addrmgr.TstKnownAddressIsBad(addrmgr.TstNewKnownAddress(currentNa, 3, secondsOld, monthOld, true, 0)) {
83
+	if known.TstAddressIsBad(known.TstNewAddress(currentNa, 3, secondsOld, monthOld, true, 0)) {
84 84
 		t.Errorf("test case 4: addresses that have been tried in the last minute are not bad.")
85 85
 	}
86
-	if addrmgr.TstKnownAddressIsBad(addrmgr.TstNewKnownAddress(currentNa, 2, secondsOld, secondsOld, true, 0)) {
86
+	if known.TstAddressIsBad(known.TstNewAddress(currentNa, 2, secondsOld, secondsOld, true, 0)) {
87 87
 		t.Errorf("test case 5: addresses that have been tried in the last minute are not bad.")
88 88
 	}
89 89
 
90 90
 	//Test address that claims to be from the future.
91
-	if !addrmgr.TstKnownAddressIsBad(addrmgr.TstNewKnownAddress(futureNa, 0, minutesOld, hoursOld, true, 0)) {
91
+	if !known.TstAddressIsBad(known.TstNewAddress(futureNa, 0, minutesOld, hoursOld, true, 0)) {
92 92
 		t.Errorf("test case 6: addresses that claim to be from the future are bad.")
93 93
 	}
94 94
 
95 95
 	//Test address that has not been seen in over a month.
96
-	if !addrmgr.TstKnownAddressIsBad(addrmgr.TstNewKnownAddress(monthOldNa, 0, minutesOld, hoursOld, true, 0)) {
96
+	if !known.TstAddressIsBad(known.TstNewAddress(monthOldNa, 0, minutesOld, hoursOld, true, 0)) {
97 97
 		t.Errorf("test case 7: addresses more than a month old are bad.")
98 98
 	}
99 99
 
100 100
 	//It has failed at least three times and never succeeded.
101
-	if !addrmgr.TstKnownAddressIsBad(addrmgr.TstNewKnownAddress(minutesOldNa, 3, minutesOld, zeroTime, true, 0)) {
101
+	if !known.TstAddressIsBad(known.TstNewAddress(minutesOldNa, 3, minutesOld, zeroTime, true, 0)) {
102 102
 		t.Errorf("test case 8: addresses that have never succeeded are bad.")
103 103
 	}
104 104
 
105 105
 	//It has failed ten times in the last week
106
-	if !addrmgr.TstKnownAddressIsBad(addrmgr.TstNewKnownAddress(minutesOldNa, 10, minutesOld, monthOld, true, 0)) {
106
+	if !known.TstAddressIsBad(known.TstNewAddress(minutesOldNa, 10, minutesOld, monthOld, true, 0)) {
107 107
 		t.Errorf("test case 9: addresses that have not succeeded in too long are bad.")
108 108
 	}
109 109
 
110 110
 	//Test an address that should work.
111
-	if addrmgr.TstKnownAddressIsBad(addrmgr.TstNewKnownAddress(minutesOldNa, 2, minutesOld, hoursOld, true, 0)) {
111
+	if known.TstAddressIsBad(known.TstNewAddress(minutesOldNa, 2, minutesOld, hoursOld, true, 0)) {
112 112
 		t.Errorf("test case 10: This should be a valid address.")
113 113
 	}
114 114
 }

+ 18
- 17
addrmgr/network_test.go View File

@@ -8,7 +8,8 @@ import (
8 8
 	"net"
9 9
 	"testing"
10 10
 
11
-	"git.parallelcoin.io/dev/btcd/addrmgr"
11
+	"git.parallelcoin.io/dev/btcd/addrmgr/network"
12
+	"git.parallelcoin.io/dev/btcd/wire/service"
12 13
 	"git.parallelcoin.io/dev/btcd/wire"
13 14
 )
14 15
 
@@ -39,7 +40,7 @@ func TestIPTypes(t *testing.T) {
39 40
 		rfc4193, rfc4380, rfc4843, rfc4862, rfc5737, rfc6052, rfc6145, rfc6598,
40 41
 		local, valid, routable bool) ipTest {
41 42
 		nip := net.ParseIP(ip)
42
-		na := *wire.NewNetAddressIPPort(nip, 8333, wire.SFNodeNetwork)
43
+		na := *wire.NewNetAddressIPPort(nip, 8333, service.NodeNetwork)
43 44
 		test := ipTest{na, rfc1918, rfc2544, rfc3849, rfc3927, rfc3964, rfc4193, rfc4380,
44 45
 			rfc4843, rfc4862, rfc5737, rfc6052, rfc6145, rfc6598, local, valid, routable}
45 46
 		return test
@@ -88,55 +89,55 @@ func TestIPTypes(t *testing.T) {
88 89
 
89 90
 	t.Logf("Running %d tests", len(tests))
90 91
 	for _, test := range tests {
91
-		if rv := addrmgr.IsRFC1918(&test.in); rv != test.rfc1918 {
92
+		if rv := network.IsRFC1918(&test.in); rv != test.rfc1918 {
92 93
 			t.Errorf("IsRFC1918 %s\n got: %v want: %v", test.in.IP, rv, test.rfc1918)
93 94
 		}
94 95
 
95
-		if rv := addrmgr.IsRFC3849(&test.in); rv != test.rfc3849 {
96
+		if rv := network.IsRFC3849(&test.in); rv != test.rfc3849 {
96 97
 			t.Errorf("IsRFC3849 %s\n got: %v want: %v", test.in.IP, rv, test.rfc3849)
97 98
 		}
98 99
 
99
-		if rv := addrmgr.IsRFC3927(&test.in); rv != test.rfc3927 {
100
+		if rv := network.IsRFC3927(&test.in); rv != test.rfc3927 {
100 101
 			t.Errorf("IsRFC3927 %s\n got: %v want: %v", test.in.IP, rv, test.rfc3927)
101 102
 		}
102 103
 
103
-		if rv := addrmgr.IsRFC3964(&test.in); rv != test.rfc3964 {
104
+		if rv := network.IsRFC3964(&test.in); rv != test.rfc3964 {
104 105
 			t.Errorf("IsRFC3964 %s\n got: %v want: %v", test.in.IP, rv, test.rfc3964)
105 106
 		}
106 107
 
107
-		if rv := addrmgr.IsRFC4193(&test.in); rv != test.rfc4193 {
108
+		if rv := network.IsRFC4193(&test.in); rv != test.rfc4193 {
108 109
 			t.Errorf("IsRFC4193 %s\n got: %v want: %v", test.in.IP, rv, test.rfc4193)
109 110
 		}
110 111
 
111
-		if rv := addrmgr.IsRFC4380(&test.in); rv != test.rfc4380 {
112
+		if rv := network.IsRFC4380(&test.in); rv != test.rfc4380 {
112 113
 			t.Errorf("IsRFC4380 %s\n got: %v want: %v", test.in.IP, rv, test.rfc4380)
113 114
 		}
114 115
 
115
-		if rv := addrmgr.IsRFC4843(&test.in); rv != test.rfc4843 {
116
+		if rv := network.IsRFC4843(&test.in); rv != test.rfc4843 {
116 117
 			t.Errorf("IsRFC4843 %s\n got: %v want: %v", test.in.IP, rv, test.rfc4843)
117 118
 		}
118 119
 
119
-		if rv := addrmgr.IsRFC4862(&test.in); rv != test.rfc4862 {
120
+		if rv := network.IsRFC4862(&test.in); rv != test.rfc4862 {
120 121
 			t.Errorf("IsRFC4862 %s\n got: %v want: %v", test.in.IP, rv, test.rfc4862)
121 122
 		}
122 123
 
123
-		if rv := addrmgr.IsRFC6052(&test.in); rv != test.rfc6052 {
124
+		if rv := network.IsRFC6052(&test.in); rv != test.rfc6052 {
124 125
 			t.Errorf("isRFC6052 %s\n got: %v want: %v", test.in.IP, rv, test.rfc6052)
125 126
 		}
126 127
 
127
-		if rv := addrmgr.IsRFC6145(&test.in); rv != test.rfc6145 {
128
+		if rv := network.IsRFC6145(&test.in); rv != test.rfc6145 {
128 129
 			t.Errorf("IsRFC1918 %s\n got: %v want: %v", test.in.IP, rv, test.rfc6145)
129 130
 		}
130 131
 
131
-		if rv := addrmgr.IsLocal(&test.in); rv != test.local {
132
+		if rv := network.IsLocal(&test.in); rv != test.local {
132 133
 			t.Errorf("IsLocal %s\n got: %v want: %v", test.in.IP, rv, test.local)
133 134
 		}
134 135
 
135
-		if rv := addrmgr.IsValid(&test.in); rv != test.valid {
136
+		if rv := network.IsValid(&test.in); rv != test.valid {
136 137
 			t.Errorf("IsValid %s\n got: %v want: %v", test.in.IP, rv, test.valid)
137 138
 		}
138 139
 
139
-		if rv := addrmgr.IsRoutable(&test.in); rv != test.routable {
140
+		if rv := network.IsRoutable(&test.in); rv != test.routable {
140 141
 			t.Errorf("IsRoutable %s\n got: %v want: %v", test.in.IP, rv, test.routable)
141 142
 		}
142 143
 	}
@@ -192,8 +193,8 @@ func TestGroupKey(t *testing.T) {
192 193
 
193 194
 	for i, test := range tests {
194 195
 		nip := net.ParseIP(test.ip)
195
-		na := *wire.NewNetAddressIPPort(nip, 8333, wire.SFNodeNetwork)
196
-		if key := addrmgr.GroupKey(&na); key != test.expected {
196
+		na := *wire.NewNetAddressIPPort(nip, 8333, service.NodeNetwork)
197
+		if key := network.GroupKey(&na); key != test.expected {
197 198
 			t.Errorf("TestGroupKey #%d (%s): unexpected group key "+
198 199
 				"- got '%s', want '%s'", i, test.name,
199 200
 				key, test.expected)

+ 4
- 4
blockchain/bench_test.go View File

@@ -7,23 +7,23 @@ package blockchain
7 7
 import (
8 8
 	"testing"
9 9
 
10
-	"git.parallelcoin.io/dev/btcd/btcutil"
10
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
11 11
 )
12 12
 
13 13
 // BenchmarkIsCoinBase performs a simple benchmark against the IsCoinBase
14 14
 // function.
15 15
 func BenchmarkIsCoinBase(b *testing.B) {
16
-	tx, _ := btcutil.NewBlock(&Block100000).Tx(1)
16
+	tt, _ := block.New(&block.Block100000).Tx(1)
17 17
 	b.ResetTimer()
18 18
 	for i := 0; i < b.N; i++ {
19
-		IsCoinBase(tx)
19
+		IsCoinBase(tt)
20 20
 	}
21 21
 }
22 22
 
23 23
 // BenchmarkIsCoinBaseTx performs a simple benchmark against the IsCoinBaseTx
24 24
 // function.
25 25
 func BenchmarkIsCoinBaseTx(b *testing.B) {
26
-	tx := Block100000.Transactions[1]
26
+	tx := block.Block100000.Transactions[1]
27 27
 	b.ResetTimer()
28 28
 	for i := 0; i < b.N; i++ {
29 29
 		IsCoinBaseTx(tx)

+ 3
- 3
blockchain/chain.go View File

@@ -402,8 +402,8 @@ func (b *BlockChain) calcSequenceLock(node *blockNode, tx *tx.Tx, utxoView *Utxo
402 402
 	nextHeight := node.height + 1
403 403
 
404 404
 	for txInIndex, txIn := range mTx.TxIn {
405
-		utxo := utxoView.LookupEntry(txIn.PreviousOutPoint)
406
-		if utxo == nil {
405
+		uu := utxoView.LookupEntry(txIn.PreviousOutPoint)
406
+		if uu == nil {
407 407
 			str := fmt.Sprintf("output %v referenced from "+
408 408
 				"transaction %s:%d either does not exist or "+
409 409
 				"has already been spent", txIn.PreviousOutPoint,
@@ -414,7 +414,7 @@ func (b *BlockChain) calcSequenceLock(node *blockNode, tx *tx.Tx, utxoView *Utxo
414 414
 		// If the input height is set to the mempool height, then we
415 415
 		// assume the transaction makes it into the next block when
416 416
 		// evaluating its sequence blocks.
417
-		inputHeight := utxo.BlockHeight()
417
+		inputHeight := uu.GetBlockHeight()
418 418
 		if inputHeight == 0x7fffffff {
419 419
 			inputHeight = nextHeight
420 420
 		}

+ 7
- 6
blockchain/chain_test.go View File

@@ -9,10 +9,11 @@ import (
9 9
 	"testing"
10 10
 	"time"
11 11
 
12
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
13
+	"git.parallelcoin.io/dev/btcd/btcutil/tx"
12 14
 	"git.parallelcoin.io/dev/btcd/chaincfg"
13 15
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
14 16
 	"git.parallelcoin.io/dev/btcd/wire"
15
-	"git.parallelcoin.io/dev/btcd/btcutil"
16 17
 )
17 18
 
18 19
 // TestHaveBlock tests the HaveBlock API to ensure proper functionality.
@@ -25,7 +26,7 @@ func TestHaveBlock(t *testing.T) {
25 26
 		"blk_3A.dat.bz2",
26 27
 	}
27 28
 
28
-	var blocks []*btcutil.Block
29
+	var blocks []*block.Block
29 30
 	for _, file := range testFiles {
30 31
 		blockTmp, err := loadBlocks(file)
31 32
 		if err != nil {
@@ -62,7 +63,7 @@ func TestHaveBlock(t *testing.T) {
62 63
 	}
63 64
 
64 65
 	// Insert an orphan block.
65
-	_, isOrphan, err := chain.ProcessBlock(btcutil.NewBlock(&Block100000),
66
+	_, isOrphan, err := chain.ProcessBlock(block.New(&block.Block100000),
66 67
 		BFNone)
67 68
 	if err != nil {
68 69
 		t.Errorf("Unable to process block: %v", err)
@@ -139,7 +140,7 @@ func TestCalcSequenceLock(t *testing.T) {
139 140
 	// Create a utxo view with a fake utxo for the inputs used in the
140 141
 	// transactions created below.  This utxo is added such that it has an
141 142
 	// age of 4 blocks.
142
-	targetTx := btcutil.NewTx(&wire.MsgTx{
143
+	targetTx := tx.New(&wire.MsgTx{
143 144
 		TxOut: []*wire.TxOut{{
144 145
 			PkScript: nil,
145 146
 			Value:    10,
@@ -187,7 +188,7 @@ func TestCalcSequenceLock(t *testing.T) {
187 188
 
188 189
 	// Adding a utxo with a height of 0x7fffffff indicates that the output
189 190
 	// is currently unmined.
190
-	utxoView.AddTxOuts(btcutil.NewTx(unConfTx), 0x7fffffff)
191
+	utxoView.AddTxOuts(tx.New(unConfTx), 0x7fffffff)
191 192
 
192 193
 	tests := []struct {
193 194
 		tx      *wire.MsgTx
@@ -422,7 +423,7 @@ func TestCalcSequenceLock(t *testing.T) {
422 423
 
423 424
 	t.Logf("Running %v SequenceLock tests", len(tests))
424 425
 	for i, test := range tests {
425
-		utilTx := btcutil.NewTx(test.tx)
426
+		utilTx := tx.New(test.tx)
426 427
 		seqLock, err := chain.CalcSequenceLock(utilTx, test.view, test.mempool)
427 428
 		if err != nil {
428 429
 			t.Fatalf("test #%d, unable to calc sequence lock: %v", i, err)

+ 9
- 9
blockchain/chainio.go View File

@@ -619,7 +619,7 @@ func utxoEntryHeaderCode(entry *UtxoEntry) (uint64, error) {
619 619
 	// As described in the serialization format comments, the header code
620 620
 	// encodes the height shifted over one bit and the coinbase flag in the
621 621
 	// lowest bit.
622
-	headerCode := uint64(entry.BlockHeight()) << 1
622
+	headerCode := uint64(entry.GetBlockHeight()) << 1
623 623
 	if entry.IsCoinBase() {
624 624
 		headerCode |= 0x01
625 625
 	}
@@ -643,14 +643,14 @@ func serializeUtxoEntry(entry *UtxoEntry) ([]byte, error) {
643 643
 
644 644
 	// Calculate the size needed to serialize the entry.
645 645
 	size := serializeSizeVLQ(headerCode) +
646
-		compressedTxOutSize(uint64(entry.Amount()), entry.PkScript())
646
+		compressedTxOutSize(uint64(entry.GetAmount()), entry.GetPkScript())
647 647
 
648 648
 	// Serialize the header code followed by the compressed unspent
649 649
 	// transaction output.
650 650
 	serialized := make([]byte, size)
651 651
 	offset := putVLQ(serialized, headerCode)
652
-	offset += putCompressedTxOut(serialized[offset:], uint64(entry.Amount()),
653
-		entry.PkScript())
652
+	offset += putCompressedTxOut(serialized[offset:], uint64(entry.GetAmount()),
653
+		entry.GetPkScript())
654 654
 
655 655
 	return serialized, nil
656 656
 }
@@ -680,13 +680,13 @@ func deserializeUtxoEntry(serialized []byte) (*UtxoEntry, error) {
680 680
 	}
681 681
 
682 682
 	entry := &UtxoEntry{
683
-		amount:      int64(amount),
684
-		pkScript:    pkScript,
685
-		blockHeight: blockHeight,
686
-		packedFlags: 0,
683
+		Amount:      int64(amount),
684
+		PkScript:    pkScript,
685
+		BlockHeight: blockHeight,
686
+		PackedFlags: 0,
687 687
 	}
688 688
 	if isCoinBase {
689
-		entry.packedFlags |= TFCoinBase
689
+		entry.PackedFlags |= TFCoinBase
690 690
 	}
691 691
 
692 692
 	return entry, nil

+ 23
- 23
blockchain/chainio_test.go View File

@@ -418,10 +418,10 @@ func TestUtxoSerialization(t *testing.T) {
418 418
 		{
419 419
 			name: "height 1, coinbase",
420 420
 			entry: &UtxoEntry{
421
-				amount:      5000000000,
422
-				pkScript:    hexToBytes("410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac"),
423
-				blockHeight: 1,
424
-				packedFlags: tfCoinBase,
421
+				Amount:      5000000000,
422
+				PkScript:    hexToBytes("410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac"),
423
+				BlockHeight: 1,
424
+				PackedFlags: TFCoinBase,
425 425
 			},
426 426
 			serialized: hexToBytes("03320496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52"),
427 427
 		},
@@ -430,10 +430,10 @@ func TestUtxoSerialization(t *testing.T) {
430 430
 		{
431 431
 			name: "height 1, coinbase, spent",
432 432
 			entry: &UtxoEntry{
433
-				amount:      5000000000,
434
-				pkScript:    hexToBytes("410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac"),
435
-				blockHeight: 1,
436
-				packedFlags: tfCoinBase | tfSpent,
433
+				Amount:      5000000000,
434
+				PkScript:    hexToBytes("410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac"),
435
+				BlockHeight: 1,
436
+				PackedFlags: TFCoinBase | TFSpent,
437 437
 			},
438 438
 			serialized: nil,
439 439
 		},
@@ -442,10 +442,10 @@ func TestUtxoSerialization(t *testing.T) {
442 442
 		{
443 443
 			name: "height 100001, not coinbase",
444 444
 			entry: &UtxoEntry{
445
-				amount:      1000000,
446
-				pkScript:    hexToBytes("76a914ee8bd501094a7d5ca318da2506de35e1cb025ddc88ac"),
447
-				blockHeight: 100001,
448
-				packedFlags: 0,
445
+				Amount:      1000000,
446
+				PkScript:    hexToBytes("76a914ee8bd501094a7d5ca318da2506de35e1cb025ddc88ac"),
447
+				BlockHeight: 100001,
448
+				PackedFlags: 0,
449 449
 			},
450 450
 			serialized: hexToBytes("8b99420700ee8bd501094a7d5ca318da2506de35e1cb025ddc"),
451 451
 		},
@@ -454,10 +454,10 @@ func TestUtxoSerialization(t *testing.T) {
454 454
 		{
455 455
 			name: "height 100001, not coinbase, spent",
456 456
 			entry: &UtxoEntry{
457
-				amount:      1000000,
458
-				pkScript:    hexToBytes("76a914ee8bd501094a7d5ca318da2506de35e1cb025ddc88ac"),
459
-				blockHeight: 100001,
460
-				packedFlags: tfSpent,
457
+				Amount:      1000000,
458
+				PkScript:    hexToBytes("76a914ee8bd501094a7d5ca318da2506de35e1cb025ddc88ac"),
459
+				BlockHeight: 100001,
460
+				PackedFlags: TFSpent,
461 461
 			},
462 462
 			serialized: nil,
463 463
 		},
@@ -502,23 +502,23 @@ func TestUtxoSerialization(t *testing.T) {
502 502
 
503 503
 		// Ensure the deserialized entry has the same properties as the
504 504
 		// ones in the test entry.
505
-		if utxoEntry.Amount() != test.entry.Amount() {
505
+		if utxoEntry.GetAmount() != test.entry.GetAmount() {
506 506
 			t.Errorf("deserializeUtxoEntry #%d (%s) mismatched "+
507 507
 				"amounts: got %d, want %d", i, test.name,
508
-				utxoEntry.Amount(), test.entry.Amount())
508
+				utxoEntry.GetAmount(), test.entry.GetAmount())
509 509
 			continue
510 510
 		}
511 511
 
512
-		if !bytes.Equal(utxoEntry.PkScript(), test.entry.PkScript()) {
512
+		if !bytes.Equal(utxoEntry.GetPkScript(), test.entry.GetPkScript()) {
513 513
 			t.Errorf("deserializeUtxoEntry #%d (%s) mismatched "+
514 514
 				"scripts: got %x, want %x", i, test.name,
515
-				utxoEntry.PkScript(), test.entry.PkScript())
515
+				utxoEntry.GetPkScript(), test.entry.GetPkScript())
516 516
 			continue
517 517
 		}
518
-		if utxoEntry.BlockHeight() != test.entry.BlockHeight() {
518
+		if utxoEntry.GetBlockHeight() != test.entry.GetBlockHeight() {
519 519
 			t.Errorf("deserializeUtxoEntry #%d (%s) mismatched "+
520 520
 				"block height: got %d, want %d", i, test.name,
521
-				utxoEntry.BlockHeight(), test.entry.BlockHeight())
521
+				utxoEntry.GetBlockHeight(), test.entry.GetBlockHeight())
522 522
 			continue
523 523
 		}
524 524
 		if utxoEntry.IsCoinBase() != test.entry.IsCoinBase() {
@@ -543,7 +543,7 @@ func TestUtxoEntryHeaderCodeErrors(t *testing.T) {
543 543
 	}{
544 544
 		{
545 545
 			name:    "Force assertion due to spent output",
546
-			entry:   &UtxoEntry{packedFlags: tfSpent},
546
+			entry:   &UtxoEntry{PackedFlags: TFSpent},
547 547
 			errType: AssertError(""),
548 548
 		},
549 549
 	}

+ 13
- 10
blockchain/common_test.go View File

@@ -14,13 +14,16 @@ import (
14 14
 	"strings"
15 15
 	"time"
16 16
 
17
+	"git.parallelcoin.io/dev/btcd/txscript/sig"
18
+
19
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
20
+	"git.parallelcoin.io/dev/btcd/wire/service"
21
+
17 22
 	"git.parallelcoin.io/dev/btcd/chaincfg"
18 23
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
19 24
 	"git.parallelcoin.io/dev/btcd/database"
20 25
 	_ "git.parallelcoin.io/dev/btcd/database/ffldb"
21
-	"git.parallelcoin.io/dev/btcd/txscript"
22 26
 	"git.parallelcoin.io/dev/btcd/wire"
23
-	"git.parallelcoin.io/dev/btcd/btcutil"
24 27
 )
25 28
 
26 29
 const (
@@ -31,7 +34,7 @@ const (
31 34
 	testDbRoot = "testdbs"
32 35
 
33 36
 	// blockDataNet is the expected network in the test block data.
34
-	blockDataNet = wire.MainNet
37
+	blockDataNet = service.MainNet
35 38
 )
36 39
 
37 40
 // filesExists returns whether or not the named file or directory exists.
@@ -59,11 +62,11 @@ func isSupportedDbType(dbType string) bool {
59 62
 
60 63
 // loadBlocks reads files containing bitcoin block data (gzipped but otherwise
61 64
 // in the format bitcoind writes) from disk and returns them as an array of
62
-// btcutil.Block.  This is largely borrowed from the test code in btcdb.
63
-func loadBlocks(filename string) (blocks []*btcutil.Block, err error) {
65
+// block.Block.  This is largely borrowed from the test code in btcdb.
66
+func loadBlocks(filename string) (blocks []*block.Block, err error) {
64 67
 	filename = filepath.Join("testdata/", filename)
65 68
 
66
-	var network = wire.MainNet
69
+	var network = service.MainNet
67 70
 	var dr io.Reader
68 71
 	var fi io.ReadCloser
69 72
 
@@ -79,7 +82,7 @@ func loadBlocks(filename string) (blocks []*btcutil.Block, err error) {
79 82
 	}
80 83
 	defer fi.Close()
81 84
 
82
-	var block *btcutil.Block
85
+	var bb *block.Block
83 86
 
84 87
 	err = nil
85 88
 	for height := int64(1); err == nil; height++ {
@@ -105,11 +108,11 @@ func loadBlocks(filename string) (blocks []*btcutil.Block, err error) {
105 108
 		// read block
106 109
 		dr.Read(rbytes)
107 110
 
108
-		block, err = btcutil.NewBlockFromBytes(rbytes)
111
+		bb, err = block.NewFromBytes(rbytes)
109 112
 		if err != nil {
110 113
 			return
111 114
 		}
112
-		blocks = append(blocks, block)
115
+		blocks = append(blocks, bb)
113 116
 	}
114 117
 
115 118
 	return
@@ -177,7 +180,7 @@ func chainSetup(dbName string, params *chaincfg.Params) (*BlockChain, func(), er
177 180
 		ChainParams: &paramsCopy,
178 181
 		Checkpoints: nil,
179 182
 		TimeSource:  NewMedianTime(),
180
-		SigCache:    txscript.NewSigCache(1000),
183
+		SigCache:    sig.NewCache(1000),
181 184
 	})
182 185
 	if err != nil {
183 186
 		teardown()

+ 2
- 37
blockchain/example_test.go View File

@@ -6,15 +6,14 @@ package blockchain_test
6 6
 
7 7
 import (
8 8
 	"fmt"
9
-	"math/big"
10 9
 	"os"
11 10
 	"path/filepath"
12 11
 
12
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
13 13
 	"git.parallelcoin.io/dev/btcd/blockchain"
14 14
 	"git.parallelcoin.io/dev/btcd/chaincfg"
15 15
 	"git.parallelcoin.io/dev/btcd/database"
16 16
 	_ "git.parallelcoin.io/dev/btcd/database/ffldb"
17
-	"git.parallelcoin.io/dev/btcd/btcutil"
18 17
 )
19 18
 
20 19
 // This example demonstrates how to create a new chain instance and use
@@ -58,7 +57,7 @@ func ExampleBlockChain_ProcessBlock() {
58 57
 	// Process a block.  For this example, we are going to intentionally
59 58
 	// cause an error by trying to process the genesis block which already
60 59
 	// exists.
61
-	genesisBlock := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock)
60
+	genesisBlock := block.New(chaincfg.MainNetParams.GenesisBlock)
62 61
 	isMainChain, isOrphan, err := chain.ProcessBlock(genesisBlock,
63 62
 		blockchain.BFNone)
64 63
 	if err != nil {
@@ -71,37 +70,3 @@ func ExampleBlockChain_ProcessBlock() {
71 70
 	// Output:
72 71
 	// Failed to process block: already have block 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
73 72
 }
74
-
75
-// This example demonstrates how to convert the compact "bits" in a block header
76
-// which represent the target difficulty to a big integer and display it using
77
-// the typical hex notation.
78
-func ExampleCompactToBig() {
79
-	// Convert the bits from block 300000 in the main block chain.
80
-	bits := uint32(419465580)
81
-	targetDifficulty := diff.CompactToBig(bits)
82
-
83
-	// Display it in hex.
84
-	fmt.Printf("%064x\n", targetDifficulty.Bytes())
85
-
86
-	// Output:
87
-	// 0000000000000000896c00000000000000000000000000000000000000000000
88
-}
89
-
90
-// This example demonstrates how to convert a target difficulty into the compact
91
-// "bits" in a block header which represent that target difficulty .
92
-func ExampleBigToCompact() {
93
-	// Convert the target difficulty from block 300000 in the main block
94
-	// chain to compact form.
95
-	t := "0000000000000000896c00000000000000000000000000000000000000000000"
96
-	targetDifficulty, success := new(big.Int).SetString(t, 16)
97
-	if !success {
98
-		fmt.Println("invalid target difficulty")
99
-		return
100
-	}
101
-	bits := blockchain.BigToCompact(targetDifficulty)
102
-
103
-	fmt.Println(bits)
104
-
105
-	// Output:
106
-	// 419465580
107
-}

+ 10
- 8
blockchain/fullblocks_test.go View File

@@ -12,15 +12,17 @@ import (
12 12
 	"path/filepath"
13 13
 	"testing"
14 14
 
15
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
16
+	"git.parallelcoin.io/dev/btcd/txscript/sig"
17
+	"git.parallelcoin.io/dev/btcd/wire/service"
18
+
15 19
 	"git.parallelcoin.io/dev/btcd/blockchain"
16 20
 	"git.parallelcoin.io/dev/btcd/blockchain/fullblocktests"
17 21
 	"git.parallelcoin.io/dev/btcd/chaincfg"
18 22
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
19 23
 	"git.parallelcoin.io/dev/btcd/database"
20 24
 	_ "git.parallelcoin.io/dev/btcd/database/ffldb"
21
-	"git.parallelcoin.io/dev/btcd/txscript"
22 25
 	"git.parallelcoin.io/dev/btcd/wire"
23
-	"git.parallelcoin.io/dev/btcd/btcutil"
24 26
 )
25 27
 
26 28
 const (
@@ -31,7 +33,7 @@ const (
31 33
 	testDbRoot = "testdbs"
32 34
 
33 35
 	// blockDataNet is the expected network in the test block data.
34
-	blockDataNet = wire.MainNet
36
+	blockDataNet = service.MainNet
35 37
 )
36 38
 
37 39
 // filesExists returns whether or not the named file or directory exists.
@@ -119,7 +121,7 @@ func chainSetup(dbName string, params *chaincfg.Params) (*blockchain.BlockChain,
119 121
 		ChainParams: &paramsCopy,
120 122
 		Checkpoints: nil,
121 123
 		TimeSource:  blockchain.NewMedianTime(),
122
-		SigCache:    txscript.NewSigCache(1000),
124
+		SigCache:    sig.NewCache(1000),
123 125
 	})
124 126
 	if err != nil {
125 127
 		teardown()
@@ -151,7 +153,7 @@ func TestFullBlocks(t *testing.T) {
151 153
 	// specified in the test.
152 154
 	testAcceptedBlock := func(item fullblocktests.AcceptedBlock) {
153 155
 		blockHeight := item.Height
154
-		block := btcutil.NewBlock(item.Block)
156
+		block := block.New(item.Block)
155 157
 		block.SetHeight(blockHeight)
156 158
 		t.Logf("Testing block %s (hash %s, height %d)",
157 159
 			item.Name, block.Hash(), blockHeight)
@@ -185,7 +187,7 @@ func TestFullBlocks(t *testing.T) {
185 187
 	// specified in the test.
186 188
 	testRejectedBlock := func(item fullblocktests.RejectedBlock) {
187 189
 		blockHeight := item.Height
188
-		block := btcutil.NewBlock(item.Block)
190
+		block := block.New(item.Block)
189 191
 		block.SetHeight(blockHeight)
190 192
 		t.Logf("Testing block %s (hash %s, height %d)",
191 193
 			item.Name, block.Hash(), blockHeight)
@@ -242,7 +244,7 @@ func TestFullBlocks(t *testing.T) {
242 244
 	// orphan or rejected with a rule violation.
243 245
 	testOrphanOrRejectedBlock := func(item fullblocktests.OrphanOrRejectedBlock) {
244 246
 		blockHeight := item.Height
245
-		block := btcutil.NewBlock(item.Block)
247
+		block := block.New(item.Block)
246 248
 		block.SetHeight(blockHeight)
247 249
 		t.Logf("Testing block %s (hash %s, height %d)",
248 250
 			item.Name, block.Hash(), blockHeight)
@@ -270,7 +272,7 @@ func TestFullBlocks(t *testing.T) {
270 272
 	// block specified in the provided test instance.
271 273
 	testExpectedTip := func(item fullblocktests.ExpectedTip) {
272 274
 		blockHeight := item.Height
273
-		block := btcutil.NewBlock(item.Block)
275
+		block := block.New(item.Block)
274 276
 		block.SetHeight(blockHeight)
275 277
 		t.Logf("Testing tip for block %s (hash %s, height %d)",
276 278
 			item.Name, block.Hash(), blockHeight)

+ 1
- 1
blockchain/indexers/addrindex.go View File

@@ -888,7 +888,7 @@ func (idx *AddrIndex) AddUnconfirmedTx(t *tx.Tx, utxoView *blockchain.UtxoViewpo
888 888
 			// call out all inputs must be available.
889 889
 			continue
890 890
 		}
891
-		idx.indexUnconfirmedAddresses(entry.PkScript(), t)
891
+		idx.indexUnconfirmedAddresses(entry.GetPkScript(), t)
892 892
 	}
893 893
 
894 894
 	// Index addresses of all created outputs.

+ 4
- 4
blockchain/merkle_test.go View File

@@ -7,15 +7,15 @@ package blockchain
7 7
 import (
8 8
 	"testing"
9 9
 
10
-	"git.parallelcoin.io/dev/btcd/btcutil"
10
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
11 11
 )
12 12
 
13 13
 // TestMerkle tests the BuildMerkleTreeStore API.
14 14
 func TestMerkle(t *testing.T) {
15
-	block := btcutil.NewBlock(&Block100000)
16
-	merkles := BuildMerkleTreeStore(block.Transactions(), false)
15
+	bb := block.New(&block.Block100000)
16
+	merkles := BuildMerkleTreeStore(bb.Transactions(), false)
17 17
 	calculatedMerkleRoot := merkles[len(merkles)-1]
18
-	wantMerkle := &Block100000.Header.MerkleRoot
18
+	wantMerkle := &block.Block100000.Header.MerkleRoot
19 19
 	if !wantMerkle.IsEqual(calculatedMerkleRoot) {
20 20
 		t.Errorf("BuildMerkleTreeStore: merkle root mismatch - "+
21 21
 			"got %v, want %v", calculatedMerkleRoot, wantMerkle)

+ 4
- 4
blockchain/scriptval.go View File

@@ -58,8 +58,8 @@ out:
58 58
 		case txVI := <-v.validateChan:
59 59
 			// Ensure the referenced input utxo is available.
60 60
 			txIn := txVI.txIn
61
-			utxo := v.utxoView.LookupEntry(txIn.PreviousOutPoint)
62
-			if utxo == nil {
61
+			uu := v.utxoView.LookupEntry(txIn.PreviousOutPoint)
62
+			if uu == nil {
63 63
 				str := fmt.Sprintf("unable to find unspent "+
64 64
 					"output %v referenced from "+
65 65
 					"transaction %s:%d",
@@ -73,8 +73,8 @@ out:
73 73
 			// Create a new script engine for the script pair.
74 74
 			sigScript := txIn.SignatureScript
75 75
 			witness := txIn.Witness
76
-			pkScript := utxo.PkScript()
77
-			inputAmount := utxo.Amount()
76
+			pkScript := uu.GetPkScript()
77
+			inputAmount := uu.GetAmount()
78 78
 			vm, err := txscript.NewEngine(pkScript, txVI.tx.MsgTx(),
79 79
 				txVI.txInIndex, v.flags, v.sigCache, txVI.sigHashes,
80 80
 				inputAmount)

+ 2
- 2
blockchain/scriptval_test.go View File

@@ -9,7 +9,7 @@ import (
9 9
 	"runtime"
10 10
 	"testing"
11 11
 
12
-	"git.parallelcoin.io/dev/btcd/txscript"
12
+	"git.parallelcoin.io/dev/btcd/txscript/sf"
13 13
 )
14 14
 
15 15
 // TestCheckBlockScripts ensures that validating the all of the scripts in a
@@ -40,7 +40,7 @@ func TestCheckBlockScripts(t *testing.T) {
40 40
 		return
41 41
 	}
42 42
 
43
-	scriptFlags := txscript.ScriptBip16
43
+	scriptFlags := sf.ScriptBip16
44 44
 	err = checkBlockScripts(blocks[0], view, scriptFlags, nil, nil)
45 45
 	if err != nil {
46 46
 		t.Errorf("Transaction script validation failed: %v\n", err)

+ 4
- 4
blockchain/upgrade.go View File

@@ -423,10 +423,10 @@ func deserializeUtxoEntryV0(serialized []byte) (map[uint32]*UtxoEntry, error) {
423 423
 
424 424
 		// Create a new utxo entry with the details deserialized above.
425 425
 		entries[outputIndex] = &UtxoEntry{
426
-			amount:      int64(amount),
427
-			pkScript:    pkScript,
428
-			blockHeight: int32(blockHeight),
429
-			packedFlags: packedFlags,
426
+			Amount:      int64(amount),
427
+			PkScript:    pkScript,
428
+			BlockHeight: int32(blockHeight),
429
+			PackedFlags: packedFlags,
430 430
 		}
431 431
 	}
432 432
 

+ 24
- 24
blockchain/upgrade_test.go View File

@@ -23,10 +23,10 @@ func TestDeserializeUtxoEntryV0(t *testing.T) {
23 23
 			name: "Only output 0, coinbase",
24 24
 			entries: map[uint32]*UtxoEntry{
25 25
 				0: {
26
-					amount:      5000000000,
27
-					pkScript:    hexToBytes("410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac"),
28
-					blockHeight: 1,
29
-					packedFlags: tfCoinBase,
26
+					Amount:      5000000000,
27
+					PkScript:    hexToBytes("410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac"),
28
+					BlockHeight: 1,
29
+					PackedFlags: TFCoinBase,
30 30
 				},
31 31
 			},
32 32
 			serialized: hexToBytes("010103320496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52"),
@@ -37,10 +37,10 @@ func TestDeserializeUtxoEntryV0(t *testing.T) {
37 37
 			name: "Only output 1, not coinbase",
38 38
 			entries: map[uint32]*UtxoEntry{
39 39
 				1: {
40
-					amount:      1000000,
41
-					pkScript:    hexToBytes("76a914ee8bd501094a7d5ca318da2506de35e1cb025ddc88ac"),
42
-					blockHeight: 100001,
43
-					packedFlags: 0,
40
+					Amount:      1000000,
41
+					PkScript:    hexToBytes("76a914ee8bd501094a7d5ca318da2506de35e1cb025ddc88ac"),
42
+					BlockHeight: 100001,
43
+					PackedFlags: 0,
44 44
 				},
45 45
 			},
46 46
 			serialized: hexToBytes("01858c21040700ee8bd501094a7d5ca318da2506de35e1cb025ddc"),
@@ -51,10 +51,10 @@ func TestDeserializeUtxoEntryV0(t *testing.T) {
51 51
 			name: "Only output 2, coinbase",
52 52
 			entries: map[uint32]*UtxoEntry{
53 53
 				2: {
54
-					amount:      100937281,
55
-					pkScript:    hexToBytes("76a914da33f77cee27c2a975ed5124d7e4f7f97513510188ac"),
56
-					blockHeight: 99004,
57
-					packedFlags: tfCoinBase,
54
+					Amount:      100937281,
55
+					PkScript:    hexToBytes("76a914da33f77cee27c2a975ed5124d7e4f7f97513510188ac"),
56
+					BlockHeight: 99004,
57
+					PackedFlags: TFCoinBase,
58 58
 				},
59 59
 			},
60 60
 			serialized: hexToBytes("0185843c010182b095bf4100da33f77cee27c2a975ed5124d7e4f7f975135101"),
@@ -65,16 +65,16 @@ func TestDeserializeUtxoEntryV0(t *testing.T) {
65 65
 			name: "outputs 0 and 2 not coinbase",
66 66
 			entries: map[uint32]*UtxoEntry{
67 67
 				0: {
68
-					amount:      20000000,
69
-					pkScript:    hexToBytes("76a914e2ccd6ec7c6e2e581349c77e067385fa8236bf8a88ac"),
70
-					blockHeight: 113931,
71
-					packedFlags: 0,
68
+					Amount:      20000000,
69
+					PkScript:    hexToBytes("76a914e2ccd6ec7c6e2e581349c77e067385fa8236bf8a88ac"),
70
+					BlockHeight: 113931,
71
+					PackedFlags: 0,
72 72
 				},
73 73
 				2: {
74
-					amount:      15000000,
75
-					pkScript:    hexToBytes("76a914b8025be1b3efc63b0ad48e7f9f10e87544528d5888ac"),
76
-					blockHeight: 113931,
77
-					packedFlags: 0,
74
+					Amount:      15000000,
75
+					PkScript:    hexToBytes("76a914b8025be1b3efc63b0ad48e7f9f10e87544528d5888ac"),
76
+					BlockHeight: 113931,
77
+					PackedFlags: 0,
78 78
 				},
79 79
 			},
80 80
 			serialized: hexToBytes("0185f90b0a011200e2ccd6ec7c6e2e581349c77e067385fa8236bf8a800900b8025be1b3efc63b0ad48e7f9f10e87544528d58"),
@@ -85,10 +85,10 @@ func TestDeserializeUtxoEntryV0(t *testing.T) {
85 85
 			name: "Only output 22, not coinbase",
86 86
 			entries: map[uint32]*UtxoEntry{
87 87
 				22: {
88
-					amount:      366875659,
89
-					pkScript:    hexToBytes("a9141dd46a006572d820e448e12d2bbb38640bc718e687"),
90
-					blockHeight: 338156,
91
-					packedFlags: 0,
88
+					Amount:      366875659,
89
+					PkScript:    hexToBytes("a9141dd46a006572d820e448e12d2bbb38640bc718e687"),
90
+					BlockHeight: 338156,
91
+					PackedFlags: 0,
92 92
 				},
93 93
 			},
94 94
 			serialized: hexToBytes("0193d06c100000108ba5b9e763011dd46a006572d820e448e12d2bbb38640bc718e6"),

+ 43
- 43
blockchain/utxoviewpoint.go View File

@@ -42,38 +42,38 @@ type UtxoEntry struct {
42 42
 	// specifically crafted to result in minimal padding.  There will be a
43 43
 	// lot of these in memory, so a few extra bytes of padding adds up.
44 44
 
45
-	amount      int64
46
-	pkScript    []byte // The public key script for the output.
47
-	blockHeight int32  // Height of block containing tx.
45
+	Amount      int64
46
+	PkScript    []byte // The public key script for the output.
47
+	BlockHeight int32  // Height of block containing tx.
48 48
 
49 49
 	// packedFlags contains additional info about output such as whether it
50 50
 	// is a coinbase, whether it is spent, and whether it has been modified
51 51
 	// since it was loaded.  This approach is used in order to reduce memory
52 52
 	// usage since there will be a lot of these in memory.
53
-	packedFlags UtxoFlags
53
+	PackedFlags UtxoFlags
54 54
 }
55 55
 
56 56
 // isModified returns whether or not the output has been modified since it was
57 57
 // loaded.
58 58
 func (entry *UtxoEntry) isModified() bool {
59
-	return entry.packedFlags&TFModified == TFModified
59
+	return entry.PackedFlags&TFModified == TFModified
60 60
 }
61 61
 
62 62
 // IsCoinBase returns whether or not the output was contained in a coinbase
63 63
 // transaction.
64 64
 func (entry *UtxoEntry) IsCoinBase() bool {
65
-	return entry.packedFlags&TFCoinBase == TFCoinBase
65
+	return entry.PackedFlags&TFCoinBase == TFCoinBase
66 66
 }
67 67
 
68
-// BlockHeight returns the height of the block containing the output.
69
-func (entry *UtxoEntry) BlockHeight() int32 {
70
-	return entry.blockHeight
68
+// GetBlockHeight returns the height of the block containing the output.
69
+func (entry *UtxoEntry) GetBlockHeight() int32 {
70
+	return entry.BlockHeight
71 71
 }
72 72
 
73 73
 // IsSpent returns whether or not the output has been spent based upon the
74 74
 // current state of the unspent transaction output view it was obtained from.
75 75
 func (entry *UtxoEntry) IsSpent() bool {
76
-	return entry.packedFlags&TFSpent == TFSpent
76
+	return entry.PackedFlags&TFSpent == TFSpent
77 77
 }
78 78
 
79 79
 // Spend marks the output as spent.  Spending an output that is already spent
@@ -85,17 +85,17 @@ func (entry *UtxoEntry) Spend() {
85 85
 	}
86 86
 
87 87
 	// Mark the output as spent and modified.
88
-	entry.packedFlags |= TFSpent | TFModified
88
+	entry.PackedFlags |= TFSpent | TFModified
89 89
 }
90 90
 
91
-// Amount returns the amount of the output.
92
-func (entry *UtxoEntry) Amount() int64 {
93
-	return entry.amount
91
+// GetAmount returns the amount of the output.
92
+func (entry *UtxoEntry) GetAmount() int64 {
93
+	return entry.Amount
94 94
 }
95 95
 
96
-// PkScript returns the public key script for the output.
97
-func (entry *UtxoEntry) PkScript() []byte {
98
-	return entry.pkScript
96
+// GetPkScript returns the public key script for the output.
97
+func (entry *UtxoEntry) GetPkScript() []byte {
98
+	return entry.PkScript
99 99
 }
100 100
 
101 101
 // Clone returns a shallow copy of the utxo entry.
@@ -105,10 +105,10 @@ func (entry *UtxoEntry) Clone() *UtxoEntry {
105 105
 	}
106 106
 
107 107
 	return &UtxoEntry{
108
-		amount:      entry.amount,
109
-		pkScript:    entry.pkScript,
110
-		blockHeight: entry.blockHeight,
111
-		packedFlags: entry.packedFlags,
108
+		Amount:      entry.Amount,
109
+		PkScript:    entry.PkScript,
110
+		BlockHeight: entry.BlockHeight,
111
+		PackedFlags: entry.PackedFlags,
112 112
 	}
113 113
 }
114 114
 
@@ -164,12 +164,12 @@ func (view *UtxoViewpoint) addTxOut(outpoint wire.OutPoint, txOut *wire.TxOut, i
164 164
 		view.entries[outpoint] = entry
165 165
 	}
166 166
 
167
-	entry.amount = txOut.Value
168
-	entry.pkScript = txOut.PkScript
169
-	entry.blockHeight = blockHeight
170
-	entry.packedFlags = TFModified
167
+	entry.Amount = txOut.Value
168
+	entry.PkScript = txOut.PkScript
169
+	entry.BlockHeight = blockHeight
170
+	entry.PackedFlags = TFModified
171 171
 	if isCoinBase {
172
-		entry.packedFlags |= TFCoinBase
172
+		entry.PackedFlags |= TFCoinBase
173 173
 	}
174 174
 }
175 175
 
@@ -241,9 +241,9 @@ func (view *UtxoViewpoint) connectTransaction(tx *tx.Tx, blockHeight int32, stxo
241 241
 		if stxos != nil {
242 242
 			// Populate the stxo details using the utxo entry.
243 243
 			var stxo = SpentTxOut{
244
-				Amount:     entry.Amount(),
245
-				PkScript:   entry.PkScript(),
246
-				Height:     entry.BlockHeight(),
244
+				Amount:     entry.GetAmount(),
245
+				PkScript:   entry.GetPkScript(),
246
+				Height:     entry.GetBlockHeight(),
247 247
 				IsCoinBase: entry.IsCoinBase(),
248 248
 			}
249 249
 			*stxos = append(*stxos, stxo)
@@ -353,10 +353,10 @@ func (view *UtxoViewpoint) disconnectTransactions(db database.DB, block *block.B
353 353
 			entry := view.entries[prevOut]
354 354
 			if entry == nil {
355 355
 				entry = &UtxoEntry{
356
-					amount:      txOut.Value,
357
-					pkScript:    txOut.PkScript,
358
-					blockHeight: block.Height(),
359
-					packedFlags: packedFlags,
356
+					Amount:      txOut.Value,
357
+					PkScript:    txOut.PkScript,
358
+					BlockHeight: block.Height(),
359
+					PackedFlags: packedFlags,
360 360
 				}
361 361
 
362 362
 				view.entries[prevOut] = entry
@@ -407,28 +407,28 @@ func (view *UtxoViewpoint) disconnectTransactions(db database.DB, block *block.B
407 407
 			// only ever run with the new v2 format, this code path
408 408
 			// will never run.
409 409
 			if stxo.Height == 0 {
410
-				utxo, err := view.fetchEntryByHash(db, txHash)
410
+				uu, err := view.fetchEntryByHash(db, txHash)
411 411
 				if err != nil {
412 412
 					return err
413 413
 				}
414
-				if utxo == nil {
414
+				if uu == nil {
415 415
 					return AssertError(fmt.Sprintf("unable "+
416 416
 						"to resurrect legacy stxo %v",
417 417
 						*originOut))
418 418
 				}
419 419
 
420
-				stxo.Height = utxo.BlockHeight()
421
-				stxo.IsCoinBase = utxo.IsCoinBase()
420
+				stxo.Height = uu.GetBlockHeight()
421
+				stxo.IsCoinBase = uu.IsCoinBase()
422 422
 			}
423 423
 
424 424
 			// Restore the utxo using the stxo data from the spend
425 425
 			// journal and mark it as modified.
426
-			entry.amount = stxo.Amount
427
-			entry.pkScript = stxo.PkScript
428
-			entry.blockHeight = stxo.Height
429
-			entry.packedFlags = TFModified
426
+			entry.Amount = stxo.Amount
427
+			entry.PkScript = stxo.PkScript
428
+			entry.BlockHeight = stxo.Height
429
+			entry.PackedFlags = TFModified
430 430
 			if stxo.IsCoinBase {
431
-				entry.packedFlags |= TFCoinBase
431
+				entry.PackedFlags |= TFCoinBase
432 432
 			}
433 433
 		}
434 434
 	}
@@ -460,7 +460,7 @@ func (view *UtxoViewpoint) commit() {
460 460
 			continue
461 461
 		}
462 462
 
463
-		entry.packedFlags ^= TFModified
463
+		entry.PackedFlags ^= TFModified
464 464
 	}
465 465
 }
466 466
 

+ 7
- 7
blockchain/validate.go View File

@@ -396,7 +396,7 @@ func CountP2SHSigOps(tx *tx.Tx, isCoinBaseTx bool, utxoView *UtxoViewpoint) (int
396 396
 
397 397
 		// We're only interested in pay-to-script-hash types, so skip
398 398
 		// this input if it's not one.
399
-		pkScript := utxo.PkScript()
399
+		pkScript := utxo.GetPkScript()
400 400
 		if !txscript.IsPayToScriptHash(pkScript) {
401 401
 			continue
402 402
 		}
@@ -853,7 +853,7 @@ func (b *BlockChain) checkBIP0030(node *blockNode, block *block.Block, view *Utx
853 853
 		if utxo != nil && !utxo.IsSpent() {
854 854
 			str := fmt.Sprintf("tried to overwrite transaction %v "+
855 855
 				"at block height %d that is not fully spent",
856
-				outpoint.Hash, utxo.BlockHeight())
856
+				outpoint.Hash, utxo.GetBlockHeight())
857 857
 			return ruleError(ErrOverwriteTx, str)
858 858
 		}
859 859
 	}
@@ -882,8 +882,8 @@ func CheckTransactionInputs(tx *tx.Tx, txHeight int32, utxoView *UtxoViewpoint,
882 882
 	var totalSatoshiIn int64
883 883
 	for txInIndex, txIn := range tx.MsgTx().TxIn {
884 884
 		// Ensure the referenced input transaction is available.
885
-		utxo := utxoView.LookupEntry(txIn.PreviousOutPoint)
886
-		if utxo == nil || utxo.IsSpent() {
885
+		uu := utxoView.LookupEntry(txIn.PreviousOutPoint)
886
+		if uu == nil || uu.IsSpent() {
887 887
 			str := fmt.Sprintf("output %v referenced from "+
888 888
 				"transaction %s:%d either does not exist or "+
889 889
 				"has already been spent", txIn.PreviousOutPoint,
@@ -893,8 +893,8 @@ func CheckTransactionInputs(tx *tx.Tx, txHeight int32, utxoView *UtxoViewpoint,
893 893
 
894 894
 		// Ensure the transaction is not spending coins which have not
895 895
 		// yet reached the required coinbase maturity.
896
-		if utxo.IsCoinBase() {
897
-			originHeight := utxo.BlockHeight()
896
+		if uu.IsCoinBase() {
897
+			originHeight := uu.GetBlockHeight()
898 898
 			blocksSincePrev := txHeight - originHeight
899 899
 			coinbaseMaturity := int32(chainParams.CoinbaseMaturity)
900 900
 			if blocksSincePrev < coinbaseMaturity {
@@ -914,7 +914,7 @@ func CheckTransactionInputs(tx *tx.Tx, txHeight int32, utxoView *UtxoViewpoint,
914 914
 		// a transaction are in a unit value known as a satoshi.  One
915 915
 		// bitcoin is a quantity of satoshi as defined by the
916 916
 		// SatoshiPerBitcoin constant.
917
-		originTxSatoshi := utxo.Amount()
917
+		originTxSatoshi := uu.GetAmount()
918 918
 		if originTxSatoshi < 0 {
919 919
 			str := fmt.Sprintf("transaction output has negative "+
920 920
 				"value of %v", amt.Amount(originTxSatoshi))

+ 12
- 10
blockchain/validate_test.go View File

@@ -10,7 +10,9 @@ import (
10 10
 	"testing"
11 11
 	"time"
12 12
 
13
-	"git.parallelcoin.io/dev/btcd/btcutil"
13
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
14
+	"git.parallelcoin.io/dev/btcd/btcutil/tx"
15
+
14 16
 	"git.parallelcoin.io/dev/btcd/chaincfg"
15 17
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
16 18
 	"git.parallelcoin.io/dev/btcd/wire"
@@ -87,7 +89,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) {
87 89
 		"blk_3A.dat.bz2",
88 90
 	}
89 91
 
90
-	var blocks []*btcutil.Block
92
+	var blocks []*block.Block
91 93
 	for _, file := range testFiles {
92 94
 		blockTmp, err := loadBlocks(file)
93 95
 		if err != nil {
@@ -132,7 +134,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) {
132 134
 	// Block 4 should connect even if proof of work is invalid.
133 135
 	invalidPowBlock := *blocks[4].MsgBlock()
134 136
 	invalidPowBlock.Header.Nonce++
135
-	err = chain.CheckConnectBlockTemplate(btcutil.NewBlock(&invalidPowBlock))
137
+	err = chain.CheckConnectBlockTemplate(block.New(&invalidPowBlock))
136 138
 	if err != nil {
137 139
 		t.Fatalf("CheckConnectBlockTemplate: Received unexpected error on "+
138 140
 			"block 4 with bad nonce: %v", err)
@@ -141,7 +143,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) {
141 143
 	// Invalid block building on chain tip should fail to connect.
142 144
 	invalidBlock := *blocks[4].MsgBlock()
143 145
 	invalidBlock.Header.Bits--
144
-	err = chain.CheckConnectBlockTemplate(btcutil.NewBlock(&invalidBlock))
146
+	err = chain.CheckConnectBlockTemplate(block.New(&invalidBlock))
145 147
 	if err == nil {
146 148
 		t.Fatal("CheckConnectBlockTemplate: Did not received expected error " +
147 149
 			"on block 4 with invalid difficulty bits")
@@ -152,18 +154,18 @@ func TestCheckConnectBlockTemplate(t *testing.T) {
152 154
 // as expected.
153 155
 func TestCheckBlockSanity(t *testing.T) {
154 156
 	powLimit := chaincfg.MainNetParams.PowLimit
155
-	block := btcutil.NewBlock(&Block100000)
157
+	bb := block.New(&block.Block100000)
156 158
 	timeSource := NewMedianTime()
157
-	err := CheckBlockSanity(block, powLimit, timeSource)
159
+	err := CheckBlockSanity(bb, powLimit, timeSource)
158 160
 	if err != nil {
159 161
 		t.Errorf("CheckBlockSanity: %v", err)
160 162
 	}
161 163
 
162 164
 	// Ensure a block that has a timestamp with a precision higher than one
163 165
 	// second fails.
164
-	timestamp := block.MsgBlock().Header.Timestamp
165
-	block.MsgBlock().Header.Timestamp = timestamp.Add(time.Nanosecond)
166
-	err = CheckBlockSanity(block, powLimit, timeSource)
166
+	timestamp := bb.MsgBlock().Header.Timestamp
167
+	bb.MsgBlock().Header.Timestamp = timestamp.Add(time.Nanosecond)
168
+	err = CheckBlockSanity(bb, powLimit, timeSource)
167 169
 	if err == nil {
168 170
 		t.Errorf("CheckBlockSanity: error is nil when it shouldn't be")
169 171
 	}
@@ -213,7 +215,7 @@ func TestCheckSerializedHeight(t *testing.T) {
213 215
 	for i, test := range tests {
214 216
 		msgTx := coinbaseTx.Copy()
215 217
 		msgTx.TxIn[0].SignatureScript = test.sigScript
216
-		tx := btcutil.NewTx(msgTx)
218
+		tx := tx.New(msgTx)
217 219
 
218 220
 		err := checkSerializedHeight(tx, test.wantHeight)
219 221
 		if reflect.TypeOf(err) != reflect.TypeOf(test.err) {

+ 3
- 3
blockchain/weight.go View File

@@ -92,8 +92,8 @@ func GetSigOpCost(tx *tx.Tx, isCoinBaseTx bool, utxoView *UtxoViewpoint, bip16,
92 92
 		for txInIndex, txIn := range msgTx.TxIn {
93 93
 			// Ensure the referenced output is available and hasn't
94 94
 			// already been spent.
95
-			utxo := utxoView.LookupEntry(txIn.PreviousOutPoint)
96
-			if utxo == nil || utxo.IsSpent() {
95
+			uu := utxoView.LookupEntry(txIn.PreviousOutPoint)
96
+			if uu == nil || uu.IsSpent() {
97 97
 				str := fmt.Sprintf("output %v referenced from "+
98 98
 					"transaction %s:%d either does not "+
99 99
 					"exist or has already been spent",
@@ -104,7 +104,7 @@ func GetSigOpCost(tx *tx.Tx, isCoinBaseTx bool, utxoView *UtxoViewpoint, bip16,
104 104
 
105 105
 			witness := txIn.Witness
106 106
 			sigScript := txIn.SignatureScript
107
-			pkScript := utxo.PkScript()
107
+			pkScript := uu.GetPkScript()
108 108
 			numSigOps += txscript.GetWitnessSigOpCount(sigScript, pkScript, witness)
109 109
 		}
110 110
 

+ 5
- 2
btcutil/bloom/merkleblock_test.go View File

@@ -9,8 +9,11 @@ import (
9 9
 	"encoding/hex"
10 10
 	"testing"
11 11
 
12
+	"git.parallelcoin.io/dev/btcd/wire/version"
13
+
12 14
 	"git.parallelcoin.io/dev/btcd/btcutil/block"
13 15
 	"git.parallelcoin.io/dev/btcd/btcutil/bloom"
16
+	"git.parallelcoin.io/dev/btcd/btcutil/filter"
14 17
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
15 18
 	"git.parallelcoin.io/dev/btcd/wire"
16 19
 )
@@ -35,7 +38,7 @@ func TestMerkleBlock3(t *testing.T) {
35 38
 		return
36 39
 	}
37 40
 
38
-	f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll)
41
+	f := filter.New(10, 0, 0.000001, wire.BloomUpdateAll)
39 42
 
40 43
 	inputStr := "63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5"
41 44
 	hash, err := chainhash.NewHashFromStr(inputStr)
@@ -60,7 +63,7 @@ func TestMerkleBlock3(t *testing.T) {
60 63
 	}
61 64
 
62 65
 	got := bytes.NewBuffer(nil)
63
-	err = mBlock.BtcEncode(got, wire.ProtocolVersion, wire.LatestEncoding)
66
+	err = mBlock.BtcEncode(got, version.Protocol, wire.LatestEncoding)
64 67
 	if err != nil {
65 68
 		t.Errorf("TestMerkleBlock3 BtcEncode failed: %v", err)
66 69
 		return

+ 2
- 1
btcutil/coinset/coins.go View File

@@ -9,9 +9,10 @@ import (
9 9
 	"errors"
10 10
 	"sort"
11 11
 
12
+	"git.parallelcoin.io/dev/btcd/btcutil/amt"
13
+	"git.parallelcoin.io/dev/btcd/btcutil/tx"
12 14
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
13 15
 	"git.parallelcoin.io/dev/btcd/wire"
14
-	"git.parallelcoin.io/dev/btcd/btcutil"
15 16
 )
16 17
 
17 18
 // Coin represents a spendable transaction outpoint

+ 3
- 2
btcutil/coinset/coins_test.go View File

@@ -5,6 +5,8 @@
5 5
 package coinset_test
6 6
 
7 7
 import (
8
+	"git.parallelcoin.io/dev/btcd/btcutil/tx"
9
+	"git.parallelcoin.io/dev/btcd/btcutil/amt"
8 10
 	"bytes"
9 11
 	"crypto/sha256"
10 12
 	"encoding/hex"
@@ -13,7 +15,6 @@ import (
13 15
 
14 16
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
15 17
 	"git.parallelcoin.io/dev/btcd/wire"
16
-	"git.parallelcoin.io/dev/btcd/btcutil"
17 18
 	"git.parallelcoin.io/dev/btcd/btcutil/coinset"
18 19
 )
19 20
 
@@ -230,7 +231,7 @@ var (
230 231
 	testSimpleCoinTxPkScript0Hex      = "76a914686dd149a79b4a559d561fbc396d3e3c6628b98d88ac"
231 232
 	testSimpleCoinTxPkScript0Bytes, _ = hex.DecodeString(testSimpleCoinTxPkScript0Hex)
232 233
 	testSimpleCoinTxBytes, _          = hex.DecodeString(testSimpleCoinTxHex)
233
-	testSimpleCoinTx, _               = btcutil.NewTxFromBytes(testSimpleCoinTxBytes)
234
+	testSimpleCoinTx, _               = tx.NewFromBytes(testSimpleCoinTxBytes)
234 235
 	testSimpleCoin                    = &coinset.SimpleCoin{
235 236
 		Tx:         testSimpleCoinTx,
236 237
 		TxIndex:    0,

btcutil/bloom/example_test.go → btcutil/filter/example_test.go View File

@@ -2,28 +2,28 @@
2 2
 // Use of this source code is governed by an ISC
3 3
 // license that can be found in the LICENSE file.
4 4
 
5
-package bloom_test
5
+package filter_test
6 6
 
7 7
 import (
8 8
 	"fmt"
9 9
 	"math/rand"
10 10
 	"time"
11 11
 
12
+	"git.parallelcoin.io/dev/btcd/btcutil/filter"
12 13
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
13 14
 	"git.parallelcoin.io/dev/btcd/wire"
14
-	"git.parallelcoin.io/dev/btcd/btcutil/bloom"
15 15
 )
16 16
 
17 17
 // This example demonstrates how to create a new bloom filter, add a transaction
18 18
 // hash to it, and check if the filter matches the transaction.
19
-func ExampleNewFilter() {
19
+func ExampleNew() {
20 20
 	rand.Seed(time.Now().UnixNano())
21 21
 	tweak := rand.Uint32()
22 22
 
23 23
 	// Create a new bloom filter intended to hold 10 elements with a 0.01%
24 24
 	// false positive rate and does not include any automatic update
25 25
 	// functionality when transactions are matched.
26
-	filter := bloom.NewFilter(10, tweak, 0.0001, wire.BloomUpdateNone)
26
+	ff := filter.New(10, tweak, 0.0001, wire.BloomUpdateNone)
27 27
 
28 28
 	// Create a transaction hash and add it to the filter.  This particular
29 29
 	// trasaction is the first transaction in block 310,000 of the main
@@ -34,10 +34,10 @@ func ExampleNewFilter() {
34 34
 		fmt.Println(err)
35 35
 		return
36 36
 	}
37
-	filter.AddHash(txHash)
37
+	ff.AddHash(txHash)
38 38
 
39 39
 	// Show that the filter matches.
40
-	matches := filter.Matches(txHash[:])
40
+	matches := ff.Matches(txHash[:])
41 41
 	fmt.Println("Filter Matches?:", matches)
42 42
 
43 43
 	// Output:

+ 8
- 6
btcutil/filter/filter_test.go View File

@@ -5,11 +5,13 @@
5 5
 package filter_test
6 6
 
7 7
 import (
8
+	"git.parallelcoin.io/dev/btcd/btcutil/wif"
8 9
 	"bytes"
9 10
 	"encoding/hex"
10 11
 	"testing"
11 12
 
12
-	"git.parallelcoin.io/dev/btcd/btcutil"
13
+	"git.parallelcoin.io/dev/btcd/wire/version"
14
+
13 15
 	"git.parallelcoin.io/dev/btcd/btcutil/block"
14 16
 	"git.parallelcoin.io/dev/btcd/btcutil/bloom"
15 17
 	"git.parallelcoin.io/dev/btcd/btcutil/filter"
@@ -87,7 +89,7 @@ func TestFilterInsert(t *testing.T) {
87 89
 	}
88 90
 
89 91
 	got := bytes.NewBuffer(nil)
90
-	err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion, wire.LatestEncoding)
92
+	err = f.MsgFilterLoad().BtcEncode(got, version.Protocol, wire.LatestEncoding)
91 93
 	if err != nil {
92 94
 		t.Errorf("TestFilterInsert BtcDecode failed: %v\n", err)
93 95
 		return
@@ -147,7 +149,7 @@ func TestFilterFPRange(t *testing.T) {
147 149
 		f := test.filter
148 150
 		f.AddHash(hash)
149 151
 		got := bytes.NewBuffer(nil)
150
-		err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion, wire.LatestEncoding)
152
+		err = f.MsgFilterLoad().BtcEncode(got, version.Protocol, wire.LatestEncoding)
151 153
 		if err != nil {
152 154
 			t.Errorf("BtcDecode unexpected error: %v\n", err)
153 155
 			continue
@@ -200,7 +202,7 @@ func TestFilterInsertWithTweak(t *testing.T) {
200 202
 		return
201 203
 	}
202 204
 	got := bytes.NewBuffer(nil)
203
-	err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion, wire.LatestEncoding)
205
+	err = f.MsgFilterLoad().BtcEncode(got, version.Protocol, wire.LatestEncoding)
204 206
 	if err != nil {
205 207
 		t.Errorf("TestFilterInsertWithTweak BtcDecode failed: %v\n", err)
206 208
 		return
@@ -218,7 +220,7 @@ func TestFilterInsertWithTweak(t *testing.T) {
218 220
 func TestFilterInsertKey(t *testing.T) {
219 221
 	secret := "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C"
220 222
 
221
-	wif, err := btcutil.DecodeWIF(secret)
223
+	wif, err := wif.Decode(secret)
222 224
 	if err != nil {
223 225
 		t.Errorf("TestFilterInsertKey DecodeWIF failed: %v", err)
224 226
 		return
@@ -234,7 +236,7 @@ func TestFilterInsertKey(t *testing.T) {
234 236
 		return
235 237
 	}
236 238
 	got := bytes.NewBuffer(nil)
237
-	err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion, wire.LatestEncoding)
239
+	err = f.MsgFilterLoad().BtcEncode(got, version.Protocol, wire.LatestEncoding)
238 240
 	if err != nil {
239 241
 		t.Errorf("TestFilterInsertWithTweak BtcDecode failed: %v\n", err)
240 242
 		return

+ 2
- 2
btcutil/gcs/builder/builder_test.go View File

@@ -6,6 +6,7 @@
6 6
 package builder_test
7 7
 
8 8
 import (
9
+	"git.parallelcoin.io/dev/btcd/btcutil/ad"
9 10
 	"encoding/hex"
10 11
 	"testing"
11 12
 
@@ -13,7 +14,6 @@ import (
13 14
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
14 15
 	"git.parallelcoin.io/dev/btcd/txscript"
15 16
 	"git.parallelcoin.io/dev/btcd/wire"
16
-	"git.parallelcoin.io/dev/btcd/btcutil"
17 17
 	"git.parallelcoin.io/dev/btcd/btcutil/gcs"
18 18
 	"git.parallelcoin.io/dev/btcd/btcutil/gcs/builder"
19 19
 )
@@ -80,7 +80,7 @@ func TestUseBlockHash(t *testing.T) {
80 80
 	}
81 81
 
82 82
 	// btcutil.Address
83
-	addr, err := btcutil.DecodeAddress(testAddr, &chaincfg.MainNetParams)
83
+	addr, err := ad.DecodeAddress(testAddr, &chaincfg.MainNetParams)
84 84
 	if err != nil {
85 85
 		t.Fatalf("Address decode failed: %s", err.Error())
86 86
 	}

+ 8
- 6
btcutil/hdkeychain/extendedkey.go View File

@@ -18,11 +18,13 @@ import (
18 18
 	"fmt"
19 19
 	"math/big"
20 20
 
21
+	"git.parallelcoin.io/dev/btcd/btcutil/ad"
22
+
21 23
 	"git.parallelcoin.io/dev/btcd/btcec"
24
+	"git.parallelcoin.io/dev/btcd/btcutil/base58"
25
+	"git.parallelcoin.io/dev/btcd/btcutil/hash"
22 26
 	"git.parallelcoin.io/dev/btcd/chaincfg"
23 27
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
24
-	"git.parallelcoin.io/dev/btcd/btcutil"
25
-	"git.parallelcoin.io/dev/btcd/btcutil/base58"
26 28
 )
27 29
 
28 30
 const (
@@ -324,7 +326,7 @@ func (k *ExtendedKey) Child(i uint32) (*ExtendedKey, error) {
324 326
 
325 327
 	// The fingerprint of the parent for the derived child is the first 4
326 328
 	// bytes of the RIPEMD160(SHA256(parentPubKey)).
327
-	parentFP := btcutil.Hash160(k.pubKeyBytes())[:4]
329
+	parentFP := hash.H160(k.pubKeyBytes())[:4]
328 330
 	return NewExtendedKey(k.version, childKey, childChainCode, parentFP,
329 331
 		k.depth+1, i, isPrivate), nil
330 332
 }
@@ -377,9 +379,9 @@ func (k *ExtendedKey) ECPrivKey() (*btcec.PrivateKey, error) {
377 379
 
378 380
 // Address converts the extended key to a standard bitcoin pay-to-pubkey-hash
379 381
 // address for the passed network.
380
-func (k *ExtendedKey) Address(net *chaincfg.Params) (*btcutil.AddressPubKeyHash, error) {
381
-	pkHash := btcutil.Hash160(k.pubKeyBytes())
382
-	return btcutil.NewAddressPubKeyHash(pkHash, net)
382
+func (k *ExtendedKey) Address(net *chaincfg.Params) (*ad.PubKeyHash, error) {
383
+	pkHash := hash.H160(k.pubKeyBytes())
384
+	return ad.NewAddressPubKeyHash(pkHash, net)
383 385
 }
384 386
 
385 387
 // paddedAppend appends the src byte slice to dst, returning the new slice.

+ 9
- 10
btcutil/tx/tx_test.go View File

@@ -5,22 +5,21 @@
5 5
 package tx_test
6 6
 
7 7
 import (
8
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
9
+	"git.parallelcoin.io/dev/btcd/btcutil/tx"
8 10
 	"bytes"
9 11
 	"io"
10 12
 	"reflect"
11 13
 	"testing"
12 14
 
13
-	"git.parallelcoin.io/dev/btcd/blockchain"
14
-
15
-	"git.parallelcoin.io/dev/btcd/btcutil"
16 15
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
17 16
 	"github.com/davecgh/go-spew/spew"
18 17
 )
19 18
 
20 19
 // TestTx tests the API for Tx.
21 20
 func TestTx(t *testing.T) {
22
-	testTx := blockchain.Block100000.Transactions[0]
23
-	tx := btcutil.NewTx(testTx)
21
+	testTx := block.Block100000.Transactions[0]
22
+	tx := tx.New(testTx)
24 23
 
25 24
 	// Ensure we get the same data back out.
26 25
 	if msgTx := tx.MsgTx(); !reflect.DeepEqual(msgTx, testTx) {
@@ -56,7 +55,7 @@ func TestTx(t *testing.T) {
56 55
 // TestNewTxFromBytes tests creation of a Tx from serialized bytes.
57 56
 func TestNewTxFromBytes(t *testing.T) {
58 57
 	// Serialize the test transaction.
59
-	testTx := blockchain.Block100000.Transactions[0]
58
+	testTx := block.Block100000.Transactions[0]
60 59
 	var testTxBuf bytes.Buffer
61 60
 	err := testTx.Serialize(&testTxBuf)
62 61
 	if err != nil {
@@ -65,7 +64,7 @@ func TestNewTxFromBytes(t *testing.T) {
65 64
 	testTxBytes := testTxBuf.Bytes()
66 65
 
67 66
 	// Create a new transaction from the serialized bytes.
68
-	tx, err := btcutil.NewTxFromBytes(testTxBytes)
67
+	tx, err := tx.NewFromBytes(testTxBytes)
69 68
 	if err != nil {
70 69
 		t.Errorf("NewTxFromBytes: %v", err)
71 70
 		return
@@ -81,7 +80,7 @@ func TestNewTxFromBytes(t *testing.T) {
81 80
 // TestTxErrors tests the error paths for the Tx API.
82 81
 func TestTxErrors(t *testing.T) {
83 82
 	// Serialize the test transaction.
84
-	testTx := blockchain.Block100000.Transactions[0]
83
+	testTx := block.Block100000.Transactions[0]
85 84
 	var testTxBuf bytes.Buffer
86 85
 	err := testTx.Serialize(&testTxBuf)
87 86
 	if err != nil {
@@ -91,9 +90,9 @@ func TestTxErrors(t *testing.T) {
91 90
 
92 91
 	// Truncate the transaction byte buffer to force errors.
93 92
 	shortBytes := testTxBytes[:4]
94
-	_, err = btcutil.NewTxFromBytes(shortBytes)
93
+	_, err = tx.NewFromBytes(shortBytes)
95 94
 	if err != io.EOF {
96
-		t.Errorf("NewTxFromBytes: did not get expected error - "+
95
+		t.Errorf("tx.NewFromBytes: did not get expected error - "+
97 96
 			"got %v, want %v", err, io.EOF)
98 97
 	}
99 98
 }

+ 1
- 1
chaincfg/doc.go View File

@@ -10,7 +10,7 @@
10 10
 // For library packages, chaincfg provides the ability to lookup chain
11 11
 // parameters and encoding magics when passed a *Params.  Older APIs not updated
12 12
 // to the new convention of passing a *Params may lookup the parameters for a
13
-// wire.BitcoinNet using ParamsForNet, but be aware that this usage is
13
+// service.Net using ParamsForNet, but be aware that this usage is
14 14
 // deprecated and will be removed from chaincfg in the future.
15 15
 //
16 16
 // For main packages, a (typically global) var may be assigned the address of

+ 4
- 5
cmd/addblock/config.go View File

@@ -1,4 +1,3 @@
1
-
2 1
 package main
3 2
 
4 3
 import (
@@ -6,11 +5,11 @@ import (
6 5
 	"os"
7 6
 	"path/filepath"
8 7
 
8
+	"git.parallelcoin.io/dev/btcd/btcutil/appdata"
9 9
 	"git.parallelcoin.io/dev/btcd/chaincfg"
10 10
 	"git.parallelcoin.io/dev/btcd/database"
11 11
 	_ "git.parallelcoin.io/dev/btcd/database/ffldb"
12
-	"git.parallelcoin.io/dev/btcd/wire"
13
-	"git.parallelcoin.io/dev/btcd/btcutil"
12
+	"git.parallelcoin.io/dev/btcd/wire/service"
14 13
 	flags "github.com/jessevdk/go-flags"
15 14
 )
16 15
 
@@ -21,7 +20,7 @@ const (
21 20
 )
22 21
 
23 22
 var (
24
-	btcdHomeDir     = btcutil.AppDataDir("btcd", false)
23
+	btcdHomeDir     = appdata.Dir("btcd", false)
25 24
 	defaultDataDir  = filepath.Join(btcdHomeDir, "data")
26 25
 	knownDbTypes    = database.SupportedDrivers()
27 26
 	activeNetParams = &chaincfg.MainNetParams
@@ -74,7 +73,7 @@ func validDbType(dbType string) bool {
74 73
 // removed and the network parameter's name used instead.
75 74
 func netName(chainParams *chaincfg.Params) string {
76 75
 	switch chainParams.Net {
77
-	case wire.TestNet3:
76
+	case service.TestNet3:
78 77
 		return "testnet"
79 78
 	default:
80 79
 		return chainParams.Name

+ 8
- 8
cmd/addblock/import.go View File

@@ -1,4 +1,3 @@
1
-
2 1
 package main
3 2
 
4 3
 import (
@@ -8,12 +7,13 @@ import (
8 7
 	"sync"
9 8
 	"time"
10 9
 
10
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
11
+
11 12
 	"git.parallelcoin.io/dev/btcd/blockchain"
12 13
 	"git.parallelcoin.io/dev/btcd/blockchain/indexers"
13 14
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
14 15
 	"git.parallelcoin.io/dev/btcd/database"
15 16
 	"git.parallelcoin.io/dev/btcd/wire"
16
-	"git.parallelcoin.io/dev/btcd/btcutil"
17 17
 )
18 18
 
19 19
 var zeroHash = chainhash.Hash{}
@@ -91,17 +91,17 @@ func (bi *blockImporter) readBlock() ([]byte, error) {
91 91
 // with any potential errors.
92 92
 func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
93 93
 	// Deserialize the block which includes checks for malformed blocks.
94
-	block, err := btcutil.NewBlockFromBytes(serializedBlock)
94
+	bb, err := block.NewFromBytes(serializedBlock)
95 95
 	if err != nil {
96 96
 		return false, err
97 97
 	}
98 98
 
99 99
 	// update progress statistics
100
-	bi.lastBlockTime = block.MsgBlock().Header.Timestamp
101
-	bi.receivedLogTx += int64(len(block.MsgBlock().Transactions))
100
+	bi.lastBlockTime = bb.MsgBlock().Header.Timestamp
101
+	bi.receivedLogTx += int64(len(bb.MsgBlock().Transactions))
102 102
 
103 103
 	// Skip blocks that already exist.
104
-	blockHash := block.Hash()
104
+	blockHash := bb.Hash()
105 105
 	exists, err := bi.chain.HaveBlock(blockHash)
106 106
 	if err != nil {
107 107
 		return false, err
@@ -111,7 +111,7 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
111 111
 	}
112 112
 
113 113
 	// Don't bother trying to process orphans.
114
-	prevHash := &block.MsgBlock().Header.PrevBlock
114
+	prevHash := &bb.MsgBlock().Header.PrevBlock
115 115
 	if !prevHash.IsEqual(&zeroHash) {
116 116
 		exists, err := bi.chain.HaveBlock(prevHash)
117 117
 		if err != nil {
@@ -126,7 +126,7 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
126 126
 
127 127
 	// Ensure the blocks follows all of the chain rules and match up to the
128 128
 	// known checkpoints.
129
-	isMainChain, isOrphan, err := bi.chain.ProcessBlock(block,
129
+	isMainChain, isOrphan, err := bi.chain.ProcessBlock(bb,
130 130
 		blockchain.BFFastAdd)
131 131
 	if err != nil {
132 132
 		return false, err

+ 4
- 5
cmd/findcheckpoint/config.go View File

@@ -1,4 +1,3 @@
1
-
2 1
 package main
3 2
 
4 3
 import (
@@ -6,11 +5,11 @@ import (
6 5
 	"os"
7 6
 	"path/filepath"
8 7
 
8
+	"git.parallelcoin.io/dev/btcd/btcutil/appdata"
9
+	"git.parallelcoin.io/dev/btcd/wire/service"
9 10
 	"git.parallelcoin.io/dev/btcd/chaincfg"
10 11
 	"git.parallelcoin.io/dev/btcd/database"
11 12
 	_ "git.parallelcoin.io/dev/btcd/database/ffldb"
12
-	"git.parallelcoin.io/dev/btcd/wire"
13
-	"git.parallelcoin.io/dev/btcd/btcutil"
14 13
 	flags "github.com/jessevdk/go-flags"
15 14
 )
16 15
 
@@ -22,7 +21,7 @@ const (
22 21
 )
23 22
 
24 23
 var (
25
-	btcdHomeDir     = btcutil.AppDataDir("btcd", false)
24
+	btcdHomeDir     = appdata.Dir("btcd", false)
26 25
 	defaultDataDir  = filepath.Join(btcdHomeDir, "data")
27 26
 	knownDbTypes    = database.SupportedDrivers()
28 27
 	activeNetParams = &chaincfg.MainNetParams
@@ -63,7 +62,7 @@ func validDbType(dbType string) bool {
63 62
 // removed and the network parameter's name used instead.
64 63
 func netName(chainParams *chaincfg.Params) string {
65 64
 	switch chainParams.Net {
66
-	case wire.TestNet3:
65
+	case service.TestNet3:
67 66
 		return "testnet"
68 67
 	default:
69 68
 		return chainParams.Name

+ 5
- 3
cmd/gencerts/gencerts.go View File

@@ -12,7 +12,9 @@ import (
12 12
 	"strings"
13 13
 	"time"
14 14
 
15
-	"git.parallelcoin.io/dev/btcd/btcutil"
15
+	"git.parallelcoin.io/dev/btcd/btcutil/appdata"
16
+	"git.parallelcoin.io/dev/btcd/btcutil/cert"
17
+
16 18
 	flags "github.com/jessevdk/go-flags"
17 19
 )
18 20
 
@@ -58,7 +60,7 @@ func main() {
58 60
 	}
59 61
 
60 62
 	validUntil := time.Now().Add(time.Duration(cfg.Years) * 365 * 24 * time.Hour)
61
-	cert, key, err := btcutil.NewTLSCertPair(cfg.Organization, validUntil, cfg.ExtraHosts)
63
+	cert, key, err := cert.NewTLSCertPair(cfg.Organization, validUntil, cfg.ExtraHosts)
62 64
 	if err != nil {
63 65
 		fmt.Fprintf(os.Stderr, "cannot generate certificate pair: %v\n", err)
64 66
 		os.Exit(1)
@@ -81,7 +83,7 @@ func main() {
81 83
 func cleanAndExpandPath(path string) string {
82 84
 	// Expand initial ~ to OS specific home directory.
83 85
 	if strings.HasPrefix(path, "~") {
84
-		appHomeDir := btcutil.AppDataDir("gencerts", false)
86
+		appHomeDir := appdata.Dir("gencerts", false)
85 87
 		homeDir := filepath.Dir(appHomeDir)
86 88
 		path = strings.Replace(path, "~", homeDir, 1)
87 89
 	}

+ 4
- 4
database/cmd/dbtool/globalconfig.go View File

@@ -10,15 +10,15 @@ import (
10 10
 	"os"
11 11
 	"path/filepath"
12 12
 
13
+	"git.parallelcoin.io/dev/btcd/btcutil/appdata"
13 14
 	"git.parallelcoin.io/dev/btcd/chaincfg"
14 15
 	"git.parallelcoin.io/dev/btcd/database"
15 16
 	_ "git.parallelcoin.io/dev/btcd/database/ffldb"
16
-	"git.parallelcoin.io/dev/btcd/wire"
17
-	"git.parallelcoin.io/dev/btcd/btcutil"
17
+	"git.parallelcoin.io/dev/btcd/wire/service"
18 18
 )
19 19
 
20 20
 var (
21
-	btcdHomeDir     = btcutil.AppDataDir("btcd", false)
21
+	btcdHomeDir     = appdata.Dir("btcd", false)
22 22
 	knownDbTypes    = database.SupportedDrivers()
23 23
 	activeNetParams = &chaincfg.MainNetParams
24 24
 
@@ -70,7 +70,7 @@ func validDbType(dbType string) bool {
70 70
 // removed and the network parameter's name used instead.
71 71
 func netName(chainParams *chaincfg.Params) string {
72 72
 	switch chainParams.Net {
73
-	case wire.TestNet3:
73
+	case service.TestNet3:
74 74
 		return "testnet"
75 75
 	default:
76 76
 		return chainParams.Name

+ 8
- 7
database/cmd/dbtool/insecureimport.go View File

@@ -12,10 +12,11 @@ import (
12 12
 	"sync"
13 13
 	"time"
14 14
 
15
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
16
+
15 17
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
16 18
 	"git.parallelcoin.io/dev/btcd/database"
17 19
 	"git.parallelcoin.io/dev/btcd/wire"
18
-	"git.parallelcoin.io/dev/btcd/btcutil"
19 20
 )
20 21
 
21 22
 // importCmd defines the configuration options for the insecureimport command.
@@ -108,19 +109,19 @@ func (bi *blockImporter) readBlock() ([]byte, error) {
108 109
 // NOTE: This is not a safe import as it does not verify chain rules.
109 110
 func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
110 111
 	// Deserialize the block which includes checks for malformed blocks.
111
-	block, err := btcutil.NewBlockFromBytes(serializedBlock)
112
+	blk, err := block.NewFromBytes(serializedBlock)
112 113
 	if err != nil {
113 114
 		return false, err
114 115
 	}
115 116
 
116 117
 	// update progress statistics
117
-	bi.lastBlockTime = block.MsgBlock().Header.Timestamp
118
-	bi.receivedLogTx += int64(len(block.MsgBlock().Transactions))
118
+	bi.lastBlockTime = blk.MsgBlock().Header.Timestamp
119
+	bi.receivedLogTx += int64(len(blk.MsgBlock().Transactions))
119 120
 
120 121
 	// Skip blocks that already exist.
121 122
 	var exists bool
122 123
 	err = bi.db.View(func(tx database.Tx) error {
123
-		exists, err = tx.HasBlock(block.Hash())
124
+		exists, err = tx.HasBlock(blk.Hash())
124 125
 		return err
125 126
 	})
126 127
 	if err != nil {
@@ -131,7 +132,7 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
131 132
 	}
132 133
 
133 134
 	// Don't bother trying to process orphans.
134
-	prevHash := &block.MsgBlock().Header.PrevBlock
135
+	prevHash := &blk.MsgBlock().Header.PrevBlock
135 136
 	if !prevHash.IsEqual(&zeroHash) {
136 137
 		var exists bool
137 138
 		err := bi.db.View(func(tx database.Tx) error {
@@ -150,7 +151,7 @@ func (bi *blockImporter) processBlock(serializedBlock []byte) (bool, error) {
150 151
 
151 152
 	// Put the blocks into the database with no checking of chain rules.
152 153
 	err = bi.db.Update(func(tx database.Tx) error {
153
-		return tx.StoreBlock(block)
154
+		return tx.StoreBlock(blk)
154 155
 	})
155 156
 	if err != nil {
156 157
 		return false, err

+ 6
- 6
database/example_test.go View File

@@ -10,11 +10,11 @@ import (
10 10
 	"os"
11 11
 	"path/filepath"
12 12
 
13
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
13 14
 	"git.parallelcoin.io/dev/btcd/chaincfg"
14 15
 	"git.parallelcoin.io/dev/btcd/database"
15 16
 	_ "git.parallelcoin.io/dev/btcd/database/ffldb"
16
-	"git.parallelcoin.io/dev/btcd/wire"
17
-	"git.parallelcoin.io/dev/btcd/btcutil"
17
+	"git.parallelcoin.io/dev/btcd/wire/service"
18 18
 )
19 19
 
20 20
 // This example demonstrates creating a new database.
@@ -31,7 +31,7 @@ func ExampleCreate() {
31 31
 	// this, nor put it in the temp directory, but it's done here to ensure
32 32
 	// the example cleans up after itself.
33 33
 	dbPath := filepath.Join(os.TempDir(), "examplecreate")
34
-	db, err := database.Create("ffldb", dbPath, wire.MainNet)
34
+	db, err := database.Create("ffldb", dbPath, service.MainNet)
35 35
 	if err != nil {
36 36
 		fmt.Println(err)
37 37
 		return
@@ -57,7 +57,7 @@ func Example_basicUsage() {
57 57
 	// this, nor put it in the temp directory, but it's done here to ensure
58 58
 	// the example cleans up after itself.
59 59
 	dbPath := filepath.Join(os.TempDir(), "exampleusage")
60
-	db, err := database.Create("ffldb", dbPath, wire.MainNet)
60
+	db, err := database.Create("ffldb", dbPath, service.MainNet)
61 61
 	if err != nil {
62 62
 		fmt.Println(err)
63 63
 		return
@@ -123,7 +123,7 @@ func Example_blockStorageAndRetrieval() {
123 123
 	// this, nor put it in the temp directory, but it's done here to ensure
124 124
 	// the example cleans up after itself.
125 125
 	dbPath := filepath.Join(os.TempDir(), "exampleblkstorage")
126
-	db, err := database.Create("ffldb", dbPath, wire.MainNet)
126
+	db, err := database.Create("ffldb", dbPath, service.MainNet)
127 127
 	if err != nil {
128 128
 		fmt.Println(err)
129 129
 		return
@@ -136,7 +136,7 @@ func Example_blockStorageAndRetrieval() {
136 136
 	// and example.
137 137
 	err = db.Update(func(tx database.Tx) error {
138 138
 		genesisBlock := chaincfg.MainNetParams.GenesisBlock
139
-		return tx.StoreBlock(btcutil.NewBlock(genesisBlock))
139
+		return tx.StoreBlock(block.New(genesisBlock))
140 140
 	})
141 141
 	if err != nil {
142 142
 		fmt.Println(err)

+ 3
- 3
database/ffldb/bench_test.go View File

@@ -9,9 +9,9 @@ import (
9 9
 	"path/filepath"
10 10
 	"testing"
11 11
 
12
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
12 13
 	"git.parallelcoin.io/dev/btcd/chaincfg"
13 14
 	"git.parallelcoin.io/dev/btcd/database"
14
-	"git.parallelcoin.io/dev/btcd/btcutil"
15 15
 )
16 16
 
17 17
 // BenchmarkBlockHeader benchmarks how long it takes to load the mainnet genesis
@@ -28,7 +28,7 @@ func BenchmarkBlockHeader(b *testing.B) {
28 28
 	defer os.RemoveAll(dbPath)
29 29
 	defer db.Close()
30 30
 	err = db.Update(func(tx database.Tx) error {
31
-		block := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock)
31
+		block := block.New(chaincfg.MainNetParams.GenesisBlock)
32 32
 		return tx.StoreBlock(block)
33 33
 	})
34 34
 	if err != nil {
@@ -69,7 +69,7 @@ func BenchmarkBlock(b *testing.B) {
69 69
 	defer os.RemoveAll(dbPath)
70 70
 	defer db.Close()
71 71
 	err = db.Update(func(tx database.Tx) error {
72
-		block := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock)
72
+		block := block.New(chaincfg.MainNetParams.GenesisBlock)
73 73
 		return tx.StoreBlock(block)
74 74
 	})
75 75
 	if err != nil {

+ 2
- 2
database/ffldb/driver_test.go View File

@@ -12,10 +12,10 @@ import (
12 12
 	"runtime"
13 13
 	"testing"
14 14
 
15
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
15 16
 	"git.parallelcoin.io/dev/btcd/chaincfg"
16 17
 	"git.parallelcoin.io/dev/btcd/database"
17 18
 	"git.parallelcoin.io/dev/btcd/database/ffldb"
18
-	"git.parallelcoin.io/dev/btcd/btcutil"
19 19
 )
20 20
 
21 21
 // dbType is the database type name for this driver.
@@ -171,7 +171,7 @@ func TestPersistence(t *testing.T) {
171 171
 		"b1key2": "foo2",
172 172
 		"b1key3": "foo3",
173 173
 	}
174
-	genesisBlock := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock)
174
+	genesisBlock := block.New(chaincfg.MainNetParams.GenesisBlock)
175 175
 	genesisHash := chaincfg.MainNetParams.GenesisHash
176 176
 	err = db.Update(func(tx database.Tx) error {
177 177
 		metadataBucket := tx.Metadata()

+ 8
- 7
database/ffldb/interface_test.go View File

@@ -25,16 +25,17 @@ import (
25 25
 	"testing"
26 26
 	"time"
27 27
 
28
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
28 29
 	"git.parallelcoin.io/dev/btcd/chaincfg"
29 30
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
30 31
 	"git.parallelcoin.io/dev/btcd/database"
31 32
 	"git.parallelcoin.io/dev/btcd/wire"
32
-	"git.parallelcoin.io/dev/btcd/btcutil"
33
+	"git.parallelcoin.io/dev/btcd/wire/service"
33 34
 )
34 35
 
35 36
 var (
36 37
 	// blockDataNet is the expected network in the test block data.
37
-	blockDataNet = wire.MainNet
38
+	blockDataNet = service.MainNet
38 39
 
39 40
 	// blockDataFile is the path to a file containing the first 256 blocks
40 41
 	// of the block chain.
@@ -46,7 +47,7 @@ var (
46 47
 
47 48
 // loadBlocks loads the blocks contained in the testdata directory and returns
48 49
 // a slice of them.
49
-func loadBlocks(t *testing.T, dataFile string, network wire.BitcoinNet) ([]*btcutil.Block, error) {
50
+func loadBlocks(t *testing.T, dataFile string, network service.Net) ([]*block.Block, error) {
50 51
 	// Open the file that contains the blocks for reading.
51 52
 	fi, err := os.Open(dataFile)
52 53
 	if err != nil {
@@ -62,8 +63,8 @@ func loadBlocks(t *testing.T, dataFile string, network wire.BitcoinNet) ([]*btcu
62 63
 	dr := bzip2.NewReader(fi)
63 64
 
64 65
 	// Set the first block as the genesis block.
65
-	blocks := make([]*btcutil.Block, 0, 256)
66
-	genesis := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock)
66
+	blocks := make([]*block.Block, 0, 256)
67
+	genesis := block.New(chaincfg.MainNetParams.GenesisBlock)
67 68
 	blocks = append(blocks, genesis)
68 69
 
69 70
 	// Load the remaining blocks.
@@ -102,7 +103,7 @@ func loadBlocks(t *testing.T, dataFile string, network wire.BitcoinNet) ([]*btcu
102 103
 		}
103 104
 
104 105
 		// Deserialize and store the block.
105
-		block, err := btcutil.NewBlockFromBytes(blockBytes)
106
+		block, err := block.NewFromBytes(blockBytes)
106 107
 		if err != nil {
107 108
 			t.Errorf("Failed to parse block %v: %v", height, err)
108 109
 			return nil, err
@@ -139,7 +140,7 @@ type testContext struct {
139 140
 	db          database.DB
140 141
 	bucketDepth int
141 142
 	isWritable  bool
142
-	blocks      []*btcutil.Block
143
+	blocks      []*block.Block
143 144
 }
144 145
 
145 146
 // keyPair houses a key/value pair.  It is used over maps so ordering can be

+ 8
- 8
database/ffldb/whitebox_test.go View File

@@ -17,17 +17,17 @@ import (
17 17
 	"path/filepath"
18 18
 	"testing"
19 19
 
20
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
20 21
 	"git.parallelcoin.io/dev/btcd/chaincfg"
21 22
 	"git.parallelcoin.io/dev/btcd/database"
22
-	"git.parallelcoin.io/dev/btcd/wire"
23
-	"git.parallelcoin.io/dev/btcd/btcutil"
23
+	"git.parallelcoin.io/dev/btcd/wire/service"
24 24
 	"github.com/btcsuite/goleveldb/leveldb"
25 25
 	ldberrors "github.com/btcsuite/goleveldb/leveldb/errors"
26 26
 )
27 27
 
28 28
 var (
29 29
 	// blockDataNet is the expected network in the test block data.
30
-	blockDataNet = wire.MainNet
30
+	blockDataNet = service.MainNet
31 31
 
32 32
 	// blockDataFile is the path to a file containing the first 256 blocks
33 33
 	// of the block chain.
@@ -39,7 +39,7 @@ var (
39 39
 
40 40
 // loadBlocks loads the blocks contained in the testdata directory and returns
41 41
 // a slice of them.
42
-func loadBlocks(t *testing.T, dataFile string, network wire.BitcoinNet) ([]*btcutil.Block, error) {
42
+func loadBlocks(t *testing.T, dataFile string, network service.Net) ([]*block.Block, error) {
43 43
 	// Open the file that contains the blocks for reading.
44 44
 	fi, err := os.Open(dataFile)
45 45
 	if err != nil {
@@ -55,8 +55,8 @@ func loadBlocks(t *testing.T, dataFile string, network wire.BitcoinNet) ([]*btcu
55 55
 	dr := bzip2.NewReader(fi)
56 56
 
57 57
 	// Set the first block as the genesis block.
58
-	blocks := make([]*btcutil.Block, 0, 256)
59
-	genesis := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock)
58
+	blocks := make([]*block.Block, 0, 256)
59
+	genesis := block.New(chaincfg.MainNetParams.GenesisBlock)
60 60
 	blocks = append(blocks, genesis)
61 61
 
62 62
 	// Load the remaining blocks.
@@ -95,7 +95,7 @@ func loadBlocks(t *testing.T, dataFile string, network wire.BitcoinNet) ([]*btcu
95 95
 		}
96 96
 
97 97
 		// Deserialize and store the block.
98
-		block, err := btcutil.NewBlockFromBytes(blockBytes)
98
+		block, err := block.NewFromBytes(blockBytes)
99 99
 		if err != nil {
100 100
 			t.Errorf("Failed to parse block %v: %v", height, err)
101 101
 			return nil, err
@@ -132,7 +132,7 @@ type testContext struct {
132 132
 	db           database.DB
133 133
 	files        map[uint32]*lockableFile
134 134
 	maxFileSizes map[uint32]int64
135
-	blocks       []*btcutil.Block
135
+	blocks       []*block.Block
136 136
 }
137 137
 
138 138
 // TestConvertErr ensures the leveldb error to database error conversion works

+ 3
- 3
docs/json_rpc_api.md View File

@@ -1105,7 +1105,7 @@ func main() {
1105 1105
 	// Load the certificate for the TLS connection which is automatically
1106 1106
 	// generated by btcd when it starts the RPC server and doesn't already
1107 1107
 	// have one.
1108
-	btcdHomeDir := btcutil.AppDataDir("btcd", false)
1108
+	btcdHomeDir := appdata.Dir("btcd", false)
1109 1109
 	certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
1110 1110
 	if err != nil {
1111 1111
 		log.Fatal(err)
@@ -1169,7 +1169,7 @@ func main() {
1169 1169
 	// Load the certificate for the TLS connection which is automatically
1170 1170
 	// generated by btcd when it starts the RPC server and doesn't already
1171 1171
 	// have one.
1172
-	btcdHomeDir := btcutil.AppDataDir("btcd", false)
1172
+	btcdHomeDir := appdata.Dir("btcd", false)
1173 1173
 	certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
1174 1174
 	if err != nil {
1175 1175
 		log.Fatal(err)
@@ -1272,7 +1272,7 @@ func main() {
1272 1272
 	// Load the certificate for the TLS connection which is automatically
1273 1273
 	// generated by btcd when it starts the RPC server and doesn't already
1274 1274
 	// have one.
1275
-	btcdHomeDir := btcutil.AppDataDir("btcd", false)
1275
+	btcdHomeDir := appdata.Dir("btcd", false)
1276 1276
 	certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
1277 1277
 	if err != nil {
1278 1278
 		log.Fatal(err)

+ 19
- 16
integration/rpctest/blockgen.go View File

@@ -12,11 +12,14 @@ import (
12 12
 	"time"
13 13
 
14 14
 	"git.parallelcoin.io/dev/btcd/blockchain"
15
+	"git.parallelcoin.io/dev/btcd/btcutil/ad"
16
+	"git.parallelcoin.io/dev/btcd/btcutil/block"
17
+	"git.parallelcoin.io/dev/btcd/btcutil/tx"
15 18
 	"git.parallelcoin.io/dev/btcd/chaincfg"
16 19
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
17 20
 	"git.parallelcoin.io/dev/btcd/txscript"
21
+	"git.parallelcoin.io/dev/btcd/util/diff"
18 22
 	"git.parallelcoin.io/dev/btcd/wire"
19
-	"git.parallelcoin.io/dev/btcd/btcutil"
20 23
 )
21 24
 
22 25
 // solveBlock attempts to find a nonce which makes the passed block header hash
@@ -44,7 +47,7 @@ func solveBlock(header *wire.BlockHeader, targetDifficulty *big.Int) bool {
44 47
 			default:
45 48
 				hdr.Nonce = i
46 49
 				hash := hdr.BlockHash()
47
-				if blockchain.HashToBig(&hash).Cmp(targetDifficulty) <= 0 {
50
+				if diff.HashToBig(&hash).Cmp(targetDifficulty) <= 0 {
48 51
 					select {
49 52
 					case results <- sbResult{true, i}:
50 53
 						return
@@ -96,7 +99,7 @@ func standardCoinbaseScript(nextBlockHeight int32, extraNonce uint64) ([]byte, e
96 99
 // createCoinbaseTx returns a coinbase transaction paying an appropriate
97 100
 // subsidy based on the passed block height to the provided address.
98 101
 func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int32,
99
-	addr btcutil.Address, mineTo []wire.TxOut,
102
+	addr ad.Address, mineTo []wire.TxOut,
100 103
 	net *chaincfg.Params) (*tx.Tx, error) {
101 104
 
102 105
 	// Create the script to pay to the provided payment address.
@@ -105,8 +108,8 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int32,
105 108
 		return nil, err
106 109
 	}
107 110
 
108
-	tx := wire.NewMsgTx(wire.TxVersion)
109
-	tx.AddTxIn(&wire.TxIn{
111
+	tt := wire.NewMsgTx(wire.TxVersion)
112
+	tt.AddTxIn(&wire.TxIn{
110 113
 		// Coinbase transactions have no inputs, so previous outpoint is
111 114
 		// zero hash and max index.
112 115
 		PreviousOutPoint: *wire.NewOutPoint(&chainhash.Hash{},
@@ -115,16 +118,16 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int32,
115 118
 		Sequence:        wire.MaxTxInSequenceNum,
116 119
 	})
117 120
 	if len(mineTo) == 0 {
118
-		tx.AddTxOut(&wire.TxOut{
121
+		tt.AddTxOut(&wire.TxOut{
119 122
 			Value:    blockchain.CalcBlockSubsidy(nextBlockHeight, net),
120 123
 			PkScript: pkScript,
121 124
 		})
122 125
 	} else {
123 126
 		for i := range mineTo {
124
-			tx.AddTxOut(&mineTo[i])
127
+			tt.AddTxOut(&mineTo[i])
125 128
 		}
126 129
 	}
127
-	return btcutil.NewTx(tx), nil
130
+	return tx.New(tt), nil
128 131
 }
129 132
 
130 133
 // CreateBlock creates a new block building from the previous block with a
@@ -132,9 +135,9 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int32,
132 135
 // initialized), then the timestamp of the previous block will be used plus 1
133 136
 // second is used. Passing nil for the previous block results in a block that
134 137
 // builds off of the genesis block for the specified chain.
135
-func CreateBlock(prevBlock *btcutil.Block, inclusionTxs []*tx.Tx,
136
-	blockVersion int32, blockTime time.Time, miningAddr btcutil.Address,
137
-	mineTo []wire.TxOut, net *chaincfg.Params) (*btcutil.Block, error) {
138
+func CreateBlock(prevBlock *block.Block, inclusionTxs []*tx.Tx,
139
+	blockVersion int32, blockTime time.Time, miningAddr ad.Address,
140
+	mineTo []wire.TxOut, net *chaincfg.Params) (*block.Block, error) {
138 141
 
139 142
 	var (
140 143
 		prevHash      *chainhash.Hash
@@ -182,8 +185,8 @@ func CreateBlock(prevBlock *btcutil.Block, inclusionTxs []*tx.Tx,
182 185
 		blockTxns = append(blockTxns, inclusionTxs...)
183 186
 	}
184 187
 	merkles := blockchain.BuildMerkleTreeStore(blockTxns, false)
185
-	var block wire.MsgBlock
186
-	block.Header = wire.BlockHeader{
188
+	var bb wire.MsgBlock
189
+	bb.Header = wire.BlockHeader{
187 190
 		Version:    blockVersion,
188 191
 		PrevBlock:  *prevHash,
189 192
 		MerkleRoot: *merkles[len(merkles)-1],
@@ -191,17 +194,17 @@ func CreateBlock(prevBlock *btcutil.Block, inclusionTxs []*tx.Tx,
191 194
 		Bits:       net.PowLimitBits,
192 195
 	}
193 196
 	for _, tx := range blockTxns {
194
-		if err := block.AddTransaction(tx.MsgTx()); err != nil {
197
+		if err := bb.AddTransaction(tx.MsgTx()); err != nil {
195 198
 			return nil, err
196 199
 		}
197 200
 	}
198 201
 
199
-	found := solveBlock(&block.Header, net.PowLimit)
202
+	found := solveBlock(&bb.Header, net.PowLimit)
200 203
 	if !found {
201 204
 		return nil, errors.New("Unable to solve block")
202 205
 	}
203 206
 
204
-	utilBlock := btcutil.NewBlock(&block)
207
+	utilBlock := block.New(&bb)
205 208
 	utilBlock.SetHeight(blockHeight)
206 209
 	return utilBlock, nil
207 210
 }

+ 17
- 14
integration/rpctest/memwallet.go View File

@@ -10,15 +10,18 @@ import (
10 10
 	"fmt"
11 11
 	"sync"
12 12
 
13
+	"git.parallelcoin.io/dev/btcd/btcutil/ad"
14
+
13 15
 	"git.parallelcoin.io/dev/btcd/blockchain"
14 16
 	"git.parallelcoin.io/dev/btcd/btcec"
17
+	"git.parallelcoin.io/dev/btcd/btcutil/amt"
18
+	"git.parallelcoin.io/dev/btcd/btcutil/hdkeychain"
19
+	"git.parallelcoin.io/dev/btcd/btcutil/tx"
15 20
 	"git.parallelcoin.io/dev/btcd/chaincfg"
16 21
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
17 22
 	"git.parallelcoin.io/dev/btcd/rpcclient"
18 23
 	"git.parallelcoin.io/dev/btcd/txscript"
19 24
 	"git.parallelcoin.io/dev/btcd/wire"
20
-	"git.parallelcoin.io/dev/btcd/btcutil"
21
-	"git.parallelcoin.io/dev/btcd/btcutil/hdkeychain"
22 25
 )
23 26
 
24 27
 var (
@@ -72,7 +75,7 @@ type undoEntry struct {
72 75
 // hierarchy which promotes reproducibility between harness test runs.
73 76
 type memWallet struct {
74 77
 	coinbaseKey  *btcec.PrivateKey
75
-	coinbaseAddr btcutil.Address
78
+	coinbaseAddr ad.Address
76 79
 
77 80
 	// hdRoot is the root master private key for the wallet.
78 81
 	hdRoot *hdkeychain.ExtendedKey
@@ -86,7 +89,7 @@ type memWallet struct {
86 89
 
87 90
 	// addrs tracks all addresses belonging to the wallet. The addresses
88 91
 	// are indexed by their keypath from the hdRoot.
89
-	addrs map[uint32]btcutil.Address
92
+	addrs map[uint32]ad.Address
90 93
 
91 94
 	// utxos is the set of utxos spendable by the wallet.
92 95
 	utxos map[wire.OutPoint]*utxo
@@ -140,7 +143,7 @@ func newMemWallet(net *chaincfg.Params, harnessID uint32) (*memWallet, error) {
140 143
 
141 144
 	// Track the coinbase generation address to ensure we properly track
142 145
 	// newly generated bitcoin we can spend.
143
-	addrs := make(map[uint32]btcutil.Address)
146
+	addrs := make(map[uint32]ad.Address)
144 147
 	addrs[0] = coinbaseAddr
145 148
 
146 149
 	return &memWallet{
@@ -334,7 +337,7 @@ func (m *memWallet) unwindBlock(update *chainUpdate) {
334 337
 // newAddress returns a new address from the wallet's hd key chain.  It also
335 338
 // loads the address into the RPC client's transaction filter to ensure any
336 339
 // transactions that involve it are delivered via the notifications.
337
-func (m *memWallet) newAddress() (btcutil.Address, error) {
340
+func (m *memWallet) newAddress() (ad.Address, error) {
338 341
 	index := m.hdIndex
339 342
 
340 343
 	childKey, err := m.hdRoot.Child(index)
@@ -351,7 +354,7 @@ func (m *memWallet) newAddress() (btcutil.Address, error) {
351 354
 		return nil, err
352 355
 	}
353 356
 
354
-	err = m.rpc.LoadTxFilter(false, []btcutil.Address{addr}, nil)
357
+	err = m.rpc.LoadTxFilter(false, []ad.Address{addr}, nil)
355 358
 	if err != nil {
356 359
 		return nil, err
357 360
 	}
@@ -366,7 +369,7 @@ func (m *memWallet) newAddress() (btcutil.Address, error) {
366 369
 // NewAddress returns a fresh address spendable by the wallet.
367 370
 //
368 371
 // This function is safe for concurrent access.
369
-func (m *memWallet) NewAddress() (btcutil.Address, error) {
372
+func (m *memWallet) NewAddress() (ad.Address, error) {
370 373
 	m.Lock()
371 374
 	defer m.Unlock()
372 375
 
@@ -414,14 +417,14 @@ func (m *memWallet) fundTx(tx *wire.MsgTx, aa amt.Amount,
414 417
 		// coins from he current amount selected to pay the fee, then
415 418
 		// continue to grab more coins.
416 419
 		reqFee := amt.Amount(txSize * int(feeRate))
417
-		if amtSelected-reqFee < amt {
420
+		if amtSelected-reqFee < aa {
418 421
 			continue
419 422
 		}
420 423
 
421 424
 		// If we have any change left over and we should create a change
422 425
 		// output, then add an additional output to the transaction
423 426
 		// reserved for it.
424
-		changeVal := amtSelected - amt - reqFee
427
+		changeVal := amtSelected - aa - reqFee
425 428
 		if changeVal > 0 && change {
426 429
 			addr, err := m.newAddress()
427 430
 			if err != nil {
@@ -490,7 +493,7 @@ func (m *memWallet) CreateTransaction(outputs []*wire.TxOut,
490 493
 
491 494
 	// Tally up the total amount to be sent in order to perform coin
492 495
 	// selection shortly below.
493
-	var outputaa amt.Amount
496
+	var outputAmt amt.Amount
494 497
 	for _, output := range outputs {
495 498
 		outputAmt += amt.Amount(output.Value)
496 499
 		tx.AddTxOut(output)
@@ -581,11 +584,11 @@ func (m *memWallet) ConfirmedBalance() amt.Amount {
581 584
 }
582 585
 
583 586
 // keyToAddr maps the passed private to corresponding p2pkh address.
584
-func keyToAddr(key *btcec.PrivateKey, net *chaincfg.Params) (btcutil.Address, error) {
587
+func keyToAddr(key *btcec.PrivateKey, net *chaincfg.Params) (ad.Address, error) {
585 588
 	serializedKey := key.PubKey().SerializeCompressed()
586
-	pubKeyAddr, err := btcutil.NewAddressPubKey(serializedKey, net)
589
+	pubKeyAddr, err := ad.NewPubKey(serializedKey, net)
587 590
 	if err != nil {
588 591
 		return nil, err
589 592
 	}
590
-	return pubKeyAddr.AddressPubKeyHash(), nil
593
+	return pubKeyAddr.PubKeyHash(), nil
591 594
 }

+ 3
- 3
integration/rpctest/node.go View File

@@ -14,8 +14,8 @@ import (
14 14
 	"runtime"
15 15
 	"time"