Skip to content

Commit

Permalink
Merge pull request #14 from mosadialiou/fix-testnet
Browse files Browse the repository at this point in the history
Fix litecoin testnet
  • Loading branch information
kcw-grunt authored Mar 23, 2020
2 parents 3558733 + 4751194 commit 2ea83a2
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions BRAddress.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ size_t BRAddressFromScriptPubKey(char *addr, size_t addrLen, const uint8_t *scri
size_t count = BRScriptElements(elems, sizeof(elems)/sizeof(*elems), script, scriptLen), l = 0;

data[0] = BITCOIN_PUBKEY_ADDRESS;
#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
data[0] = BITCOIN_PUBKEY_ADDRESS_TEST;
#endif

Expand All @@ -259,7 +259,7 @@ size_t BRAddressFromScriptPubKey(char *addr, size_t addrLen, const uint8_t *scri
else if (count == 3 && *elems[0] == OP_HASH160 && *elems[1] == 20 && *elems[2] == OP_EQUAL) {
// pay-to-script-hash scriptPubKey
data[0] = BITCOIN_SCRIPT_ADDRESS;
#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
data[0] = BITCOIN_SCRIPT_ADDRESS_TEST;
#endif
d = BRScriptData(elems[1], &l);
Expand Down Expand Up @@ -288,7 +288,7 @@ size_t BRAddressFromScriptSig(char *addr, size_t addrLen, const uint8_t *script,
size_t count = BRScriptElements(elems, sizeof(elems)/sizeof(*elems), script, scriptLen), l = 0;

data[0] = BITCOIN_PUBKEY_ADDRESS;
#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
data[0] = BITCOIN_PUBKEY_ADDRESS_TEST;
#endif

Expand All @@ -301,7 +301,7 @@ size_t BRAddressFromScriptSig(char *addr, size_t addrLen, const uint8_t *script,
else if (count >= 2 && *elems[count - 2] <= OP_PUSHDATA4 && *elems[count - 1] <= OP_PUSHDATA4 &&
*elems[count - 1] > 0) { // pay-to-script-hash scriptSig
data[0] = BITCOIN_SCRIPT_ADDRESS;
#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
data[0] = BITCOIN_SCRIPT_ADDRESS_TEST;
#endif
d = BRScriptData(elems[count - 1], &l);
Expand All @@ -324,7 +324,7 @@ size_t BRAddressScriptPubKey(uint8_t *script, size_t scriptLen, const char *addr

assert(addr != NULL);

#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
pubkeyAddress = BITCOIN_PUBKEY_ADDRESS_TEST;
scriptAddress = BITCOIN_SCRIPT_ADDRESS_TEST;
#endif
Expand Down Expand Up @@ -368,7 +368,7 @@ int BRAddressIsValid(const char *addr)
if (BRBase58CheckDecode(data, sizeof(data), addr) == 21) {
r = (data[0] == BITCOIN_PUBKEY_ADDRESS || data[0] == BITCOIN_SCRIPT_ADDRESS);

#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
r = (data[0] == BITCOIN_PUBKEY_ADDRESS_TEST || data[0] == BITCOIN_SCRIPT_ADDRESS_TEST);
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion BRAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
extern "C" {
#endif

#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
#pragma message "testnet build"
#endif

Expand Down
8 changes: 4 additions & 4 deletions BRKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int BRPrivKeyIsValid(const char *privKey)
strLen = strlen(privKey);

if (dataLen == 33 || dataLen == 34) { // wallet import format: https://en.bitcoin.it/wiki/Wallet_import_format
#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
r = (data[0] == BITCOIN_PRIVKEY_TEST);
#else
r = (data[0] == BITCOIN_PRIVKEY);
Expand Down Expand Up @@ -172,7 +172,7 @@ int BRKeySetPrivKey(BRKey *key, const char *privKey)
uint8_t data[34], version = BITCOIN_PRIVKEY;
int r = 0;

#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
version = BITCOIN_PRIVKEY_TEST;
#endif

Expand Down Expand Up @@ -233,7 +233,7 @@ size_t BRKeyPrivKey(const BRKey *key, char *privKey, size_t pkLen)

if (secp256k1_ec_seckey_verify(_ctx, key->secret.u8)) {
data[0] = BITCOIN_PRIVKEY;
#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
data[0] = BITCOIN_PRIVKEY_TEST;
#endif

Expand Down Expand Up @@ -292,7 +292,7 @@ size_t BRKeyAddress(BRKey *key, char *addr, size_t addrLen)

hash = BRKeyHash160(key);
data[0] = BITCOIN_PUBKEY_ADDRESS;
#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
data[0] = BITCOIN_PUBKEY_ADDRESS_TEST;
#endif
UInt160Set(&data[1], hash);
Expand Down
2 changes: 1 addition & 1 deletion BRMerkleBlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ int BRMerkleBlockVerifyDifficulty(const BRMerkleBlock *block, const BRMerkleBloc
if (! previous || !UInt256Eq(block->prevBlock, previous->blockHash) || block->height != previous->height + 1) r = 0;
if (r && (block->height % BLOCK_DIFFICULTY_INTERVAL) == 0 && transitionTime == 0) r = 0;

#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
// TODO: implement testnet difficulty rule check
return r; // don't worry about difficulty on testnet for now
#endif
Expand Down
2 changes: 1 addition & 1 deletion BRPeer.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>

#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
#define MAGIC_NUMBER 0xf1c8d2fd
#else
#define MAGIC_NUMBER 0xdbb6c0fb
Expand Down
2 changes: 1 addition & 1 deletion BRPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
extern "C" {
#endif

#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
#define STANDARD_PORT 19335
#else
#define STANDARD_PORT 9333
Expand Down
2 changes: 1 addition & 1 deletion BRPeerManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define PEER_FLAG_SYNCED 0x01
#define PEER_FLAG_NEEDSUPDATE 0x02

#if BITCOIN_TESTNET
#if LITECOIN_TESTNET

static const struct { uint32_t height; const char *hash; uint32_t timestamp; uint32_t target; } checkpoint_array[] = {
{ 0, "4966625a4b2851d9fdee139e56211a0d88575f59ed816ff5e6a63deb4e3e29a0", 1486949366, 0x1e0ffff0 }
Expand Down
6 changes: 3 additions & 3 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ int BRKeyTests()
BRKeySetPrivKey(&key, "S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy");
BRKeyAddress(&key, addr.s, sizeof(addr));
printf("privKey:S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy = %s\n", addr.s);
#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
if (! BRAddressEq(&addr, "ms8fwvXzrCoyatnGFRaLbepSqwGRxVJQF1"))
r = 0, fprintf(stderr, "***FAILED*** %s: BRKeySetPrivKey() test 1\n", __func__);
#else
Expand All @@ -1021,15 +1021,15 @@ int BRKeyTests()
BRKeySetPrivKey(&key, "SzavMBLoXU6kDrqtUVmffv");
BRKeyAddress(&key, addr.s, sizeof(addr));
printf("privKey:SzavMBLoXU6kDrqtUVmffv = %s\n", addr.s);
#if BITCOIN_TESTNET
#if LITECOIN_TESTNET
if (! BRAddressEq(&addr, "mrhzp5mstA4Midx85EeCjuaUAAGANMFmRP"))
r = 0, fprintf(stderr, "***FAILED*** %s: BRKeySetPrivKey() test 2\n", __func__);
#else
if (! BRAddressEq(&addr, "1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj"))
r = 0, fprintf(stderr, "***FAILED*** %s: BRKeySetPrivKey() test 2\n", __func__);
#endif

#if ! BITCOIN_TESTNET
#if ! LITECOIN_TESTNET
// uncompressed private key
if (! BRPrivKeyIsValid("5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF"))
r = 0, fprintf(stderr, "***FAILED*** %s: BRPrivKeyIsValid() test 3\n", __func__);
Expand Down

0 comments on commit 2ea83a2

Please sign in to comment.