Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitcoin Cash Support #37

Merged
merged 4 commits into from Jan 19, 2018
Merged

Bitcoin Cash Support #37

merged 4 commits into from Jan 19, 2018

Conversation

DesWurstes
Copy link
Contributor

@DesWurstes DesWurstes commented Nov 4, 2017

Ready To Be Merged

The first Bitcoin Cash atomic swap has been made!

To test both participate and initiate, the atomic swap was made as BCC-><-BCC.
Proof at the end of this Pull Request.

To do:

Proof:

Secret:      1c219f5aa297cd6e43370af03139c18b616c5b951489110486fe2a8774b1f357
Secret hash: d179b059810d3a92f2034b3a7eda48793ac79c28

Contract fee: 0.00000224 BTC (0.00001000 BTC/kB)
Refund fee:   0.00000281 BTC (0.00001022 BTC/kB)

Contract (3KSmcFRuunMcTNN1bGdCdmNkt6S8VSPq8k):
63a614d179b059810d3a92f2034b3a7eda48793ac79c288876a91421cf3314cbb2ffa97d65847ce925c0fd0f12c2aa6704d80c005ab17576a914973d2163109e780cc499dcac0ab40fe0fab63af56888ac

Contract transaction (c46587a8709014cc644bde757a51445c9b829e73a2f08266b84ace09677c61a5):
0200000001e0b3fcb18629bffc29f41f3d97292262843a0d1ed5417df54b697a3cd58e6c04010000006b483045022100a24595c0797cda919ddf191b31cfa237aee7717a14602cb3139f816ed7940bf202200b07df394ead43162a52b043795c97f7c9cb48626068d4acd7166cea1b58dfab4121033c056ade10b36e72402c6cabaf3a144c2766284a5781dbba04969b9866eb720ffeffffff02e80300000000000017a914c2c07da0d1029012de3608322affa8e3d0a0d466875b247504000000001976a91488ced5c06b367d02c8f04b436b063ed49ce0009488ac1ba40700

Refund transaction (f7cc8e512b73d42d19110508fd80d51f1e0bc59c3c371435888ce5c8f521bbf6):
0200000001a5617c6709ce4ab86682f0a2739e829b5c44517a75de4b64cc149070a88765c400000000be47304402205a8cdf92a9d3cb54261100f6ee7352d398e25a193cdc132b95e0d2d77f2f7bb0022078de3bf3f7ff77580ec1ef6ad4f774c614252330e10091c0e07ac89b8107c7ce412103e31e1b29ef35cd226fee063be70d5f7b69e176a28c146acadbd5c11d0e43af2c004c5163a614d179b059810d3a92f2034b3a7eda48793ac79c288876a91421cf3314cbb2ffa97d65847ce925c0fd0f12c2aa6704d80c005ab17576a914973d2163109e780cc499dcac0ab40fe0fab63af56888ac0000000001cf020000000000001976a914e768d7ee85153d2fec57c002b60af7382ab87b6188acd80c005a

Publish contract transaction? [y/N] y
Published contract transaction (c46587a8709014cc644bde757a51445c9b829e73a2f08266b84ace09677c61a5)

Contract fee: 0.00000224 BTC (0.00001000 BTC/kB)
Refund fee:   0.00000281 BTC (0.00001022 BTC/kB)

Contract (3A7ZYY5SJiyZSA4wnpNEEprw75FA1dyEjm):
63a614d179b059810d3a92f2034b3a7eda48793ac79c288876a9149768e0f2b709a9b27410f299e8667eca7c907af76704bbbbfe59b17576a9144e5f167449bf4724b250eace368eeb347a05b79e6888ac

Contract transaction (5e1b408d005eef911c4bc9389d34a74572b271be794eaf51bd1ca978a923e3c2):
0200000001c10dbe9bf2237ef7b7676a30e6c4ef3223cef140163b25d927eb1116f1f01aca010000006b483045022100dc4c9af4adf9a38942875f96d9a357cd1275eb55e407f063e3807bd764b98079022008912d4340c0695fad6ca8f8b2fd83f88093fc1d53771cd651d7750902da1677412103a43b74d633b3c79e11f6aeeb3d1f1a45c43d4797378f39b4042801ffcb62a6aafeffffff02ee30ea0b000000001976a9144ce1bb1e060dbc4349d88f1cc99c379ea8995f7b88ace80300000000000017a9145c65628708065321444c8694e1a1b7f8db96d552871ba40700

Refund transaction (17646ba9d97939fa60a1bb46ba0496cab4661f95a52a4c3310eff895dd07d22e):
0200000001c2e323a978a91cbd51af4e79be71b27245a7349d38c94b1c91ef5e008d401b5e01000000be4730440220488c34d78d7aa3e15861835dd7b6c67f855f22a4f4917795c2e8c769030012720220038debd969c89c9d54b63b1d71157e11db916205e11e68e7da6039dcac02ccce41210323e5109c2db44697ce71c917f4506a10d82b193727bbd079858dc8fc894a7697004c5163a614d179b059810d3a92f2034b3a7eda48793ac79c288876a9149768e0f2b709a9b27410f299e8667eca7c907af76704bbbbfe59b17576a9144e5f167449bf4724b250eace368eeb347a05b79e6888ac0000000001cf020000000000001976a914815f0ac0ea87a60768028d20454f2d8ce9a005d288acbbbbfe59

DesWurstes:atomicswap DesWurstes$ /Users/DesWurstes/go/bin/btcatomicswap --rpcuser=bitcoinrpc --rpcpass=6lOxOOOPSGxyTKs66aql7x6vK redeem 63a614d179b059810d3a92f2034b3a7eda48793ac79c288876a9149768e0f2b709a9b27410f299e8667eca7c907af76704bbbbfe59b17576a9144e5f167449bf4724b250eace368eeb347a05b79e6888ac 0200000001c10dbe9bf2237ef7b7676a30e6c4ef3223cef140163b25d927eb1116f1f01aca010000006b483045022100dc4c9af4adf9a38942875f96d9a357cd1275eb55e407f063e3807bd764b98079022008912d4340c0695fad6ca8f8b2fd83f88093fc1d53771cd651d7750902da1677412103a43b74d633b3c79e11f6aeeb3d1f1a45c43d4797378f39b4042801ffcb62a6aafeffffff02ee30ea0b000000001976a9144ce1bb1e060dbc4349d88f1cc99c379ea8995f7b88ace80300000000000017a9145c65628708065321444c8694e1a1b7f8db96d552871ba40700 1c219f5aa297cd6e43370af03139c18b616c5b951489110486fe2a8774b1f357
Redeem fee: 0.00000314 BTC (0.00001019 BTC/kB)

Redeem transaction (dc1b1f11ef09041a78240c02e019f9867773dd39367dbe489c7be09a47baa28c):
0200000001c2e323a978a91cbd51af4e79be71b27245a7349d38c94b1c91ef5e008d401b5e01000000df473044022023a93c83e7b7cea3850c13de67670fca150345ee80c5a95367fdf0d4375d132602207e248b10e581161214ce8024fd732bf8e31351e585cad1389ccda000fd2d7475412103ad161d06f01e4d7c9b2bdb6b5f372492953b1cb6f8656ada567898409f41ee49201c219f5aa297cd6e43370af03139c18b616c5b951489110486fe2a8774b1f357514c5163a614d179b059810d3a92f2034b3a7eda48793ac79c288876a9149768e0f2b709a9b27410f299e8667eca7c907af76704bbbbfe59b17576a9144e5f167449bf4724b250eace368eeb347a05b79e6888acffffffff01ae020000000000001976a914ec5605bc9a6d8f956b59b1a1d8c27028d35bdbe888acbbbbfe59

Publish redeem transaction? [y/N] y
Published redeem transaction (dc1b1f11ef09041a78240c02e019f9867773dd39367dbe489c7be09a47baa28c)

Redeem fee: 0.00000314 BTC (0.00001016 BTC/kB)

Redeem transaction (f08720cf546429c66caf3c4a4ad930c78af98a11fcdd6f53a83d79c86667ce8a):
0200000001a5617c6709ce4ab86682f0a2739e829b5c44517a75de4b64cc149070a88765c400000000e0483045022100d12b8f8b16078816cd3b7f55a9c8d6b3a4bca382e148f0992e7bd2ef6c1ec82902201fda05716a0103bee8589653ac201466480ab513381c27c5dcba26aebb20f92b412103676cff7650b9e234b9ccbc2f49411824edb814d2009abb856e8f94745ee80191201c219f5aa297cd6e43370af03139c18b616c5b951489110486fe2a8774b1f357514c5163a614d179b059810d3a92f2034b3a7eda48793ac79c288876a91421cf3314cbb2ffa97d65847ce925c0fd0f12c2aa6704d80c005ab17576a914973d2163109e780cc499dcac0ab40fe0fab63af56888acffffffff01ae020000000000001976a9146e7c37283828af7148a202570c65f59febb40f0088acd80c005a

Publish redeem transaction? [y/N] y
Published redeem transaction (f08720cf546429c66caf3c4a4ad930c78af98a11fcdd6f53a83d79c86667ce8a)

Another proof that I am MCCCS: "I am MCCCS"

@DesWurstes DesWurstes changed the title Bitcoin Cash Support!!! Bitcoin Cash Support Nov 4, 2017
@gubatron
Copy link

gubatron commented Nov 4, 2017

Investigate whether all of BU, ABC, XT, Classic supports estimatesmartfee

This exists in bitcoinclassic's code, not sure if that means it does support it:

src/txmempool.cpp

CFeeRate CTxMemPool::estimateSmartFee(int nBlocks, int *answerFoundAtBlocks) const
{
    LOCK(cs);
    return minerPolicyEstimator->estimateSmartFee(nBlocks, answerFoundAtBlocks, *this);
}

@DesWurstes
Copy link
Contributor Author

DesWurstes commented Nov 5, 2017

Unfortunately Bitcoin XT supports fundrawtransaction 0% while Bitcoin ABC supports it 100%.

Bitcoin Classic and Unlimited don't allow the fees to be passed, which may be a problem only if fees rise.

@dgenr8
Copy link

dgenr8 commented Nov 6, 2017

Just make it great. XT will cherry-pick fundrawtransaction from core.

Copy link
Member

@jrick jrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for picking up the ball with this. just have some small suggestions about naming


var (
flagset = flag.NewFlagSet("", flag.ExitOnError)
connectFlag = flagset.String("s", "localhost", "host[:port] of Bitcoin Core wallet RPC server")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

references bitcoin core


// There are two directions that the atomic swap can be performed, as the
// initiator can be on either chain. This tool only deals with creating the
// Bitcoin transactions for these swaps. A second tool should be used for the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

references bitcoin


func init() {
flagset.Usage = func() {
fmt.Println("Usage: btcatomicswap [flags] cmd [cmd args]")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bccatomicswap (also why is it bccatomicswap and not bchatomicswap?)


// createSig creates and returns the serialized raw signature and compressed
// pubkey for a transaction input signature. Due to limitations of the Bitcoin
// Core RPC API, this requires dumping a private key and signing in the client,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

references bitcoin core

return fundTransactionViaRPC(rawResp)
}

func fundTransactionViaRPC(rawResp json.RawMessage) (fundedTx *wire.MsgTx, fee btcutil.Amount, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function name is sort of weird, since the other func above this one is the one actually doing the RPC, and this is just working with a json object.


fmt.Printf("Secret: %x\n", secret)
fmt.Printf("Secret hash: %x\n\n", secretHash)
fmt.Printf("Contract fee: %v (%0.8f BTC/kB)\n", b.contractFee, contractFeePerKb)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

references bitcoin

contractFeePerKb := calcFeePerKb(b.contractFee, b.contractTx.SerializeSize())
refundFeePerKb := calcFeePerKb(b.refundFee, b.refundTx.SerializeSize())

fmt.Printf("Contract fee: %v (%0.8f BTC/kB)\n", b.contractFee, contractFeePerKb)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

references bitcoin

var buf bytes.Buffer
buf.Grow(redeemTx.SerializeSize())
redeemTx.Serialize(&buf)
fmt.Printf("Redeem fee: %v (%0.8f BTC/kB)\n\n", fee, redeemFeePerKb)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

references bitcoin


refundFeePerKb := calcFeePerKb(refundFee, refundTx.SerializeSize())

fmt.Printf("Refund fee: %v (%0.8f BTC/kB)\n\n", refundFee, refundFeePerKb)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

references bitcoin

}

fmt.Printf("Contract address: %v\n", contractAddr)
fmt.Printf("Contract value: %v\n", btcutil.Amount(cmd.contractTx.TxOut[contractOut].Value))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will also reference bitcoin since the amount will be formatted with BTC at the end using the default string conversion

@DesWurstes
Copy link
Contributor Author

DesWurstes commented Nov 14, 2017

It works. HF hasn't broken it.


@jrick One last question: Can this be used to mix coins trustlessly (and privately from others)?


Ready To Be Merged!

@jrick
Copy link
Member

jrick commented Nov 14, 2017

no on that last question, you can passively observe both chains and see the swap due to the shared secret once it is revealed by both redeeming parties.

@jrick
Copy link
Member

jrick commented Nov 27, 2017

I'll try to give this another look soon, but it will need to be switched over to use OP_SHA256 instead of OP_RIPEMD160 since we just converted the rest of the tools. See 4c8c7c0 for how to make this change.

@DesWurstes
Copy link
Contributor Author

DesWurstes commented Nov 28, 2017

Should I add the new Bitcoin Cash Bech32 address format, or is it too early (14 Jan, planned by Amaury)?


Was your sha256 commit tested? Now this line throws an error:

https://github.com/DesWurstes/atomicswap/blob/BitcoinCash/cmd/bchatomicswap/main.go#L700

because pushes is nil.

@jrick
Copy link
Member

jrick commented Nov 28, 2017

Ugh you're right, it needs updates for txscript as well or else it fails to parse the script as an atomic swap script. Had that sitting in my tree and didn't make those necessary changes first.

I'm going to revert the latest commit and put up an issue so that all the maintainers can coordinate, since it will need similar updates to their btcd fork.

Thanks for noticing that and sorry for the waste of time.

@jrick jrick merged commit 7912904 into decred:master Jan 19, 2018
@DesWurstes DesWurstes deleted the BitcoinCash branch January 19, 2018 15:09
@jrick jrick moved this from Under review to Completed in Additional cryptocurrency interop support Jan 19, 2018
bitbandi pushed a commit to bitbandi/atomicswap that referenced this pull request Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants