Skip to content

Commit 40dc55b

Browse files
committed
Merge branch 'master' of github.com:BitcoinSchema/go-bitcoin
2 parents e9af92a + fba38ce commit 40dc55b

File tree

6 files changed

+73
-19
lines changed

6 files changed

+73
-19
lines changed

.github/dependabot.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Basic dependabot.yml to update gomod
2+
3+
version: 2
4+
updates:
5+
- package-ecosystem: "gomod"
6+
target-branch: "master"
7+
directory: "/"
8+
schedule:
9+
interval: "daily"
10+
# Check for npm updates at 9am UTC (5am EST)
11+
time: "10:00"
12+
reviewers:
13+
- "mrz1836"
14+
assignees:
15+
- "mrz1836"
16+
# Labels must be created first
17+
labels:
18+
- "update"

.make/Makefile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ install-go: ## Install the application (Using Native Go)
4242

4343
lint: ## Run the golangci-lint application (install if not found)
4444
@#Travis (has sudo)
45-
@if [ "$(shell command -v golangci-lint)" = "" ] && [ $(TRAVIS) ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.32.0 && sudo cp ./bin/golangci-lint $(go env GOPATH)/bin/; fi;
45+
@if [ "$(shell command -v golangci-lint)" = "" ] && [ $(TRAVIS) ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.32.2 && sudo cp ./bin/golangci-lint $(go env GOPATH)/bin/; fi;
4646
@#AWS CodePipeline
47-
@if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(CODEBUILD_BUILD_ID)" != "" ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.32.0; fi;
47+
@if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(CODEBUILD_BUILD_ID)" != "" ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.32.2; fi;
4848
@#Brew - MacOS
4949
@if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(shell command -v brew)" != "" ]; then brew install golangci-lint; fi;
5050
@echo "running golangci-lint..."

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ github.com/libsv/libsv v0.0.11/go.mod h1:jhXD2sLtYUNMWoD9mWmsQN0hoGZUK1wCvindT1O
1111
github.com/piotrnar/gocoin v0.0.0-20201027184336-0c389d7eb2c0 h1:PuqJFsnjEnbgSk7b629KC4jyuWqr5tM09k80ZpyptHY=
1212
github.com/piotrnar/gocoin v0.0.0-20201027184336-0c389d7eb2c0/go.mod h1:sW6i99ojgdRHcz53PCjyEeoTEDFh9dfP5iiEIiNfcaM=
1313
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
14+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
1415
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
1516
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
1617
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

transaction.go

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func CreateTxWithChange(utxos []*Utxo, payToAddresses []*PayToAddress, opReturns
108108
// Calculate the fees for the "Draft tx"
109109
fee := CalculateFeeForTx(tx, standardRate, dataRate)
110110

111+
// todo: replace with Libsv's new way to create change tx (when released)
112+
// for now (hacking the fee) (ensure we are over the min fee for the miner)
113+
fee++
114+
111115
// Check that we have enough to cover the fee
112116
if (totalPayToSatoshis + fee) > totalSatoshis {
113117
return nil, fmt.Errorf("not enough in utxo(s) to cover: %d found: %d", totalPayToSatoshis+fee, totalSatoshis)

transaction_test.go

+24-7
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,22 @@ func TestCalculateFeeForTxVariousTxs(t *testing.T) {
528528
"8785ca5f11795a38eb1f50f62562cb5e0335b283762fe8a2c7e96d5f7f79bb15",
529529
220,
530530
},
531+
{"01000000014179d984eb4738acddf290d1cbcb6ec0b44d945dc00020a9337738a4b5d4d0c5020000006b483045022100acc8301fb2f9bf70089e03f2a28ff8a384c0525e94a8ee5bb1ccb9b1f044bb91022012b5fb696bb92b2208f901e8bd43264a161cf97f72024cc1809224eee5fd7bab412102ad7b9a78da643560d0ffa411d27070d2468eccfcbb5b39ec30d69724a181944cffffffff045d020000000000001976a91409cc4559bdcb84cb35c107743f0dbb10d66679cc88ac9e170000000000001976a9141531448d45a7985230d2ad467acc22f635f0d10988ac985b8800000000001976a914cf500ad6b6852a13017d60080e58522716e33b9088ac0000000000000000ac006a223150755161374b36324d694b43747373534c4b79316b683536575755374d74555235035345540361707008746f6e6963706f7704747970650b6f666665725f636c69636b0f6f666665725f636f6e6669675f6964023239106f666665725f73657373696f6e5f6964403361303930636439393361346564386239626261303438643030653134666466303931633266616134333735396236366434363136396634613066313463343900000000",
532+
nil,
533+
nil,
534+
"32050b05bf48440bbb3e7c4fa79aa6cb36a69e2921965780334ee168de41f676",
535+
220,
536+
}, {"0100000001462c8567bdd70e5f4d36204c239eb1149e15f778925d5e4d36c3a0e7862bf887020000006b483045022100c55116cad7dd3c6bfba1ac4b696ebf60792032c4189c2c30735cfcad300a1c8f02201db5aa8fc38db419b559ff01a07a6dfaac1d5d7b940e89b398fa92bf387b1899412102ad7b9a78da643560d0ffa411d27070d2468eccfcbb5b39ec30d69724a181944cffffffff045c020000000000001976a91409cc4559bdcb84cb35c107743f0dbb10d66679cc88ac9b170000000000001976a9141531448d45a7985230d2ad467acc22f635f0d10988acf3258800000000001976a914cf500ad6b6852a13017d60080e58522716e33b9088ac0000000000000000ac006a223150755161374b36324d694b43747373534c4b79316b683536575755374d74555235035345540361707008746f6e6963706f7704747970650b6f666665725f636c69636b0f6f666665725f636f6e6669675f6964023239106f666665725f73657373696f6e5f6964403634353530346139663966383533393862323434363339336237393066303265666236343738366661666533326535333737373062653064646437663532323700000000",
537+
nil,
538+
nil,
539+
"4232216b35ebaa9301e386010eaaba05902be7bd4db60e2f588ae9d0e3e583e9",
540+
220,
541+
}, {"01000000014c0b196f630c02005b9c17069deef60dff492bdfd0a54a140aaaaf3769ab3d09020000006a47304402207b9acc2cb029617b625fe2a7fc4553b4b70d9f9ec87afc5aa5289866841cbf3702203047baf62881a098cb24bfa85e7f20c37513a8cbbd27efb4b30ad3519118ed7d4121028ae3c8bf25ae420e3e451be1b40f7edb8ff64e0ce32a2398b1d9374c1d50733cffffffff045c020000000000001976a914806773d8c6f90c544b98755e9a80915488357bbe88ac93170000000000001976a914a16150864dc3041666ab055f154da6c35335b6fb88acc2dd7500000000001976a914d1fc52081c4cf54454eeed6982d6b2977c40196088ac0000000000000000ad006a223150755161374b36324d694b43747373534c4b79316b683536575755374d74555235035345540361707008746f6e6963706f7704747970650b6f666665725f636c69636b0f6f666665725f636f6e6669675f696403313532106f666665725f73657373696f6e5f6964406637343736653061343763333863616664663061616164336564643539363831306235616539396130633737396637643035383438346330323933326238393500000000",
542+
nil,
543+
nil,
544+
"7a868c8529e598195c6c2cbf30006cb09fd55e9f3d3d809a38f191a586a3ce82",
545+
220,
546+
},
531547
{"010000000190c5208bed05b4e54746bab5a5d4a5e4324e2999c180b7ea7105047f1f16b84a030000006a47304402202ca5d7a2cfb2388babb549b10c47ed20cdadafb845af835c7d5ff04e933ba1c102200a8b7289bbd3c0cc62172afe0006ba374ddd0132a7e4fb4e92ebcff5ce9217db412102812d641ff356c362815f8fc03bd061c2ae57e02f5dc3083f61785c0e5b198039ffffffff040000000000000000ad006a223150755161374b36324d694b43747373534c4b79316b683536575755374d74555235035345540361707008746f6e6963706f7704747970650b6f666665725f636c69636b0f6f666665725f636f6e6669675f696403323934106f666665725f73657373696f6e5f696440653638616631393439626131633239326131376431393635343638383234383663653635313830663465363439383235613561363532376634646132303761661f0c0000000000001976a91409cc4559bdcb84cb35c107743f0dbb10d66679cc88ac31790000000000001976a9147c8ced9ee0f48192822a0148f27b5a1f24aa42d388ac53f74600000000001976a914852f89e9b05d6adfc905842ee0d301947d675df988ac00000000",
532548
&FeeAmount{Bytes: DefaultRateBytes, Satoshis: 1000},
533549
&FeeAmount{Bytes: DefaultRateBytes, Satoshis: 1000},
@@ -560,6 +576,7 @@ func TestCalculateFeeForTxVariousTxs(t *testing.T) {
560576

561577
// Test the function
562578
if satoshis = CalculateFeeForTx(tx, test.inputStandardRate, test.inputDataRate); satoshis != test.expectedSatoshis {
579+
t.Log("tx size: ", len(tx.ToBytes()))
563580
t.Errorf("%s Failed: [%s] [%v] [%v] inputted [%d] expected but got: %d", t.Name(), test.inputHex, test.inputStandardRate, test.inputDataRate, test.expectedSatoshis, satoshis)
564581
} else if tx.GetTxID() != test.expectedTxID {
565582
t.Errorf("%s Failed: [%s] [%v] [%v] inputted [%s] expected but got: %s", t.Name(), test.inputHex, test.inputStandardRate, test.inputDataRate, test.expectedTxID, tx.GetTxID())
@@ -676,7 +693,7 @@ func TestCreateTxWithChange(t *testing.T) {
676693

677694
// Expected
678695
expectedFee := uint64(149)
679-
expectedChange := uint64(352)
696+
expectedChange := uint64(351)
680697

681698
// Test the right fee
682699
fee := CalculateFeeForTx(rawTx, nil, nil)
@@ -726,7 +743,7 @@ func TestCreateTxWithChangeErrors(t *testing.T) {
726743
"1KQG5AY9GrPt3b5xrFqVh2C3YEhzSdu4kc",
727744
nil,
728745
nil,
729-
"0100000001760595866e99c1ce920197844740f5598b34763878696371d41b3a7c0a65b0b7000000006a4730440220767b6b7483746c1b07e8f58dd953bdc9ade3696036fe093cc404660704d7b407022063858090101d990568af473834d63372c9d31cb678733f9e50a62b2f047c2aa5412102ea87d1fd77d169bd56a71e700628113d0f8dfe57faa0ba0e55a36f9ce8e10be3ffffffff03f4010000000000001976a9147a1980655efbfec416b2b0c663a7b3ac0b6a25d288ac72010000000000001976a914c9d8699bdea34b131e737447b50a8b1af0b040bf88ac00000000000000001a006a07707265666978310c6578616d706c65206461746102133700000000",
746+
"0100000001760595866e99c1ce920197844740f5598b34763878696371d41b3a7c0a65b0b7000000006b483045022100b95aff403574aba31b1786e5f5ddb3c57356a13e6207b66babb16a6d851d7cfe02200d0f570f619e4c05b5b7213ce673f46549f9a7ee95814f3ec0cc0233fd54c85e412102ea87d1fd77d169bd56a71e700628113d0f8dfe57faa0ba0e55a36f9ce8e10be3ffffffff03f4010000000000001976a9147a1980655efbfec416b2b0c663a7b3ac0b6a25d288ac71010000000000001976a914c9d8699bdea34b131e737447b50a8b1af0b040bf88ac00000000000000001a006a07707265666978310c6578616d706c65206461746102133700000000",
730747
false,
731748
false,
732749
},
@@ -774,7 +791,7 @@ func TestCreateTxWithChangeErrors(t *testing.T) {
774791
"1KQG5AY9GrPt3b5xrFqVh2C3YEhzSdu4kc",
775792
nil,
776793
nil,
777-
"0100000001760595866e99c1ce920197844740f5598b34763878696371d41b3a7c0a65b0b7000000006a47304402203fa8a408ef7b523a7efab01e0016d4e4879b3e9a56418691cd441344e326fd2c022066997fde9d357a83dec6fc80722089f740f393d6ef949f966f6739da44282f44412102ea87d1fd77d169bd56a71e700628113d0f8dfe57faa0ba0e55a36f9ce8e10be3ffffffff0278030000000000001976a914c9d8699bdea34b131e737447b50a8b1af0b040bf88ac00000000000000001a006a07707265666978310c6578616d706c65206461746102133700000000",
794+
"0100000001760595866e99c1ce920197844740f5598b34763878696371d41b3a7c0a65b0b7000000006b48304502210092b9d4a913d7103e8770bdeb45528b6aed02126fafdfc64c728243714eac250002205fa4963a90fd69f6ae4cbf02c2ecc2367d585eb616244fb7c85adf4fef468a21412102ea87d1fd77d169bd56a71e700628113d0f8dfe57faa0ba0e55a36f9ce8e10be3ffffffff0277030000000000001976a914c9d8699bdea34b131e737447b50a8b1af0b040bf88ac00000000000000001a006a07707265666978310c6578616d706c65206461746102133700000000",
778795
false,
779796
false,
780797
},
@@ -789,7 +806,7 @@ func TestCreateTxWithChangeErrors(t *testing.T) {
789806
"1KQG5AY9GrPt3b5xrFqVh2C3YEhzSdu4kc",
790807
nil,
791808
nil,
792-
"0100000001760595866e99c1ce920197844740f5598b34763878696371d41b3a7c0a65b0b7000000006a4730440220143c042ecbdb9296d84a87155dcaf558b657be627ab54ffe464028c050cf0da902205117bd7aa2f85d3cd2f98b504a52599e2ea69ea6afb6a640637c12ddcef8c2f0412102ea87d1fd77d169bd56a71e700628113d0f8dfe57faa0ba0e55a36f9ce8e10be3ffffffff0188030000000000001976a914c9d8699bdea34b131e737447b50a8b1af0b040bf88ac00000000",
809+
"0100000001760595866e99c1ce920197844740f5598b34763878696371d41b3a7c0a65b0b7000000006a4730440220029595a3bc3e94f92b1d08faf298ba938cb7c9824393789a1f3afc5ea5e172a802204d224492ab440c8180b45f39a25e270b0fb0d2fc74d8362db52e3ff960d9dc5d412102ea87d1fd77d169bd56a71e700628113d0f8dfe57faa0ba0e55a36f9ce8e10be3ffffffff0187030000000000001976a914c9d8699bdea34b131e737447b50a8b1af0b040bf88ac00000000",
793810
false,
794811
false,
795812
},
@@ -957,7 +974,7 @@ func ExampleCreateTxWithChange() {
957974
}
958975

959976
fmt.Printf("rawTx: %s", rawTx.ToString())
960-
// Output:rawTx: 0100000001760595866e99c1ce920197844740f5598b34763878696371d41b3a7c0a65b0b7000000006b483045022100beab95997a8b4b0e805aa16af1fed54a0ff80d6e45a330f71787795c394ff99d02207904b4930ccf4dae9e87d1f4b18be343f2fd73bb5500870d7194726919b5f6d8412102ea87d1fd77d169bd56a71e700628113d0f8dfe57faa0ba0e55a36f9ce8e10be3ffffffff04f4010000000000001976a9147a1980655efbfec416b2b0c663a7b3ac0b6a25d288ac60010000000000001976a914c9d8699bdea34b131e737447b50a8b1af0b040bf88ac00000000000000001a006a07707265666978310c6578616d706c65206461746102133700000000000000001c006a0770726566697832116d6f7265206578616d706c65206461746100000000
977+
// Output:rawTx: 0100000001760595866e99c1ce920197844740f5598b34763878696371d41b3a7c0a65b0b7000000006b483045022100c1dc4a4c5f26a404ff3618013dc63777d0790d0b0ea3371c67ee3f1bb5126c3e02206be8c841918215337f9b6a6a6040bd058596f2bab5c8b8cb27f849b1474b9e4c412102ea87d1fd77d169bd56a71e700628113d0f8dfe57faa0ba0e55a36f9ce8e10be3ffffffff04f4010000000000001976a9147a1980655efbfec416b2b0c663a7b3ac0b6a25d288ac5f010000000000001976a914c9d8699bdea34b131e737447b50a8b1af0b040bf88ac00000000000000001a006a07707265666978310c6578616d706c65206461746102133700000000000000001c006a0770726566697832116d6f7265206578616d706c65206461746100000000
961978
}
962979

963980
// BenchmarkCreateTxWithChange benchmarks the method CreateTxWithChange()
@@ -1028,7 +1045,7 @@ func TestCreateTxWithChangeUsingWif(t *testing.T) {
10281045

10291046
// Expected
10301047
expectedFee := uint64(149)
1031-
expectedChange := uint64(352)
1048+
expectedChange := uint64(351)
10321049

10331050
// Test the right fee
10341051
fee := CalculateFeeForTx(rawTx, nil, nil)
@@ -1097,7 +1114,7 @@ func ExampleCreateTxWithChangeUsingWif() {
10971114
}
10981115

10991116
fmt.Printf("rawTx: %s", rawTx.ToString())
1100-
// Output:rawTx: 0100000001760595866e99c1ce920197844740f5598b34763878696371d41b3a7c0a65b0b7000000006b483045022100beab95997a8b4b0e805aa16af1fed54a0ff80d6e45a330f71787795c394ff99d02207904b4930ccf4dae9e87d1f4b18be343f2fd73bb5500870d7194726919b5f6d8412102ea87d1fd77d169bd56a71e700628113d0f8dfe57faa0ba0e55a36f9ce8e10be3ffffffff04f4010000000000001976a9147a1980655efbfec416b2b0c663a7b3ac0b6a25d288ac60010000000000001976a914c9d8699bdea34b131e737447b50a8b1af0b040bf88ac00000000000000001a006a07707265666978310c6578616d706c65206461746102133700000000000000001c006a0770726566697832116d6f7265206578616d706c65206461746100000000
1117+
// Output:rawTx: 0100000001760595866e99c1ce920197844740f5598b34763878696371d41b3a7c0a65b0b7000000006b483045022100c1dc4a4c5f26a404ff3618013dc63777d0790d0b0ea3371c67ee3f1bb5126c3e02206be8c841918215337f9b6a6a6040bd058596f2bab5c8b8cb27f849b1474b9e4c412102ea87d1fd77d169bd56a71e700628113d0f8dfe57faa0ba0e55a36f9ce8e10be3ffffffff04f4010000000000001976a9147a1980655efbfec416b2b0c663a7b3ac0b6a25d288ac5f010000000000001976a914c9d8699bdea34b131e737447b50a8b1af0b040bf88ac00000000000000001a006a07707265666978310c6578616d706c65206461746102133700000000000000001c006a0770726566697832116d6f7265206578616d706c65206461746100000000
11011118
}
11021119

11031120
// BenchmarkCreateTxWithChangeUsingWif benchmarks the method CreateTxWithChangeUsingWif()

verify.go

+24-10
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,31 @@ import (
99
"github.com/bitcoinsv/bsvd/bsvec"
1010
"github.com/bitcoinsv/bsvd/chaincfg/chainhash"
1111
"github.com/bitcoinsv/bsvd/wire"
12+
"github.com/bitcoinsv/bsvutil"
1213
)
1314

1415
const (
15-
// H_BSV is the magic header string required fore Bitcoin Signed Messages
16+
// hBSV is the magic header string required fore Bitcoin Signed Messages
1617
hBSV string = "Bitcoin Signed Message:\n"
1718
)
1819

19-
// PublicKeyFromSignature gets a publickey for a signature and tells you whether is was compressed
20+
// PubKeyFromSignature gets a publickey for a signature and tells you whether is was compressed
2021
func PubKeyFromSignature(sig, data string) (pubKey *bsvec.PublicKey, wasCompressed bool, err error) {
21-
decodedSig, err := base64.StdEncoding.DecodeString(sig)
22-
if err != nil {
22+
23+
var decodedSig []byte
24+
if decodedSig, err = base64.StdEncoding.DecodeString(sig); err != nil {
2325
return nil, false, err
2426
}
2527

26-
// Validate the signature - this just shows that it was valid at all.
27-
// we will compare it with the key next.
28+
// Validate the signature - this just shows that it was valid at all
29+
// we will compare it with the key next
2830
var buf bytes.Buffer
29-
wire.WriteVarString(&buf, 0, hBSV)
30-
wire.WriteVarString(&buf, 0, data)
31+
if err = wire.WriteVarString(&buf, 0, hBSV); err != nil {
32+
return nil, false, err
33+
}
34+
if err = wire.WriteVarString(&buf, 0, data); err != nil {
35+
return nil, false, err
36+
}
3137

3238
// Create the hash
3339
expectedMessageHash := chainhash.DoubleHashB(buf.Bytes())
@@ -48,13 +54,21 @@ func VerifyMessage(address, sig, data string) error {
4854
}
4955

5056
// Get the address
51-
bsvecAddress, err := GetAddressFromPubKey(publicKey, wasCompressed)
57+
var bsvecAddress *bsvutil.LegacyAddressPubKeyHash
58+
if bsvecAddress, err = GetAddressFromPubKey(publicKey, wasCompressed); err != nil {
59+
return err
60+
}
5261

5362
// Return nil if addresses match.
5463
if bsvecAddress.String() == address {
5564
return nil
5665
}
57-
return fmt.Errorf("Address (%s) not found. Was compressed: %t\n%s was found instead", address, wasCompressed, bsvecAddress.EncodeAddress())
66+
return fmt.Errorf(
67+
"address (%s) not found - compressed: %t\n%s was found instead",
68+
address,
69+
wasCompressed,
70+
bsvecAddress.EncodeAddress(),
71+
)
5872
}
5973

6074
// VerifyMessageDER will take a message string, a public key string and a signature string

0 commit comments

Comments
 (0)