From 5d80558a55f123a0097d07e9881c079fc82c8071 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Thu, 18 Oct 2018 20:18:31 +0300 Subject: [PATCH] dpow_notarytx: start preparations for VRSC sapling usesigs? when we should create unsignedrawtx and when preimage for signing? --- iguana/dpow/dpow_tx.c | 45 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index 148827d68..1f8f769eb 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -267,43 +267,65 @@ int32_t dpow_voutstandard(struct supernet_info *myinfo,struct dpow_block *bp,uin bits256 dpow_notarytx(struct supernet_info *myinfo,char *signedtx,int32_t *numsigsp,int32_t isPoS,struct dpow_block *bp,int8_t bestk,uint64_t bestmask,int32_t usesigs,int32_t src_or_dest,uint8_t pubkeys[][33],int32_t numratified) { uint32_t k,m,numsigs,version,vout,crcval,sequenceid = 0xffffffff; bits256 zero; int32_t n,siglen,len; uint8_t serialized[32768],*sig; bits256 txid; struct dpow_entry *ep; struct dpow_coinentry *cp; - signedtx[0] = 0; + + struct iguana_info *coin = (src_or_dest != 0) ? bp->destcoin : bp->srccoin; + uint32_t zcash = (strcmp(coin->symbol, "VRSC") == 0 || strcmp(coin->symbol, "VRSCTEST") == 0); + printf("[Decker] dpow_notarytx: src.(%s) dst.(%s) src_or_dest.(%d) usesigs.(%d)\n", bp->srccoin->symbol, bp->destcoin->symbol, src_or_dest, usesigs); + + signedtx[0] = 0; *numsigsp = 0; memset(zero.bytes,0,sizeof(zero)); len = numsigs = 0; version = 1; - len += iguana_rwnum(1,&serialized[len],sizeof(version),&version); - if ( isPoS != 0 ) + + if (zcash) { + version = 4; + version = 1 << 31 | version; // overwintered + } + + len += iguana_rwnum(1,&serialized[len],sizeof(version),&version); + + if (zcash) { + uint32_t versiongroupid = 0x892f2085; // sapling + len += iguana_rwnum(1, &serialized[len], sizeof(versiongroupid), &versiongroupid); + } + + + if ( isPoS != 0 ) len += iguana_rwnum(1,&serialized[len],sizeof(bp->timestamp),&bp->timestamp); m = bp->minsigs; len += iguana_rwvarint32(1,&serialized[len],(uint32_t *)&m); - for (k=m=0; knumnotaries; k++) + // -- vins -- + for (k=m=0; knumnotaries; k++) { siglen = 0; sig = 0; if ( ((1LL << k) & bestmask) != 0 ) { - if ( pubkeys != 0 && numratified > 0 ) + if ( pubkeys != 0 && numratified > 0 ) // state [1] { + printf("[Decker] dpow_notarytx: state [1]\n"); if ( src_or_dest != 0 ) { txid = bp->notaries[k].ratifydestutxo; vout = bp->notaries[k].ratifydestvout; - } + } else { txid = bp->notaries[k].ratifysrcutxo; vout = bp->notaries[k].ratifysrcvout; } - if ( bestk >= 0 ) + + if ( bestk >= 0 ) // { siglen = bp->notaries[k].ratifysiglens[src_or_dest]; sig = bp->notaries[k].ratifysigs[src_or_dest]; } //char str[65]; printf("j.%d k.%d m.%d vin.(%s) v%d siglen.%d\n",j,k,m,bits256_str(str,txid),vout,siglen); } - else + else // state [2] { + printf("[Decker] dpow_notarytx: state [2]\n"); ep = &bp->notaries[k]; cp = (src_or_dest != 0) ? &bp->notaries[k].dest : &bp->notaries[k].src; if ( bits256_nonz(cp->prev_hash) == 0 ) @@ -321,7 +343,8 @@ bits256 dpow_notarytx(struct supernet_info *myinfo,char *signedtx,int32_t *numsi } len += iguana_rwbignum(1,&serialized[len],sizeof(txid),txid.bytes); len += iguana_rwnum(1,&serialized[len],sizeof(vout),&vout); - if ( usesigs != 0 && bestk >= 0 ) + + if ( usesigs != 0 && bestk >= 0 ) { len += iguana_rwvarint32(1,&serialized[len],(uint32_t *)&siglen); if ( siglen > 0 && siglen <= sizeof(cp->sigs[bestk]) ) @@ -331,6 +354,7 @@ bits256 dpow_notarytx(struct supernet_info *myinfo,char *signedtx,int32_t *numsi numsigs++; } //else printf("%s -> %s src_or_dest.%d Missing sig from k.%d\n",bp->srccoin->symbol,bp->destcoin->symbol,src_or_dest,k); } else serialized[len++] = 0; + len += iguana_rwnum(1,&serialized[len],sizeof(sequenceid),&sequenceid); //printf("height.%d mod.%d VINI.%d <- i.%d j.%d\n",height,height % numnotaries,m,i,j); m++; @@ -338,6 +362,7 @@ bits256 dpow_notarytx(struct supernet_info *myinfo,char *signedtx,int32_t *numsi break; } } + // -- vins -- if ( (n= dpow_voutstandard(myinfo,bp,&serialized[len],m,src_or_dest,pubkeys,numratified)) < 0 ) { printf("error dpow_voutstandard m.%d src_or_dest.%d\n",m,src_or_dest); @@ -345,6 +370,8 @@ bits256 dpow_notarytx(struct supernet_info *myinfo,char *signedtx,int32_t *numsi } len += n; init_hexbytes_noT(signedtx,serialized,len); + printf("[Decker] dpow_notarytx: signedtx.(%s)\n", signedtx); + //printf("notarytx.(%s) opretlen.%d\n",signedtx,opretlen); if ( usesigs == 0 && bestk >= 0 ) {