Conversation
|
I believe this is complete now. Still waiting for feedback. Thanks. |
267cf63 to
43eab5a
Compare
|
hey @JoeGruffins sorry I didn't see the PR. I don't provide feedback on altcoins. Test it yourself and make sure it works. |
|
@NicolasDorier Thanks for replying! Gives us hope. We are changing a few things that aren't decred specific to allow decred to work. Please make sure we are not breaking anything and using methods you approve of! For example, whenever we hash a script or pubkey we use blake256 rather than sha256. We are trying to change as little as possible ofc. |
|
Rebasing and squashing and adding more. Please have a brief look though... |
|
Any updates on this? Having Decred on BTCpayserver would help our community use it as a medium of exchange. |
|
Any update on this? Would be a great addition for Decred as Cake Wallet is the go to mobile wallet for the community. |
|
Noticing some interest here, bumping for visibility. |
|
Let's getting done guys. |
|
This needs approval from a maintainer to get merged. @NicolasDorier are you the only maintainer? @JoeGruffins are you able to assign someone to approve it? |
|
Even if maintainer saw this PR and wanted to merge it, he may not be able to, given that it is marked as Draft. Ask the PR submitter to remove draft status first. |
Thanks for responding. @JoeGruffins I'm guessing it's up to you. |
|
We are working on it. We were told somewhere that tests should not be changed. The pr currently does that. Removing those and some more changes still incoming. |
8eeaede to
ae081ea
Compare
|
Altcoins shouldn't have to modify any file in NBitcoin's project, you should just put all your stuff in Especially, you custom hash160 stuff poluting the core code everywhere, there is no way this get merged. |
|
@NicolasDorier thank you for feedback! on it! You don't want the tests right? They are in a separate commit so I can lop them off and just keep it local. |
Add Decred (DCR) as an altcoin to NBitcoin with support for: - Decred transaction serialization (prefix/witness split, expiry, tree) - Block header with stake fields (StakeRoot, VoteBits, Voters, etc.) - Blake256/Blake3 hashing for PoW, checksums, and merkle trees - DCP0005 block header commitments (combined regular+stake merkle root) - DCP0011 ASERT difficulty algorithm with Blake3 PoW - DecredGetInitStateBehavior for P2P handshake - Base58 with Blake256 checksums and WIF private key sig scheme byte - RIPEMD160(Blake256) for Hash160 (address derivation) - Custom RPC handling via ConsensusFactory virtual methods - Proper GetSignatureHash with SigHashNone, SigHashSingle, SigHashAnyOneCanPay support per dcrd spec - Decred-specific RPC response parsing (getbalance, gettxoutsetinfo, getpeerinfo, getrawtransaction, getblock) - Network definitions for mainnet, testnet, and simnet/regtest All Decred-specific code is fully isolated in NBitcoin.Altcoins/Decred.cs. Core NBitcoin changes are limited to altcoin-agnostic extension points: - NetworkStringParser.CreateP2PKH(PubKey, Network) for custom Hash160 - ConsensusFactory RPC virtual methods for altcoin RPC customization - Block.GetMerkleRoot() made virtual - Consensus.GetWorkRequired() hook for custom difficulty algorithms
Add 20 unit tests covering: - Network loading and lookup for mainnet/testnet/regtest - P2PKH and P2SH address parsing (mainnet and testnet) - Address generation and roundtrip on all networks - WIF private key parsing and roundtrip (mainnet and testnet) - Blake256 hash verification (Decred vs Bitcoin address differ) - Genesis block parsing and roundtrip - Block header serialization (180-byte format) - Transaction serialization/deserialization roundtrip - Prefix-only tx hashing verification - ConsensusFactory type checks and RPC properties - Network property validation (ports, factory type)
|
Refactored to isolate all Decred-specific code in NBitcoin.Altcoins/Decred.cs. There are zero if (IsDecred) checks or Decred-specific classes in core now. I looked at Groestlcoin's pattern. It works with zero core changes because Groestlcoin uses standard RIPEMD160(SHA256) for Hash160/address derivation - it only customizes the Base58 checksum hash via the existing Base58CheckEncoder.CalculateHash() virtual. Decred's situation is different: it uses RIPEMD160(Blake256) for address derivation itself, not just the checksum. PubKey.Hash computes the hash with no network context, so by the time NetworkStringParser.CreateP2PKH(KeyId, Network) is called, the KeyId is already wrong. There was no existing extension point to hook into. To avoid threading a Hash160 delegate through 9 files (the previous approach), I added one new virtual method to NetworkStringParser: And one line change in PubKey.GetAddress() to call it. Decred overrides this to compute the correct hash. This follows the same pattern as the existing CreateP2PKH(KeyId, Network) and GetBase58CheckEncoder() virtuals. The other core additions are altcoin-agnostic extension points with Bitcoin-default behavior:
Everything else (WIF sig scheme byte, protocol payloads/behaviors, Blake256 checksums, getnewaddress param handling, Decred balance response format) is handled entirely in Altcoins using existing extension points and ConsensusFactory overrides. |
This is not complete but wanted to get feedback. Trying to add decred here with the intent of adding it to BTCpay Server. I appreciate any feedback and will do whatever it takes to get decred added. Thanks for your time.