Skip to content

Commit

Permalink
transaction: remove all refs to segwit and bech32
Browse files Browse the repository at this point in the history
dogecoin does not currently implement segregated witness otherwise known as segwit, therefore i've removed all references to segwit and bech32 address encoding.
  • Loading branch information
xanimo committed Jul 22, 2022
1 parent c349fe5 commit 0e81122
Show file tree
Hide file tree
Showing 26 changed files with 261 additions and 1,356 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ INSTALL(FILES
include/dogecoin/random.h
include/dogecoin/rmd160.h
include/dogecoin/script.h
include/dogecoin/segwit_addr.h
include/dogecoin/serialize.h
include/dogecoin/sha2.h
include/dogecoin/tool.h
Expand Down Expand Up @@ -94,7 +93,6 @@ TARGET_SOURCES(${LIBDOGECOIN_NAME} PRIVATE
src/random.c
src/rmd160.c
src/script.c
src/segwit_addr.c
src/serialize.c
src/sha2.c
src/cli/tool.c
Expand Down
2 changes: 0 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ libdogecoininclude_HEADERS = \
include/dogecoin/random.h \
include/dogecoin/rmd160.h \
include/dogecoin/script.h \
include/dogecoin/segwit_addr.h \
include/dogecoin/serialize.h \
include/dogecoin/sha2.h \
include/dogecoin/tool.h \
Expand Down Expand Up @@ -64,7 +63,6 @@ libdogecoin_la_SOURCES = \
src/random.c \
src/rmd160.c \
src/script.c \
src/segwit_addr.c \
src/serialize.c \
src/sha2.c \
src/cli/tool.c \
Expand Down
3 changes: 0 additions & 3 deletions doc/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,11 @@ Below are some examples on how to use the `such` tool in practice.
./such -c generate_public_key -p QSPDnjzvrSPAeiM7N2jCkzv2dqsi7fxoHipgpPfz2zdE3ZpYp74j
> pubkey: 02cf2c99c2db4b3d72d4289aa23bdaf5f3ccf4867ec8e5f8223ea716a7a3de10bc
> p2pkh address: D62RKK6AGkzX6fM8RzoVM8fjPx2nzrdvKU
> p2sh-p2wpkh address: 9zXbecoxo4aDsG8Ng1osUhGN9URrF1P9JZ

##### Generate the P2PKH address from a hex encoded compact public key

./such -c generate_public_key -pubkey 02cf2c99c2db4b3d72d4289aa23bdaf5f3ccf4867ec8e5f8223ea716a7a3de10bc
> p2pkh address: D62RKK6AGkzX6fM8RzoVM8fjPx2nzrdvKU
> p2sh-p2wpkh address: 9zXbecoxo4aDsG8Ng1osUhGN9URrF1P9JZ
> p2wpkh (doge / bech32) address: doge1qpx6wxh9xv780a7uj675vl0c88zd3fg4v26vlsn

##### Generate new BIP32 master key

Expand Down
5 changes: 2 additions & 3 deletions doc/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

## Introduction

The high level 'essential' API provided by libdogecoin for working with simple
transactions revolve around a structure defined as a `working_transaction` which is comprised of an index as an integer meant for retrieval, a dogecoin_tx 'transaction' structure as seen above, and finally a UT_hash_handle which stores our working_transaction struct in a hash table (using Troy D. Hanson's uthash library: see ./contrib/uthash/uthash.h and visit https://troydhanson.github.io/uthash/ for more information) to allow us to generate multiple transactions per "session". This `working_transaction` structure is defined as such:
The high level 'essential' API provided by libdogecoin for working with simple transactions revolve around a structure defined as a `working_transaction` which is comprised of an index as an integer meant for retrieval, a dogecoin_tx 'transaction' structure as seen above, and finally a UT_hash_handle which stores our working_transaction struct in a hash table (using Troy D. Hanson's uthash library: see ./contrib/uthash/uthash.h and visit https://troydhanson.github.io/uthash/ for more information) which allow us to generate multiple transactions per "session". This `working_transaction` structure is defined as such:
```C
typedef struct working_transaction {
int index;
Expand All @@ -32,7 +31,7 @@ typedef struct working_transaction {
} working_transaction;
```

The functions that have been built around this `working_transaction` structure and flow of operation are comprised of 4 macros, which are explained further in the following section describing the [working transaction API](#working-transaction-api). used to interact with uthash.
The functions that have been built around this `working_transaction` structure and flow of operation are comprised of 4 macros, which are explained further in the following section describing the [working transaction API](#working-transaction-api). used to interact with uthash. For more detailed technical information about the `dogecoin_tx` structure and Dogecoin transactions in general, please refer to the [extended transaction documentation](./transaction_extended.md).

The [Libdogecoin Essential API](#essential-api) itself is a higher level interface that contains all the necessary operations for building Dogecoin transactions from scratch. The generic process for building a transaction is as follows:
- Create an empty transaction.
Expand Down
227 changes: 49 additions & 178 deletions doc/transaction_extended.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion include/dogecoin/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ LIBDOGECOIN_API int dogecoin_base58_decode(void* bin, size_t* binszp, const char

LIBDOGECOIN_API dogecoin_bool dogecoin_p2pkh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char *addrout, int len);
LIBDOGECOIN_API dogecoin_bool dogecoin_p2sh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char* addrout, int len);
LIBDOGECOIN_API dogecoin_bool dogecoin_p2wpkh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char *addrout);

LIBDOGECOIN_END_DECL

Expand Down
2 changes: 0 additions & 2 deletions include/dogecoin/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ LIBDOGECOIN_API dogecoin_bool dogecoin_key_sign_recover_pubkey(const unsigned ch
//verifies a DER encoded signature with given pubkey and return true if valid
LIBDOGECOIN_API dogecoin_bool dogecoin_pubkey_verify_sig(const dogecoin_pubkey* pubkey, const uint256 hash, unsigned char* sigder, int len);

LIBDOGECOIN_API dogecoin_bool dogecoin_pubkey_getaddr_p2sh_p2wpkh(const dogecoin_pubkey* pubkey, const dogecoin_chainparams* chain, char* addrout);
LIBDOGECOIN_API dogecoin_bool dogecoin_pubkey_getaddr_p2pkh(const dogecoin_pubkey* pubkey, const dogecoin_chainparams* chain, char* addrout);
LIBDOGECOIN_API dogecoin_bool dogecoin_pubkey_getaddr_p2wpkh(const dogecoin_pubkey* pubkey, const dogecoin_chainparams* chain, char* addrout);

LIBDOGECOIN_END_DECL

Expand Down
8 changes: 0 additions & 8 deletions include/dogecoin/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ enum service_bits {
// Bitcoin Core nodes used to support this by default, without advertising this bit,
// but no longer do as of protocol version 70011 (= NO_BLOOM_VERSION)
DOGECOIN_NODE_BLOOM = (1 << 2),
// NODE_WITNESS indicates that a node can be asked for blocks and transactions including
// witness data.
DOGECOIN_NODE_WITNESS = (1 << 3),
// NODE_XTHIN means the node supports Xtreme Thinblocks
// If this is turned off then the node will not service nor make xthin requests
DOGECOIN_NODE_XTHIN = (1 << 4),
Expand Down Expand Up @@ -146,14 +143,9 @@ enum GetDataMsg
{
MSG_TX = 1,
MSG_BLOCK = 2,
// ORed into other flags to add witness
MSG_WITNESS_FLAG = 1 << 30,
// The following can only occur in getdata. Invs always use TX or BLOCK.
MSG_FILTERED_BLOCK = 3, //!< Defined in BIP37
MSG_CMPCT_BLOCK = 4, //!< Defined in BIP152
MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG, //!< Defined in BIP144
MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG, //!< Defined in BIP144
MSG_FILTERED_WITNESS_BLOCK = MSG_FILTERED_BLOCK | MSG_WITNESS_FLAG,
};

/* =================================== */
Expand Down
6 changes: 0 additions & 6 deletions include/dogecoin/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ LIBDOGECOIN_BEGIN_DECL
/** Sighash version types */
enum dogecoin_sig_version {
SIGVERSION_BASE = 0,
SIGVERSION_WITNESS_V0 = 1,
};

/** Signature hash types/flags */
Expand Down Expand Up @@ -203,8 +202,6 @@ enum dogecoin_tx_out_type {
DOGECOIN_TX_PUBKEYHASH,
DOGECOIN_TX_SCRIPTHASH,
DOGECOIN_TX_MULTISIG,
DOGECOIN_TX_WITNESS_V0_PUBKEYHASH,
DOGECOIN_TX_WITNESS_V0_SCRIPTHASH,
};

typedef struct dogecoin_script_op_ {
Expand Down Expand Up @@ -233,14 +230,11 @@ LIBDOGECOIN_API void dogecoin_script_append_pushdata(cstring* script_in, const u

LIBDOGECOIN_API dogecoin_bool dogecoin_script_build_multisig(cstring* script_in, const unsigned int required_signatures, const vector* pubkeys_chars);
LIBDOGECOIN_API dogecoin_bool dogecoin_script_build_p2pkh(cstring* script, const uint160 hash160);
LIBDOGECOIN_API dogecoin_bool dogecoin_script_build_p2wpkh(cstring* script, const uint160 hash160);
LIBDOGECOIN_API dogecoin_bool dogecoin_script_build_p2sh(cstring* script_in, const uint160 hash160);
LIBDOGECOIN_API dogecoin_bool dogecoin_script_get_scripthash(const cstring* script_in, uint160 scripthash);

LIBDOGECOIN_API const char* dogecoin_tx_out_type_to_str(const enum dogecoin_tx_out_type type);

LIBDOGECOIN_API dogecoin_bool dogecoin_script_is_witnessprogram(const cstring* script, uint8_t* version_out, uint8_t* program_out, int* programm_len_out);

LIBDOGECOIN_END_DECL

#endif // __LIBDOGECOIN_SCRIPT_H__
84 changes: 0 additions & 84 deletions include/dogecoin/segwit_addr.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/dogecoin/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
LIBDOGECOIN_BEGIN_DECL

/* generate the p2pkh address from a given hex pubkey */
LIBDOGECOIN_API dogecoin_bool addresses_from_pubkey(const dogecoin_chainparams* chain, const char* pubkey_hex, char* p2pkh_address, char* p2sh_p2wpkh_address, char* p2wpkh_address);
LIBDOGECOIN_API dogecoin_bool addresses_from_pubkey(const dogecoin_chainparams* chain, const char* pubkey_hex, char* p2pkh_address);

/* generate the hex publickey from a given hex private key */
LIBDOGECOIN_API dogecoin_bool pubkey_from_privatekey(const dogecoin_chainparams* chain, const char* privkey_hex, char* pubkey_hex, size_t* sizeout);
Expand Down
7 changes: 2 additions & 5 deletions include/dogecoin/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ typedef struct dogecoin_tx_in_ {
dogecoin_tx_outpoint prevout;
cstring* script_sig;
uint32_t sequence;
vector* witness_stack;
} dogecoin_tx_in;

typedef struct dogecoin_tx_out_ {
Expand Down Expand Up @@ -119,10 +118,10 @@ LIBDOGECOIN_API void dogecoin_tx_free(dogecoin_tx* tx);
LIBDOGECOIN_API void dogecoin_tx_copy(dogecoin_tx* dest, const dogecoin_tx* src);

//!deserialize/parse a p2p serialized dogecoin transaction
LIBDOGECOIN_API int dogecoin_tx_deserialize(const unsigned char* tx_serialized, size_t inlen, dogecoin_tx* tx, size_t* consumed_length, dogecoin_bool allow_witness);
LIBDOGECOIN_API int dogecoin_tx_deserialize(const unsigned char* tx_serialized, size_t inlen, dogecoin_tx* tx, size_t* consumed_length);

//!serialize a dogecoin data structure into a p2p serialized buffer
LIBDOGECOIN_API void dogecoin_tx_serialize(cstring* s, const dogecoin_tx* tx, dogecoin_bool allow_witness);
LIBDOGECOIN_API void dogecoin_tx_serialize(cstring* s, const dogecoin_tx* tx);

LIBDOGECOIN_API void dogecoin_tx_hash(const dogecoin_tx* tx, uint8_t* hashout);

Expand All @@ -139,8 +138,6 @@ LIBDOGECOIN_API dogecoin_bool dogecoin_tx_add_puzzle_out(dogecoin_tx* tx, const
LIBDOGECOIN_API dogecoin_bool dogecoin_tx_outpoint_is_null(dogecoin_tx_outpoint* tx);
LIBDOGECOIN_API dogecoin_bool dogecoin_tx_is_coinbase(dogecoin_tx* tx);

LIBDOGECOIN_API dogecoin_bool dogecoin_tx_has_witness(const dogecoin_tx* tx);

enum dogecoin_tx_sign_result {
DOGECOIN_SIGN_UNKNOWN = 0,
DOGECOIN_SIGN_INVALID_KEY = -2,
Expand Down
5 changes: 0 additions & 5 deletions src/base58.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <dogecoin/base58.h>
#include <dogecoin/chainparams.h>
#include <dogecoin/mem.h>
#include <dogecoin/segwit_addr.h>
#include <dogecoin/sha2.h>
#include <dogecoin/hash.h>

Expand Down Expand Up @@ -249,7 +248,3 @@ dogecoin_bool dogecoin_p2sh_addr_from_hash160(const uint160 hashin, const dogeco

return (dogecoin_base58_encode_check(hash160, sizeof(uint160) + 1, addrout, len) > 0);
}

dogecoin_bool dogecoin_p2wpkh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char *addrout) {
return segwit_addr_encode(addrout, chain->bech32_hrp, 0, hashin, sizeof(uint160));
}
4 changes: 0 additions & 4 deletions src/chainparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const dogecoin_chainparams dogecoin_chainparams_main = {
"main",
0x1e, // 30, starts with D
0x16, // 22, starts with 9 or A
// Human-readable part for Bech32 encoded segwit addresses, as defined in
// BIP 173.
"doge", // bech32_hrp planned for 0.21
0x9e, // 158, starts with 6 (uncompressed) or Q (compressed)
0x02fac398, // starts with dgpv
Expand All @@ -48,8 +46,6 @@ const dogecoin_chainparams dogecoin_chainparams_test = {
"testnet3",
0x71, // 113 starts with n
0xc4, // 196 starts with 2
// Human-readable part for Bech32 encoded segwit addresses, as defined in
// BIP 173.
"tdge", // bech32_hrp 0.21
0xf1, // 241 starts with 9 (uncompressed) or c (compressed)
0x04358394, // starts with tprv
Expand Down
2 changes: 1 addition & 1 deletion src/cli/sendtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int main(int argc, char* argv[]) {

dogecoin_tx* tx = dogecoin_tx_new();
/* Deserializing the transaction and broadcasting it to the network. */
if (dogecoin_tx_deserialize(data_bin, outlen, tx, NULL, true)) {
if (dogecoin_tx_deserialize(data_bin, outlen, tx, NULL)) {
broadcast_tx(chain, tx, ips, maxnodes, timeout, debug);
}
else {
Expand Down
Loading

0 comments on commit 0e81122

Please sign in to comment.