-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from bnogalm/protocol_13
Protocol 13
- Loading branch information
Showing
82 changed files
with
2,745 additions
and
749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include "abstracttransaction.h" | ||
#include "transaction.h" | ||
#include "feebumptransaction.h" | ||
|
||
AbstractTransaction::AbstractTransaction(Network *network) : m_network(network) | ||
{ | ||
checkNotNull(network, "network cannot be null"); | ||
} | ||
void AbstractTransaction::sign(KeyPair *signer) { | ||
checkNotNull(signer, "signer cannot be null"); | ||
QByteArray txHash = this->hash(); | ||
|
||
m_signatures.append(signer->signDecorated(txHash)); | ||
} | ||
|
||
void AbstractTransaction::sign(QByteArray preimage) { | ||
checkNotNull(preimage, "preimage cannot be null"); | ||
stellar::DecoratedSignature decoratedSignature; | ||
stellar::Signature &signature = decoratedSignature.signature; | ||
|
||
signature.set(reinterpret_cast<uchar*>(preimage.data()),preimage.length()); | ||
|
||
|
||
QByteArray hash = Util::hash(preimage); | ||
QByteArray signatureHintBytes =hash.right(4); | ||
|
||
stellar::SignatureHint &signatureHint = decoratedSignature.hint; | ||
memcpy(signatureHint.signatureHint,signatureHintBytes.data(),4); | ||
|
||
|
||
decoratedSignature.hint = signatureHint; | ||
decoratedSignature.signature = signature; | ||
|
||
|
||
m_signatures.append(decoratedSignature); | ||
} | ||
|
||
QByteArray AbstractTransaction::hash() const | ||
{ | ||
return Util::hash(this->signatureBase()); | ||
} | ||
|
||
QString AbstractTransaction::hashHex() const | ||
{ | ||
return QString::fromLatin1(hash().toHex()); | ||
} | ||
|
||
Network *AbstractTransaction::getNetwork() const | ||
{ | ||
return m_network; | ||
} | ||
|
||
QVector<stellar::DecoratedSignature> AbstractTransaction::getSignatures() const { | ||
return m_signatures; | ||
} | ||
|
||
AbstractTransaction *AbstractTransaction::fromEnvelopeXdr(stellar::TransactionEnvelope &xdr, Network* network) | ||
{ | ||
switch(xdr.type) | ||
{ | ||
case stellar::EnvelopeType::ENVELOPE_TYPE_TX: | ||
{ | ||
return Transaction::fromV1EnvelopeXdr(xdr.v1,network); | ||
} | ||
case stellar::EnvelopeType::ENVELOPE_TYPE_TX_V0: | ||
{ | ||
return Transaction::fromV0EnvelopeXdr(xdr.v0,network); | ||
} | ||
case stellar::EnvelopeType::ENVELOPE_TYPE_TX_FEE_BUMP: | ||
{ | ||
return FeeBumpTransaction::fromFeeBumpTransactionEnvelope(xdr.feeBump, network); | ||
} | ||
default: throw std::runtime_error("transaction type is not supported"); | ||
} | ||
|
||
|
||
} | ||
|
||
AbstractTransaction *AbstractTransaction::fromEnvelopeXdr(QString envelope, Network *network) | ||
{ | ||
QByteArray data = QByteArray::fromBase64(envelope.toLatin1()); | ||
QDataStream stream(&data, QIODevice::ReadOnly); | ||
stellar::TransactionEnvelope xdr; | ||
stream >> xdr; | ||
return fromEnvelopeXdr(xdr,network); | ||
} | ||
|
||
QString AbstractTransaction::toEnvelopeXdrBase64() { | ||
|
||
stellar::TransactionEnvelope envelope =this->toEnvelopeXdr(); | ||
QByteArray outputStream; | ||
QDataStream xdrOutputStream(&outputStream,QIODevice::WriteOnly); | ||
xdrOutputStream<< envelope; | ||
return outputStream.toBase64(XDR_BASE64ENCODING); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#ifndef ABSTRACTTRANSACTION_H | ||
#define ABSTRACTTRANSACTION_H | ||
|
||
#include <QObject> | ||
#include "xdr/stellartransaction.h" | ||
#include "keypair.h" | ||
#include "operation.h" | ||
#include "memo.h" | ||
#include "network.h" | ||
class AbstractTransaction : public QObject | ||
{ | ||
Q_OBJECT | ||
protected: | ||
Network* m_network; | ||
QVector<stellar::DecoratedSignature> m_signatures; | ||
|
||
explicit AbstractTransaction(Network* network); | ||
public: | ||
static const int MIN_BASE_FEE = 100; | ||
/** | ||
* Adds a new signature ed25519PublicKey to this transaction. | ||
* @param signer {@link KeyPair} object representing a signer | ||
*/ | ||
void sign(KeyPair* signer); | ||
|
||
/** | ||
* Adds a new sha256Hash signature to this transaction by revealing preimage. | ||
* @param preimage the sha256 hash of preimage should be equal to signer hash | ||
*/ | ||
void sign(QByteArray preimage); | ||
|
||
/** | ||
* Returns transaction hash. | ||
*/ | ||
QByteArray hash() const; | ||
|
||
|
||
/** | ||
* Returns transaction hash encoded as a hexadecimal string. | ||
*/ | ||
QString hashHex() const; | ||
|
||
|
||
/** | ||
* Returns signature base. | ||
*/ | ||
virtual QByteArray signatureBase() const= 0; | ||
|
||
|
||
Network* getNetwork() const; | ||
|
||
QVector<stellar::DecoratedSignature> getSignatures() const; | ||
|
||
/** | ||
* Generates TransactionEnvelope XDR object. | ||
*/ | ||
virtual stellar::TransactionEnvelope toEnvelopeXdr() = 0; | ||
|
||
/** | ||
* Returns base64-encoded TransactionEnvelope XDR object. Transaction need to have at least one signature. | ||
*/ | ||
QString toEnvelopeXdrBase64(); | ||
|
||
/** | ||
* Returns new AbstractTransaction object from Transaction XDR object. | ||
* @param xdr XDR object | ||
*/ | ||
static AbstractTransaction* fromEnvelopeXdr(stellar::TransactionEnvelope& xdr, Network * network = Network::current()); | ||
|
||
/** | ||
* Creates a <code>Transaction</code> instance from previously build <code>TransactionEnvelope</code> | ||
* @param envelope Base-64 encoded <code>TransactionEnvelope</code> | ||
* @return | ||
* @throws IOException | ||
*/ | ||
static AbstractTransaction* fromEnvelopeXdr(QString envelope, Network* network= Network::current()); | ||
|
||
|
||
signals: | ||
|
||
}; | ||
|
||
#endif // ABSTRACTTRANSACTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.