Skip to content

Commit 0169cf9

Browse files
Add C++ protobuf generated code.
1 parent e65ee85 commit 0169cf9

File tree

10 files changed

+77939
-10
lines changed

10 files changed

+77939
-10
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ all: prepare tools run-generate format test
1717
run-win: prepare-win tools run-generate format-win
1818

1919
protobuf:
20-
protoc --proto_path=dist/protobuf --go_opt=paths=source_relative --go_out=dist/golang/actions --js_out=library=actions,binary:dist/typescript/protobuf/actions --python_out=dist/python/ dist/protobuf/actions.proto
21-
protoc --proto_path=dist/protobuf --go_opt=paths=source_relative --go_out=dist/golang/instruments --js_out=library=instruments,binary:dist/typescript/protobuf/instruments --python_out=dist/python/ dist/protobuf/instruments.proto
22-
protoc --proto_path=dist/protobuf --go_opt=paths=source_relative --go_out=dist/golang/messages --js_out=library=messages,binary:dist/typescript/protobuf/messages --python_out=dist/python/ dist/protobuf/messages.proto
20+
protoc --proto_path=dist/protobuf --go_opt=paths=source_relative --go_out=dist/golang/actions --js_out=library=actions,binary:dist/typescript/protobuf/actions --python_out=dist/python/ --cpp_out=dist/c++/actions dist/protobuf/actions.proto
21+
protoc --proto_path=dist/protobuf --go_opt=paths=source_relative --go_out=dist/golang/instruments --js_out=library=instruments,binary:dist/typescript/protobuf/instruments --python_out=dist/python/ --cpp_out=dist/c++/instruments dist/protobuf/instruments.proto
22+
protoc --proto_path=dist/protobuf --go_opt=paths=source_relative --go_out=dist/golang/messages --js_out=library=messages,binary:dist/typescript/protobuf/messages --python_out=dist/python/ --cpp_out=dist/c++/messages dist/protobuf/messages.proto
2323

2424
generate-code:
2525
go run internal/cmd/generate/main.go

dist/c++/actions/actions.pb.cc

Lines changed: 18684 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/c++/actions/actions.pb.h

Lines changed: 26098 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/c++/instruments/instruments.pb.cc

Lines changed: 6101 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/c++/instruments/instruments.pb.h

Lines changed: 8338 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/c++/messages/messages.pb.cc

Lines changed: 8137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/c++/messages/messages.pb.h

Lines changed: 10453 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/golang/protocol/fee_test.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,3 +1008,121 @@ func Test_EstimatedConfiscationResponse(t *testing.T) {
10081008
t.Logf("Verified Estimated Response Funding : got %d, want %d", funding,
10091009
responseFee+outputValue)
10101010
}
1011+
1012+
func Test_TransferResponseFees_Example1(t *testing.T) {
1013+
contractFees := []uint64{2000}
1014+
feeRate := float32(0.05)
1015+
dustFeeRate := float32(0.0)
1016+
1017+
h := "006a02bd015108746573742e544b4e5301000254314d12010a850212034343591a14a451388d80b00661b4b90cfe103ee7ec615f0994220210412a710a152055e69778997556277d03d42794a91ebb41493a2d103218012a463044022032c6a3043487bc35aa44acb64f0945d6024fab2de3d63cc8e8389420a2fdbec5022023897ffe30cb511f493056a6bd49a9e0d4e9b27d537046ae02222084e3ec8f1330bca2313889beb7feecad82c1172a710a1520449c2b9f4500c765ee0eac4b9fdc62d5c2561829100f18012a46304402204c1952abf8fff745723166321c71193af10a86e1c138cb5ae548936fa607da640220708d7e9db541c07d694fcbde588f97a25d53266a1d925f7f3c4c0f678260fe2730bca23138ffd4b6afedad82c11710d38bc6eeb5be8cc017"
1018+
1019+
b, err := hex.DecodeString(h)
1020+
if err != nil {
1021+
t.Fatalf("Failed to parse transfer hex : %s", err)
1022+
}
1023+
1024+
action, err := Deserialize(b, true)
1025+
if err != nil {
1026+
t.Fatalf("Failed to deserialize transfer : %s", err)
1027+
}
1028+
1029+
transfer := action.(*actions.Transfer)
1030+
js, _ := json.MarshalIndent(transfer, "", " ")
1031+
t.Logf("Transfer : %s", js)
1032+
1033+
requestTx := wire.NewMsgTx(1)
1034+
1035+
var lockingScripts []bitcoin.Script
1036+
for i := 0; i < 2; i++ {
1037+
key, _ := bitcoin.GenerateKey(bitcoin.TestNet)
1038+
script, _ := key.LockingScript()
1039+
lockingScripts = append(lockingScripts, script)
1040+
1041+
var randHash bitcoin.Hash32
1042+
rand.Read(randHash[:])
1043+
requestTx.AddTxIn(wire.NewTxIn(wire.NewOutPoint(&randHash, 1), nil))
1044+
}
1045+
1046+
key, _ := bitcoin.GenerateKey(bitcoin.TestNet)
1047+
script, _ := key.LockingScript()
1048+
requestTx.AddTxOut(wire.NewTxOut(2021, script))
1049+
1050+
requestTx.AddTxOut(wire.NewTxOut(0, b))
1051+
1052+
key, _ = bitcoin.GenerateKey(bitcoin.TestNet)
1053+
script, _ = key.LockingScript()
1054+
requestTx.AddTxOut(wire.NewTxOut(187, script))
1055+
1056+
// Estimate funding
1057+
funding, boomerang, err := EstimatedTransferResponse(requestTx, lockingScripts, feeRate,
1058+
dustFeeRate, contractFees, true)
1059+
1060+
if err != nil {
1061+
t.Fatalf("Failed to estimate response : %s", err)
1062+
}
1063+
1064+
t.Logf("Funding : %v", funding)
1065+
t.Logf("Boomerang : %d", boomerang)
1066+
1067+
if len(funding) < 1 {
1068+
t.Fatalf("No contract funding returned")
1069+
}
1070+
1071+
// From response 522efbe6014b5bf740c48db0b7790d6f3a9203de06ecad1d67abeb01d1281aff
1072+
if funding[0] < 2022 {
1073+
t.Errorf("Not enough contract funding : got %d, want %d", funding[0], 2022)
1074+
}
1075+
1076+
if boomerang > 0 {
1077+
t.Errorf("Not enough boomerang : got %d, want %d", boomerang, 0)
1078+
}
1079+
}
1080+
1081+
func Test_TransferResponseFees_Example2(t *testing.T) {
1082+
contractFees := []uint64{2000, 2000}
1083+
feeRate := float32(0.05)
1084+
dustFeeRate := float32(0.0)
1085+
1086+
h := "010000000215664abb2cbc7db1d1d3b8ed8ed985fcfaed062ce0318f11aeab87dc645bec65010000006a47304402206792e2b1bb0fd2c0c31ab4ece1ab60d1057be2de1e984b9ccf385458fe9bb09802207823e56eefbea591b60f4fd816a59f2f120128162b548b760e06f0fe6deb6dca412103b8fe59c51966f28f8267ef5c43e638abe2721308eefae9677770f258eb95eba4ffffffff164fb009edd8681f2464d8b2bf7af0a3813819c0e1e974208f3fd8afa3baa08d010000006b483045022100c38f5c4d3da12333c72d565c34ef9c5b719db7d4df4ce6fc61ab6ffb8f44b5ea022047c7ef850d54c20c95b9a74ec966c46425a6987639e5c06a1c910b8dc0805871412103e52b04d4eafb375a6aee21ade32591fbac969976a43559225cadf7a3af25aa2dffffffff03e5070000000000001976a914b082b8cce2697aaaacfa698f1950e44e0ba1175c88ac0000000000000000fd2a01006a02bd015108746573742e544b4e5301000254314d12010a850212034343591a14a451388d80b00661b4b90cfe103ee7ec615f0994220210412a710a152055e69778997556277d03d42794a91ebb41493a2d103218012a463044022032c6a3043487bc35aa44acb64f0945d6024fab2de3d63cc8e8389420a2fdbec5022023897ffe30cb511f493056a6bd49a9e0d4e9b27d537046ae02222084e3ec8f1330bca2313889beb7feecad82c1172a710a1520449c2b9f4500c765ee0eac4b9fdc62d5c2561829100f18012a46304402204c1952abf8fff745723166321c71193af10a86e1c138cb5ae548936fa607da640220708d7e9db541c07d694fcbde588f97a25d53266a1d925f7f3c4c0f678260fe2730bca23138ffd4b6afedad82c11710d38bc6eeb5be8cc017bb000000000000001976a91458d2f37dd57fd7d907b72fc7de6875c79edb184588ac00000000"
1087+
1088+
b, err := hex.DecodeString(h)
1089+
if err != nil {
1090+
t.Fatalf("Failed to parse request tx hex : %s", err)
1091+
}
1092+
1093+
requestTx := &wire.MsgTx{}
1094+
if err := requestTx.Deserialize(bytes.NewReader(b)); err != nil {
1095+
t.Fatalf("Failed to parse request tx : %s", err)
1096+
}
1097+
1098+
key, _ := bitcoin.GenerateKey(bitcoin.TestNet)
1099+
script, _ := key.LockingScript()
1100+
var lockingScripts []bitcoin.Script
1101+
for range requestTx.TxIn {
1102+
lockingScripts = append(lockingScripts, script)
1103+
}
1104+
1105+
// Estimate funding
1106+
funding, boomerang, err := EstimatedTransferResponse(requestTx, lockingScripts, feeRate,
1107+
dustFeeRate, contractFees, true)
1108+
1109+
if err != nil {
1110+
t.Fatalf("Failed to estimate response : %s", err)
1111+
}
1112+
1113+
t.Logf("Funding : %v", funding)
1114+
t.Logf("Boomerang : %d", boomerang)
1115+
1116+
if len(funding) < 1 {
1117+
t.Fatalf("No contract funding returned")
1118+
}
1119+
1120+
// From response 522efbe6014b5bf740c48db0b7790d6f3a9203de06ecad1d67abeb01d1281aff
1121+
if funding[0] < 2022 {
1122+
t.Errorf("Not enough contract funding : got %d, want %d", funding[0], 2022)
1123+
}
1124+
1125+
if boomerang > 0 {
1126+
t.Errorf("Not enough boomerang : got %d, want %d", boomerang, 0)
1127+
}
1128+
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ require (
1010
github.com/spf13/cobra v0.0.5
1111
github.com/tokenized/bitcoin_interpreter v0.1.1
1212
github.com/tokenized/envelope v1.1.0
13-
github.com/tokenized/pkg v0.7.1-0.20230517150909-d946f2749c68
14-
github.com/tokenized/txbuilder v1.1.0
13+
github.com/tokenized/pkg v0.7.1-0.20230728163803-9a855fa7d049
14+
github.com/tokenized/txbuilder v1.1.1-0.20230816003850-4414c86d5db4
1515
golang.org/x/crypto v0.8.0
16+
google.golang.org/protobuf v1.23.0
1617
gopkg.in/yaml.v2 v2.2.8
1718
)
1819

@@ -29,5 +30,4 @@ require (
2930
github.com/tokenized/logger v0.1.3 // indirect
3031
github.com/tokenized/threads v0.1.2 // indirect
3132
github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564 // indirect
32-
google.golang.org/protobuf v1.23.0 // indirect
3333
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ github.com/tokenized/envelope v1.1.0/go.mod h1:9+0tL1NKJQNnFRjGhaHCIWG9K6QQnh8Hq
107107
github.com/tokenized/logger v0.1.3 h1:Vq/2jEgqyDfjJPgoMo773/bn7ZUow8EWSAY8+gFdTQI=
108108
github.com/tokenized/logger v0.1.3/go.mod h1:bA5PfUEFwtUy0yEIIq4Q3ZwBk1kIZTkYIRASq3fPw+k=
109109
github.com/tokenized/pkg v0.6.0/go.mod h1:reIXdZflcfFbuX1RvX90yAjlYVJaUiYDc5CWJ6qCQww=
110-
github.com/tokenized/pkg v0.7.1-0.20230517150909-d946f2749c68 h1:i5UJrMADBStNmMf62ESGvGYjNCm9zU7wH12tMaqkhJU=
111-
github.com/tokenized/pkg v0.7.1-0.20230517150909-d946f2749c68/go.mod h1:c1xkP+9ON6kwoMQB9LMpy34YcqUwqNXjPMlltYTYZIc=
110+
github.com/tokenized/pkg v0.7.1-0.20230728163803-9a855fa7d049 h1:cNXsk+4QXccHleAiHCP+Zjh046bmJCXB0tkBNWdewzQ=
111+
github.com/tokenized/pkg v0.7.1-0.20230728163803-9a855fa7d049/go.mod h1:c1xkP+9ON6kwoMQB9LMpy34YcqUwqNXjPMlltYTYZIc=
112112
github.com/tokenized/threads v0.1.2 h1:olWOi2kZ4GLX4XmRbgHJzMbaTxp7CKMdiMbHJjKZaRQ=
113113
github.com/tokenized/threads v0.1.2/go.mod h1:+/44KAYA6wqU+AC743pLGBgzkD06IB9+piOOE8BkGK0=
114-
github.com/tokenized/txbuilder v1.1.0 h1:vizRFrdS6VX++OjEcbWykizW1k7EyM4R4ZTEp4Ji26s=
115-
github.com/tokenized/txbuilder v1.1.0/go.mod h1:6KD6YXi2QrIaU83ONQ+WL0GDLjIJ6CTcwc6ZWcJ4N1s=
114+
github.com/tokenized/txbuilder v1.1.1-0.20230816003850-4414c86d5db4 h1:Hfmq18q1hiBTEveUeR9sWB3zihbCVfHDAuXU0vE41z0=
115+
github.com/tokenized/txbuilder v1.1.1-0.20230816003850-4414c86d5db4/go.mod h1:69p7ygkfrsyCHaKTCXrClVxDV1IVKLWehtOX3GnTgv0=
116116
github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564 h1:NXXyQVeRVLK8Xu27/hkkjwVOZLk5v4ZBEvvMtqMqznM=
117117
github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564/go.mod h1:0/YuQQF676+d4CMNclTqGUam1EDwz0B8o03K9pQqA3c=
118118
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=

0 commit comments

Comments
 (0)