ImportPayout cc eval code and alot of general cc polish. tests to write

This commit is contained in:
Scott Sadler
2018-03-30 15:46:41 -03:00
parent 991c422a9d
commit 2c8d8268dd
25 changed files with 389 additions and 116 deletions

View File

@@ -2,6 +2,8 @@ lib_LTLIBRARIES=libcryptoconditions.la
noinst_LTLIBRARIES=$(CRYPTOCONDITIONS_CORE)
SUBDIRS = src/include/secp256k1
include_HEADERS = include/cryptoconditions.h
# Have a separate build target for cryptoconditions that does not contain secp256k1
libcryptoconditions_la_SOURCES = include/cryptoconditions.h

View File

@@ -84,9 +84,9 @@ unsigned char* cc_conditionUri(const CC *cond);
unsigned char* cc_jsonRPC(unsigned char *request);
unsigned long cc_getCost(const CC *cond);
enum CCTypeId cc_typeId(const CC *cond);
uint32_t cc_typeMask(const CC *cond);
void cc_free(struct CC *cond);
#ifdef __cplusplus
}
#endif

View File

@@ -42,8 +42,8 @@ void appendUriSubtypes(uint32_t mask, unsigned char *buf) {
} else {
strcat(buf, "&subtypes=");
strcat(buf, typeRegistry[i]->name);
append = 1;
}
append = 1;
}
}
}
@@ -70,7 +70,7 @@ unsigned char *cc_conditionUri(const CC *cond) {
}
static uint32_t getSubtypes(CC *cond) {
uint32_t cc_typeMask(const CC *cond) {
uint32_t mask = 1 << cond->type->typeId;
if (cond->type->hasSubtypes) {
mask |= cond->type->getSubtypes(cond);

View File

@@ -49,7 +49,6 @@ static CC *mkAnon(const Condition_t *asnCond);
static void asnCondition(const CC *cond, Condition_t *asn);
static Condition_t *asnConditionNew(const CC *cond);
static Fulfillment_t *asnFulfillmentNew(const CC *cond);
static uint32_t getSubtypes(CC *cond);
static cJSON *jsonEncodeCondition(cJSON *params, unsigned char *err);
static struct CC *fulfillmentToCC(Fulfillment_t *ffill);
static struct CCType *getTypeByAsnEnum(Condition_PR present);

View File

@@ -71,7 +71,7 @@ static Fulfillment_t *prefixToFulfillment(const CC *cond) {
static uint32_t prefixSubtypes(const CC *cond) {
return getSubtypes(cond->subcondition) & ~(1 << cc_prefixType.typeId);
return cc_typeMask(cond->subcondition) & ~(1 << cc_prefixType.typeId);
}

View File

@@ -98,7 +98,7 @@ int secp256k1Verify(CC *cond, CCVisitor visitor) {
static int cc_secp256k1VerifyTreeMsg32(const CC *cond, const unsigned char *msg32) {
int subtypes = getSubtypes(cond);
int subtypes = cc_typeMask(cond);
if (subtypes & (1 << cc_prefixType.typeId) &&
subtypes & (1 << cc_secp256k1Type.typeId)) {
// No support for prefix currently, due to pending protocol decision on
@@ -148,7 +148,7 @@ static int secp256k1Sign(CC *cond, CCVisitor visitor) {
* Sign secp256k1 conditions in a tree
*/
int cc_signTreeSecp256k1Msg32(CC *cond, const unsigned char *privateKey, const unsigned char *msg32) {
if (getSubtypes(cond) & (1 << cc_preimageType.typeId)) {
if (cc_typeMask(cond) & (1 << cc_preimageType.typeId)) {
// No support for prefix currently, due to pending protocol decision on
// how to combine message and prefix into 32 byte hash
return 0;

View File

@@ -14,7 +14,7 @@ struct CCType cc_thresholdType;
static uint32_t thresholdSubtypes(const CC *cond) {
uint32_t mask = 0;
for (int i=0; i<cond->size; i++) {
mask |= getSubtypes(cond->subconditions[i]);
mask |= cc_typeMask(cond->subconditions[i]);
}
mask &= ~(1 << cc_thresholdType.typeId);
return mask;