Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ picocoin-config.h*
picocoin*.deb

.project
test/core
test/uahf-sighash
10 changes: 10 additions & 0 deletions include/ccoin/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ static inline int64_t bp_block_value(unsigned int height, int64_t fees)
return subsidy + fees;
}


/**
* UAHF related transaction functions
*/
//extern bool deser_bp_tx_uahf(struct bp_tx *tx, struct const_buffer *buf);
//extern void ser_bp_tx_uahf(cstring *s, const struct bp_tx *tx);
//extern bool bp_tx_valid_uahf(const struct bp_tx *tx);
extern void bp_tx_calc_sha256_uahf(struct bp_tx *tx);


#ifdef __cplusplus
}
#endif
Expand Down
31 changes: 30 additions & 1 deletion include/ccoin/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum
SIGHASH_ALL = 1,
SIGHASH_NONE = 2,
SIGHASH_SINGLE = 3,
SIGHASH_FORKID_UAHF = 0x40,
SIGHASH_ANYONECANPAY = 0x80,
};

Expand All @@ -59,6 +60,7 @@ enum
SCRIPT_VERIFY_CLEANSTACK = (1U << 8),
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9),
SCRIPT_VERIFY_CHECKSEQUENCEVERIFY = (1U << 10),
SCRIPT_ENABLE_SIGHASH_FORKID = (1U << 16),
};

enum txnouttype
Expand Down Expand Up @@ -293,15 +295,42 @@ extern bool bp_script_verify(const cstring *scriptSig, const cstring *scriptPubK
const struct bp_tx *txTo, unsigned int nIn,
unsigned int flags, int nHashType);
extern bool bp_verify_sig(const struct bp_utxo *txFrom, const struct bp_tx *txTo,
unsigned int nIn, unsigned int flags, int nHashType);
unsigned int nIn, unsigned int flags, int nHashType);

extern bool bp_script_verify_with_value(const cstring *scriptSig, const cstring *scriptPubKey,
const struct bp_tx *txTo, unsigned int nIn,
unsigned int flags, int nHashType, int64_t amount);

extern bool bp_script_sign(struct bp_keystore *ks, const cstring *fromPubKey,
const struct bp_tx *txTo, unsigned int nIn,
int nHashType);

extern bool bp_sign_sig(struct bp_keystore *ks, const struct bp_utxo *txFrom,
struct bp_tx *txTo, unsigned int nIn,
unsigned int flags, int nHashType);

extern void bp_tx_sighash_with_value(bu256_t *hash, const cstring *scriptCode,
const struct bp_tx *txTo, unsigned int nIn,
int nHashType, int64_t value);

extern bool bp_script_sign_with_value(struct bp_keystore *ks, const cstring *fromPubKey,
const struct bp_tx *txTo, unsigned int nIn,
int nHashType, int64_t value);


/**
* uahf related
*/

void uahf_bp_tx_sighash(bu256_t *hash, const cstring *scriptCode,
const struct bp_tx *txTo, unsigned int nIn,
int nHashType, int64_t value);

extern bool uahf_bp_script_sign(struct bp_keystore *ks, const cstring *fromPubKey,
const struct bp_tx *txTo, unsigned int nIn,
int nHashType, int64_t value);


/*
* script building
*/
Expand Down
1 change: 1 addition & 0 deletions lib/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,4 @@ bool bp_block_valid(struct bp_block *block)
return true;
}


21 changes: 21 additions & 0 deletions lib/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,24 @@ unsigned int bp_block_ser_size(const struct bp_block *block)
return block_ser_size;
}

/**
* the following is uahf related code
*/


void bp_tx_calc_sha256_uahf(struct bp_tx *tx)
{
if (tx->sha256_valid)
return;

/* TODO: introduce hashing-only serialization mode */

cstring *s = cstr_new_sz(512);
ser_bp_tx(s, tx);

bu_Hash((unsigned char *) &tx->sha256, s->str, s->len);
tx->sha256_valid = true;

cstr_free(s, true);
}

Loading