-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add PoS coins (e.g. Peercoin) support #428
Conversation
This is great code @visvirial, I'm just not sure if it is in scope. We've been doing our best to remove the network specific aspects of bitcoinjs-lib over the last few months. (See #325, #383 and #402 for a start). I wonder if this can be managed in such a way that we can maintain modularity? |
Interesting. I do agree that this is a bit out of scope, but I don't see how we can provide a clean entry point for such extension of the library, due to the procedural nature of deserialization/serialization. To implement support for PoS networks without modifying this library itself, one'd have to extend classes like |
When in doubt, fork and make a new project... Then just link to it in the readme. We don't have to accommodate every cryptocoin out there, but we can still point people in the right direction. |
If the goal of this project is just providing a simple and short library for cryptocurrency, Add a new network option networks.bitcoin.binaryFormat.transaction = [
// nVersion
{
name: 'version',
type: 'int32',
},
/*
// nTime for PoS coins
{
name: 'time',
type: 'uint32',
},
*/
// vin
{
name: 'vin',
type: 'CTxIn[]',
},
// vout
{
name: 'vout',
type: 'CTxOut[]',
},
// nLockTime
{
name: 'locktime',
type: 'uint32',
},
] And then, in Transaction.prototype.fromBuffer = function(...) {
(snip)
var read = function (type) {
switch(type) {
case 'int32':
case 'uint32':
return readUint32();
break;
case 'CTxIn[]':
var len = readVarInt();
tx.ins = [];
for(var i=0; i<len; i++) {
tx.ins.push(readTxIn());
}
break;
(... and so on)
}
}
network.binaryFormat.transaction.forEach(field) {
tx[field] = read(field.type);
}
(snip)
} I think this style of modification is much simpler, easier to maintain and more flexible How do you feel my suggestion? |
another case where support for a different transaction structure is needed: Sidechain Elements. I suspect Sidechains will go mainstream quickly. @mvayngrib, @pgmemk and I started working on a project where we need to support Asset transactions on Sidechains. |
@urbien what features would be needed to support Elements Alpha for example? |
@visvirial I think that is an OK suggestion. Maybe not Also, how do you enforce support with |
Targeting |
@visvirial do you use IRC? |
@dcousens What is the channel and server? |
freenode, #bitcoinjs-dev |
@dcousens re: elements alpha, it would likely have to be a fork, rather than augmenting this repo. Transaction and TransactionBuilder would need to change pretty seriously to support confidential transactions, and the elements built on top of it like asset issuance/transfer. Have you played with elements yet? |
I think I'm going to lean towards closing this. Peercoin is still around, but, to keep up with development we'd have to massively re-write the library and highly generalize it where generalization isn't really necessary. @visvirial if you're still interested in this, please re-open, I'm just not sure what the best approach is. |
@urbien if this is still a case, please keep don't hesitate to submit patches that may make patching simpler, provided the changes are in scope for bitcoinjs-lib too. |
@visvirial that said, I think #428 (comment) is spot on and might still be worth while doing. |
Someone should take these changes and port them over to bitcore, then make a pull request to the altcore project: https://github.com/priestc/altcore-lib Altcore wants to support all crypto currencies, especially ones like PPC that have many forked currencies descended from it. |
About
bitcoinjs-lib
supports alt-coins (e.g. Litecoin, Monacoin and Dogecoin) by passing coin network configurations through its API.However, for Proof of Stake (a.k.a. "PoS") coins such as Peercoin, Blackcoin and Peercoin-derived cryptocurrencies have slightly different binary format (see below) of transactions and blocks (it is represented as
CTransaction
orCBlock
respectively, in the original source code), whichbitcoinjs-lib
cannot understand.The difference of binary formats of blocks and transactions between Bitcoin and Peercoin-like cryptocurrencies are:
unsigned int nTime
field inclass CTransaction
(Peercoin: src/main.h L431)std::vector<unsigned char> vchBlockSig
field inclass CBlock
(Peercoin: src/main.h L893)In this pull request, I have added some codes regarding PoS coins support.
Summary of Changes: