peerplays_migrated/libraries/plugins/peerplays_sidechain/bitcoin/bitcoin_script.cpp
sierra19XX b436b790fb
SON Weighted Multi Signature Signing (#349)
* Bring in the bitcoin utils code into plugin
* Add tx creation, signing and tests
* tx deserialization fix
* add 10-of-14 multisig address test
* Add signing and verification tests and sign_transaction_standalone
* Add send_transaction_standalone function
* Debug logs and additional tests
* Fix for son deletion in the middle
* Extend script_builder
* Witness script for weighted wallet
* btc_weighted_multisig_address implementation
* Fix for bad-txns-nonstandard-inputs
* Weighted multisignature address test
* Create test tx with weighted multisig wallet
* Fix the issues with tx signing
* End to End test weighted multi sig
* 1 or m-of-n deposit address support
* Move network_type enum to the base class
* btc_one_or_weighted_multisig_address implementation
* Simplify redeem script
* Fix error in redeem_script
* btc_one_or_weighted_multisig_address tests
* Refactor sidechain address mapping
* CLANG code format
* CLANG code format sidechain tests
* Integration of deposit and rest of weighted wallets, withdrawal fee fix, whole code refactoring
* Move util functions to Utils file
* Add proper checks for withdraw fee
* Deposit address creation, import deposit/withdraw addresses, some code cleanup

Co-authored-by: satyakoneru <15652887+satyakoneru@users.noreply.github.com>
Co-authored-by: gladcow <s.gladkov@pbsa.info>
Co-authored-by: Srdjan Obucina <obucinac@gmail.com>
2020-04-18 22:18:04 +02:00

65 lines
2.2 KiB
C++

#include <graphene/peerplays_sidechain/bitcoin/bitcoin_script.hpp>
#include <graphene/peerplays_sidechain/bitcoin/serialize.hpp>
namespace graphene { namespace peerplays_sidechain { namespace bitcoin {
script_builder &script_builder::operator<<(op opcode) {
const auto op_byte = static_cast<uint8_t>(opcode);
if (op_byte < 0 || op_byte > 0xff)
throw std::runtime_error("script_builder::operator<<(OP): invalid opcode");
script.push_back(op_byte);
return *this;
}
script_builder &script_builder::operator<<(uint32_t number) {
if (number == 0) {
script.push_back(static_cast<uint8_t>(op::_0));
} else if (number <= 16) {
script.push_back(static_cast<uint8_t>(op::_1) + number - 1);
} else {
bytes pack_buf;
while (number) {
pack_buf.push_back(number & 0xff);
number >>= 8;
}
// - If the most significant byte is >= 0x80 and the value is positive, push a
// new zero-byte to make the significant byte < 0x80 again. So, the result can
// be 5 bytes max.
if (pack_buf.back() & 0x80)
pack_buf.push_back(0);
*this << pack_buf;
}
return *this;
}
script_builder &script_builder::operator<<(size_t size) {
write_compact_size(script, size);
return *this;
}
script_builder &script_builder::operator<<(const bytes &sc) {
write_compact_size(script, sc.size());
script.insert(script.end(), sc.begin(), sc.end());
return *this;
}
script_builder &script_builder::operator<<(const fc::sha256 &hash) {
write_compact_size(script, hash.data_size());
script.insert(script.end(), hash.data(), hash.data() + hash.data_size());
return *this;
}
script_builder &script_builder::operator<<(const fc::ripemd160 &hash) {
write_compact_size(script, hash.data_size());
script.insert(script.end(), hash.data(), hash.data() + hash.data_size());
return *this;
}
script_builder &script_builder::operator<<(const fc::ecc::public_key_data &pubkey_data) {
write_compact_size(script, pubkey_data.size());
script.insert(script.end(), pubkey_data.begin(), pubkey_data.begin() + pubkey_data.size());
return *this;
}
}}} // namespace graphene::peerplays_sidechain::bitcoin