Open dan-da opened 6 years ago
Hehe, I was write a parser for coinparams also at one point ;) sick of having to go looking for those!
It's actually why I'd really like to remove other networks parameters from this library. One person needing newer address versions would cause a BC break for everyone else. Having a separate package for that is a nice way to achieve it.
Re directly integrating it, I generally try to keep the core library abstract enough so bridges can happen without always having to submit code to this repo. eg, the zcash and bcash extensions.
Maybe I could suggest we publish those as (eg) coinparams-bitwasp-addon
which is tagged along with a bitcoin-php release? Also - there have been 35 releases due to BC breaks, so having it somewhere we can both tag from would be great!
Maybe I could suggest we publish those as (eg) coinparams-bitwasp-addon which is tagged along with a bitcoin-php release? Also - there have been 35 releases due to BC breaks, so having it somewhere we can both tag from would be great!
yeah that sounds good. I can make that project tomorrow if you like and give you commit access. Or if you want to make it that's fine too.
@afk11 Hi, I created coinparams-bitwasp-addon as you suggested. Please have a look and let me know what you think. You should be able to push commits or tags if you need to.
A few things worth pointing out:
In coinparams.json and in MultiCoinRegistry class I'm using the convention x,y,z and Y,Z to indicate different extended key types. I guess this is kinda sorta standard, but not really. Also I invented X to indicate p2sh/p2pkh in MultiCoinRegistry which is kinda gross. Let me know if you have a better idea.
The coinparams json currently uses the xpub, ypub, and zpub from BTC for altcoins if each one is not already defined. For ypub and zpub, it is only defined for BTC. All such cases of this are flagged in the coinparams json with "undefined_used_btc": true. So in the MultiCoinRegistry class, I defaulted to NOT using the BTC defaults, but provide an option to use them. I'm sort of torn about whether it is ever a good idea to use them for alts, or not. It gets weirder when the alt does define prefixes for x, but then y and z keys look different when defaulted to BTC. any thoughts on this?
LTC is annoying in two ways. 3rd party wallets started using Ltub prefixes and slip132 lists them. But Litecoin-core uses xpub prefixes. So coinparams uses xpub to match official client, but lists an alternate set for Ltub. Either can be accessed via 'alternate' option to MultiCoinRegistry. examples/bip39.php shows this.
The other thing is that litecoin-core has 2 scripthash prefixes. The second is more recent. coinparams.json includes scripthash and scripthash2. MultiCoinNetwork chooses scripthash2 if present. This can be easily overridden by a child class. Presently documented only in code. We could make it an option.
I copied over some examples from bitcoin-php and modified them. Please try them out and let me know if you see anything wrong. Maybe also we can figure out a way to not have duplicate examples in both codebases, or anyway if you modify them in bitcoin-php please also do so in this addon.
Thank you, You made my day.
Hi, @dan-da, sorry it took so long to respond to this PR! I've reviewed the adapter, and like how it's turning out! I've given the examples a look also and don't see anything major out of place
I did see a PHP notice while running the bip39 example - I'm running 7.2, which maybe is more strict about nonexistent keys?
PHP Notice: Undefined index: Ypub in /home/tk/git/coinparams-bitwasp-addon/src/MultiCoinRegistry.php on line 89
PHP Notice: Undefined index: Ypub in /home/tk/git/coinparams-bitwasp-addon/src/MultiCoinRegistry.php on line 90
PHP Notice: Undefined index: zpub in /home/tk/git/coinparams-bitwasp-addon/src/MultiCoinRegistry.php on line 89
PHP Notice: Undefined index: zpub in /home/tk/git/coinparams-bitwasp-addon/src/MultiCoinRegistry.php on line 90
PHP Notice: Undefined index: Zpub in /home/tk/git/coinparams-bitwasp-addon/src/MultiCoinRegistry.php on line 89
PHP Notice: Undefined index: Zpub in /home/tk/git/coinparams-bitwasp-addon/src/MultiCoinRegistry.php on line 90
regarding here: https://github.com/dan-da/coinparams-bitwasp-addon/blob/master/src/MultiCoinRegistry.php#L90
Also, a heads up about https://github.com/dan-da/coinparams-bitwasp-addon/blob/master/src/MultiCoinRegistry.php#L104 and https://github.com/dan-da/coinparams-bitwasp-addon/blob/master/src/MultiCoinRegistry.php#L106 but I think these should actually be multisig (https://github.com/satoshilabs/slips/issues/315)
@dan-da Can you push a new version of dan-da/coinparams-bitwasp-addon ? I see you updated the composer.json in your repo but composer is still using an old one and trying to load bitwasp/bitcoin[v0.0.35.1]
Hello, can you help me how to send bitcoin from wallet 1 to another wallet? Do you have code for this? Thanks
Since bitcoin-php already offers support for several coins and testnets, I thought the library might benefit from integrating coinparams to support hundreds more without manual effort for each.
coinparams is a little project I made to parse github source repos for altcoins and parse out blockchain specific parameters. So far about 340 coins, many with testnet and regtest networks.
Data for all coins is available in coinparams.json, as well as individual json files for each coin.
simple php/composer bindings are available.
I've been using this in a wallet derivation tool, and I created some classes that extend from bitcoin-php Network and PrefixRegistry to support using data from coinparams.json instead of the builtin classes.
There is likely a better/cleaner way, but at least these give an idea of the concept...
FlexNetwork.php NetworkCoinFactory.php MultiCoinRegistry.php