Skip to content

Commit

Permalink
platformio fixes, fee and other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
stepansnigirev committed Feb 2, 2019
1 parent 2b5f77c commit 7cda8cc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
5 changes: 4 additions & 1 deletion src/Bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ void Signature::bin(uint8_t arr[64]) const{

// ---------------------------------------------------------------- PublicKey class

PublicKey::PublicKey(){}
PublicKey::PublicKey(){
memset(point, 0, 64);
compressed = true;
}
PublicKey::PublicKey(const uint8_t * pubkeyArr, bool use_compressed){
memcpy(point, pubkeyArr, 64);
compressed = use_compressed;
Expand Down
62 changes: 31 additions & 31 deletions src/Bitcoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class Script;
class Signature{// : public Printable{
private:
public:
uint8_t r[32];
uint8_t s[32];
uint8_t r[32] = {0};
uint8_t s[32] = {0};

Signature(); // empty constructor
Signature(const uint8_t r_arr[32], const uint8_t s_arr[32]); // constructor using r and s values
Expand Down Expand Up @@ -135,8 +135,8 @@ class Signature{// : public Printable{
class Script{
private:
void clear(); // clears memory
uint8_t * scriptArray; // stores actual script data
size_t scriptLen; // script length
uint8_t * scriptArray = NULL; // stores actual script data
size_t scriptLen = 0; // script length
public:
Script(); // empty constructor
Script(const uint8_t * buffer, size_t len); // creates script from byte array
Expand Down Expand Up @@ -210,8 +210,8 @@ class Script{
*/
class PublicKey{
public:
uint8_t point[64]; // point on curve (x,y)
bool compressed;
uint8_t point[64] = { 0 }; // point on curve (x,y)
bool compressed = true;

PublicKey();
PublicKey(const uint8_t pubkeyArr[64], bool use_compressed);
Expand Down Expand Up @@ -266,7 +266,7 @@ class PublicKey{
class PrivateKey{
PublicKey pubKey; // corresponding point on curve ( secret * G )
public:
uint8_t secret[32]; // 32-byte secret
uint8_t secret[32] = { 0 }; // 32-byte secret

PrivateKey();
PrivateKey(const uint8_t secret_arr[32], bool use_compressed = true, bool use_testnet = false);
Expand All @@ -282,8 +282,8 @@ class PrivateKey{
void getSecret(uint8_t buffer[32]) const{ memcpy(buffer, secret, 32); };

// TODO: remove `compressed` from here. PublicKey already has it.
bool compressed; // set to true if you want to use compressed public key format
bool testnet; // set to true for testnet
bool compressed = true; // set to true if you want to use compressed public key format
bool testnet = false; // set to true for testnet

int wif(char * wifArr, size_t len) const; // writes wallet import format string to wif array. 51 or 52 characters are required.
#if USE_ARDUINO_STRING
Expand Down Expand Up @@ -352,11 +352,11 @@ class HDPrivateKey{
~HDPrivateKey();

PrivateKey privateKey;
uint8_t chainCode[32];
uint8_t depth;
uint8_t fingerprint[4];
uint32_t childNumber;
uint8_t type;
uint8_t chainCode[32] = { 0 };
uint8_t depth = 0;
uint8_t fingerprint[4] = { 0 };
uint32_t childNumber = 0;
uint8_t type = UNKNOWN_HD_TYPE;

int fromSeed(const uint8_t * seed, size_t seedSize, bool use_testnet);
// int fromSeed(const uint8_t seed[64], bool use_testnet = false);
Expand Down Expand Up @@ -405,12 +405,12 @@ class HDPublicKey{
~HDPublicKey();

PublicKey publicKey;
uint8_t chainCode[32];
uint8_t depth;
uint8_t fingerprint[4];
uint32_t childNumber;
uint8_t type;
bool testnet;
uint8_t chainCode[32] = { 0 };
uint8_t depth = 0;
uint8_t fingerprint[4] = { 0 };
uint32_t childNumber = 0;
uint8_t type = UNKNOWN_HD_TYPE;
bool testnet = false;

int xpub(char * arr, size_t len) const;
int address(char * arr, size_t len) const;
Expand Down Expand Up @@ -453,17 +453,17 @@ class TxIn{
// TxIn(Stream & s){ parse(s); };
// TxIn(byte raw[], size_t len){ parse(raw, len); };

uint8_t hash[32];
uint32_t outputIndex;
uint8_t hash[32] = { 0 };
uint32_t outputIndex = 0;
Script scriptSig;
uint32_t sequence;
uint32_t sequence = 0;

// for electrum tx, only 2 for now
uint16_t derivation[2];
uint16_t derivation[2] = {0,0};

// For segwit:
Script witnessProgram;
uint64_t amount; // required for signing, also used for fee calculation
uint64_t amount = 0; // required for signing, also used for fee calculation

// following information is optional,
// can be obtained from spending output
Expand Down Expand Up @@ -499,7 +499,7 @@ class TxOut{
#endif
// TxOut(byte raw[], size_t len){ parse(raw, len); };

uint64_t amount;
uint64_t amount = 0;
Script scriptPubKey;

size_t parse(const uint8_t * raw, size_t l);
Expand Down Expand Up @@ -529,14 +529,14 @@ class Tx{
Tx(Tx const &other);
Tx &operator=(Tx const &other);

uint32_t version;
uint32_t version = 1;
TxIn * txIns;
TxOut * txOuts;
uint32_t locktime;
bool is_electrum;
uint32_t locktime = 0;
bool is_electrum = false;

size_t inputsNumber;
size_t outputsNumber;
size_t inputsNumber = 0;
size_t outputsNumber = 0;
uint8_t addInput(TxIn txIn);
uint8_t addOutput(TxOut txOut);

Expand Down
1 change: 1 addition & 0 deletions src/Conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ size_t writeVarInt(uint64_t num, ByteStream &s){
ByteStream::ByteStream(){
len = 0;
cursor = 0;
buf = NULL;
}
ByteStream::ByteStream(const uint8_t * buffer, size_t length){
len = length;
Expand Down

0 comments on commit 7cda8cc

Please sign in to comment.