diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index be4d63271..65a01199e 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -77,6 +77,18 @@ // start of consensus code +void mpz_set_lli( mpz_t rop, long long op ) +{ + mpz_import(rop, 1, 1, sizeof(op), 0, 0, &op); +} + +int64_t mpz_get_si2( mpz_t op ) +{ + int64_t ret = 0; + mpz_export(&ret, NULL, 1, sizeof(ret), 0, 0, op); + return ret; +} + CScript EncodePaymentsTxidOpRet(int64_t allocation,std::vector scriptPubKey,std::vector destopret) { CScript opret; uint8_t evalcode = EVAL_PAYMENTS; @@ -277,7 +289,7 @@ int32_t payments_getallocations(int32_t top, int32_t bottom, const std::vectorInvalid("could not decode ccopret")); if ( tx.vout.back().scriptPubKey.IsOpReturn() ) fHasOpret = true; - mpz_set_si(mpzCheckamount,amountReleased); + mpz_set_lli(mpzCheckamount,amountReleased); } else return(eval->Invalid("could not decode ccopret")); // use the createtxid to fetch the tx and all of the plans info. @@ -382,7 +394,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //fprintf(stderr, "totalallocations.%li checkallocations.%li\n",totalallocations, checkallocations); if ( totalallocations != checkallocations ) return(eval->Invalid("allocation missmatch")); - mpz_set_si(mpzTotalAllocations,totalallocations); + mpz_set_lli(mpzTotalAllocations,totalallocations); } else if ( funcid == 'S' || funcid == 'O' ) { @@ -438,16 +450,16 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else { mpz_init(mpzAllocation); - mpz_set_si(mpzAllocation,allocations[n]); + mpz_set_lli(mpzAllocation,allocations[n]); mpz_mul(mpzAllocation,mpzAllocation,mpzCheckamount); mpz_tdiv_q(mpzAllocation,mpzAllocation,mpzTotalAllocations); - test = mpz_get_si(mpzAllocation); + test = mpz_get_si2(mpzAllocation); mpz_clear(mpzAllocation); } - //fprintf(stderr, "vout %i test.%li nValue.%li\n", i, test, tx.vout[i].nValue); + //fprintf(stderr, "vout.%i test.%lli vs nVlaue.%lli\n",i, (long long)test, (long long)tx.vout[i].nValue); if ( test != tx.vout[i].nValue ) { - fprintf(stderr, "vout.%i test.%li vs nVlaue.%li\n",i, test, tx.vout[i].nValue); + fprintf(stderr, "vout.%i test.%lli vs nVlaue.%lli\n",i, (long long)test, (long long)tx.vout[i].nValue); return(eval->Invalid("amounts do not match")); } if ( test < minimum ) @@ -463,10 +475,10 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & { // need to check that the next allocation was less than minimum, otherwise ppl can truncate the tx at any place not paying all elegible addresses. mpz_init(mpzAllocation); - mpz_set_si(mpzAllocation,allocations[n+1]); + mpz_set_lli(mpzAllocation,allocations[n+1]); mpz_mul(mpzAllocation,mpzAllocation,mpzCheckamount); mpz_tdiv_q(mpzAllocation,mpzAllocation,mpzTotalAllocations); - int64_t test = mpz_get_si(mpzAllocation); + int64_t test = mpz_get_si2(mpzAllocation); //fprintf(stderr, "check next vout pays under min: test.%li > minimuim.%i\n", test, minimum); if ( test > minimum ) return(eval->Invalid("next allocation was not under minimum")); @@ -785,7 +797,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) return(result); } // set totalallocations to a mpz_t bignum, for amounts calculation later. - mpz_set_si(mpzTotalAllocations,totalallocations); + mpz_set_lli(mpzTotalAllocations,totalallocations); } else if ( funcid == 'S' || funcid == 'O' ) { @@ -852,7 +864,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) } newamount = amount; int64_t totalamountsent = 0; - mpz_t mpzAmount; mpz_init(mpzAmount); mpz_set_si(mpzAmount,amount); + mpz_t mpzAmount; mpz_init(mpzAmount); mpz_set_lli(mpzAmount,amount); for (i=0; i