Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
ce9e476d6f
  1. 3
      crypto777/OS_portable.h
  2. 6
      crypto777/hmac_sha512.c
  3. 27
      crypto777/iguana_utils.c
  4. 277
      crypto777/scrypt.c
  5. 2
      iguana/SuperNET_category.c
  6. 958
      iguana/chart.html
  7. 1
      iguana/exchanges777.h
  8. 3
      iguana/iguana777.c
  9. 14
      iguana/iguana777.h
  10. 2
      iguana/iguana_accept.c
  11. 18
      iguana/iguana_blocks.c
  12. 2
      iguana/iguana_bundles.c
  13. 58
      iguana/iguana_chains.c
  14. 2
      iguana/iguana_exchanges.c
  15. 4
      iguana/iguana_init.c
  16. 6
      iguana/iguana_instantdex.c
  17. 16
      iguana/iguana_msg.c
  18. 9
      iguana/iguana_payments.c
  19. 18
      iguana/iguana_ramchain.c
  20. 9
      iguana/iguana_sign.c
  21. 324
      iguana/iguana_stake.c
  22. 4
      iguana/iguana_tx.c
  23. 2
      iguana/iguana_volatiles.c
  24. 6
      iguana/iguana_wallet.c
  25. 2
      iguana/js/api.js
  26. 59
      iguana/js/blockexplorer.js
  27. 13
      iguana/main.c
  28. 2
      iguana/mingw32
  29. 577
      iguana/mini-gmp.c
  30. 148
      iguana/mini-gmp.h
  31. 20
      iguana/swaps/iguana_BTCswap.c
  32. 2
      iguana/tests/decoderawtransaction
  33. 1
      includes/curve25519.h

3
crypto777/OS_portable.h

@ -364,11 +364,14 @@ char *bits256_lstr(char hexstr[65],bits256 x);
bits256 bits256_add(bits256 a,bits256 b); bits256 bits256_add(bits256 a,bits256 b);
int32_t bits256_cmp(bits256 a,bits256 b); int32_t bits256_cmp(bits256 a,bits256 b);
bits256 bits256_lshift(bits256 x); bits256 bits256_lshift(bits256 x);
bits256 bits256_rshift(bits256 x);
bits256 bits256_from_compact(uint32_t c); bits256 bits256_from_compact(uint32_t c);
uint32_t bits256_to_compact(bits256 x);
bits256 bits256_conv(char *hexstr); bits256 bits256_conv(char *hexstr);
int32_t btc_priv2pub(uint8_t pubkey[33],uint8_t privkey[32]); int32_t btc_priv2pub(uint8_t pubkey[33],uint8_t privkey[32]);
void calc_shares(unsigned char *shares,unsigned char *secret,int32_t size,int32_t width,int32_t M,int32_t N,unsigned char *sharenrs); void calc_shares(unsigned char *shares,unsigned char *secret,int32_t size,int32_t width,int32_t M,int32_t N,unsigned char *sharenrs);
int32_t OS_portable_rmdir(char *dirname,int32_t diralso); int32_t OS_portable_rmdir(char *dirname,int32_t diralso);
void calc_hmac_sha256(uint8_t *mac,int32_t maclen,uint8_t *key,int32_t key_size,uint8_t *message,int32_t len);
extern char *Iguana_validcommands[]; extern char *Iguana_validcommands[];
extern bits256 GENESIS_PUBKEY,GENESIS_PRIVKEY; extern bits256 GENESIS_PUBKEY,GENESIS_PRIVKEY;

6
crypto777/hmac_sha512.c

@ -519,6 +519,12 @@ char *hmac_sha384_str(char *dest,char *key,int32_t key_size,char *message)
return(dest); return(dest);
} }
void calc_hmac_sha256(uint8_t *mac,int32_t maclen,uint8_t *key,int32_t key_size,uint8_t *message,int32_t len)
{
unsigned long size = maclen;
hmac_memory(&sha256_desc,(void *)key,key_size,(void *)message,len,mac,&size);
}
char *hmac_sha256_str(char *dest,char *key,int32_t key_size,char *message) char *hmac_sha256_str(char *dest,char *key,int32_t key_size,char *message)
{ {
unsigned char mac[1024]; unsigned long size = sizeof(mac); unsigned char mac[1024]; unsigned long size = sizeof(mac);

27
crypto777/iguana_utils.c

@ -112,6 +112,18 @@ bits256 bits256_lshift(bits256 x)
return(x); return(x);
} }
bits256 bits256_rshift(bits256 x)
{
int32_t i; uint64_t carry,prevcarry = 0;
for (i=3; i>=0; i--)
{
carry = (1 & x.ulongs[i]) << 63;
x.ulongs[i] = prevcarry | (x.ulongs[i] >> 1);
prevcarry = carry;
}
return(x);
}
bits256 bits256_from_compact(uint32_t c) bits256 bits256_from_compact(uint32_t c)
{ {
uint32_t nbytes,nbits,i; bits256 x; uint32_t nbytes,nbits,i; bits256 x;
@ -124,6 +136,21 @@ bits256 bits256_from_compact(uint32_t c)
return(x); return(x);
} }
uint32_t bits256_to_compact(bits256 x)
{
int32_t i; uint32_t nbits;
for (i=31; i>2; i--)
if ( x.bytes[i] != 0 )
break;
if ( (x.bytes[i] & 0x80) != 0 )
i++;
nbits = x.bytes[i] << 16;
nbits |= x.bytes[i-1] << 8;
nbits |= x.bytes[i-2];
nbits |= ((i+1) << 24);
return(nbits);
}
int32_t bitweight(uint64_t x) int32_t bitweight(uint64_t x)
{ {
int i,wt = 0; int i,wt = 0;

277
crypto777/scrypt.c

@ -0,0 +1,277 @@
/*-
* Copyright 2009 Colin Percival, 2011 ArtForz, 2011 pooler, 2013 Balthazar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file was originally written by Colin Percival as part of the Tarsnap
* online backup system.
*/
#include "../includes/curve25519.h"
#define SCRYPT_BUFFER_SIZE (131072 + 63)
/*
static inline uint32_t be32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) + ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
}
static inline void be32enc(void *pp,uint32_t x)
{
uint8_t *p = (uint8_t *)pp;
p[3] = x & 0xff;
p[2] = (x >> 8) & 0xff;
p[1] = (x >> 16) & 0xff;
p[0] = (x >> 24) & 0xff;
}
void HMAC_SHA256_Init(HMAC_SHA256_CTX *ctx,const void * _K,size_t Klen)
{
size_t i; uint8_t pad[64],khash[32]; const uint8_t * K = (const uint8_t *)_K;
// If Klen > 64, the key is really SHA256(K).
if ( Klen > 64 )
{
SHA256_Init(&ctx->ictx);
SHA256_Update(&ctx->ictx, K, Klen);
SHA256_Final(khash, &ctx->ictx);
K = khash;
Klen = 32;
}
// Inner SHA256 operation is SHA256(K xor [block of 0x36] || data).
SHA256_Init(&ctx->ictx);
memset(pad, 0x36, 64);
for (i = 0; i < Klen; i++)
pad[i] ^= K[i];
SHA256_Update(&ctx->ictx, pad, 64);
// Outer SHA256 operation is SHA256(K xor [block of 0x5c] || hash).
SHA256_Init(&ctx->octx);
memset(pad, 0x5c, 64);
for (i = 0; i < Klen; i++)
pad[i] ^= K[i];
SHA256_Update(&ctx->octx, pad, 64);
// Clean the stack.
memset(khash,0,32);
}
// Add bytes to the HMAC-SHA256 operation.
void HMAC_SHA256_Update(HMAC_SHA256_CTX *ctx,const void *in,size_t len)
{
SHA256_Update(&ctx->ictx,in,len);
}
// Finish an HMAC-SHA256 operation.
void HMAC_SHA256_Final(uint8_t digest[32],HMAC_SHA256_CTX *ctx)
{
uint8_t ihash[32];
SHA256_Final(ihash,&ctx->ictx);
SHA256_Update(&ctx->octx,ihash,32);
SHA256_Final(digest,&ctx->octx);
memset(ihash,0,32);
}
// PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and write the output to buf. The value dkLen must be at most 32 * (2^32 - 1)
void PBKDF2_SHA256(const uint8_t *passwd,size_t passwdlen,const uint8_t *salt,size_t saltlen,uint64_t c,uint8_t *buf,size_t dkLen)
{
HMAC_SHA256_CTX PShctx, hctx;
size_t i,clen; uint8_t ivec[4],U[32],T[32]; uint64_t j; int32_t k;
// Compute HMAC state after processing P and S.
HMAC_SHA256_Init(&PShctx, passwd, passwdlen);
HMAC_SHA256_Update(&PShctx, salt, saltlen);
// Iterate through the blocks.
for (i=0; i*32<dkLen; i++)
{
// Generate INT(i + 1).
be32enc(ivec,(uint32_t)(i + 1));
// Compute U_1 = PRF(P, S || INT(i)).
memcpy(&hctx, &PShctx, sizeof(HMAC_SHA256_CTX));
HMAC_SHA256_Update(&hctx, ivec, 4);
HMAC_SHA256_Final(U, &hctx);
// T_i = U_1 ...
memcpy(T,U,32);
for (j=2; j<=c; j++)
{
// Compute U_j.
HMAC_SHA256_Init(&hctx, passwd, passwdlen);
HMAC_SHA256_Update(&hctx, U, 32);
HMAC_SHA256_Final(U, &hctx);
// ... xor U_j ...
for (k=0; k<32; k++)
T[k] ^= U[k];
}
// Copy as many bytes as necessary into buf
clen = dkLen - i * 32;
if (clen > 32)
clen = 32;
memcpy(&buf[i * 32],T,clen);
}
}*/
// Generic scrypt_core implementation
static inline void xor_salsa8(uint32_t B[16], const uint32_t Bx[16])
{
int32_t i; uint32_t x00,x01,x02,x03,x04,x05,x06,x07,x08,x09,x10,x11,x12,x13,x14,x15;
x00 = (B[0] ^= Bx[0]);
x01 = (B[1] ^= Bx[1]);
x02 = (B[2] ^= Bx[2]);
x03 = (B[3] ^= Bx[3]);
x04 = (B[4] ^= Bx[4]);
x05 = (B[5] ^= Bx[5]);
x06 = (B[6] ^= Bx[6]);
x07 = (B[7] ^= Bx[7]);
x08 = (B[8] ^= Bx[8]);
x09 = (B[9] ^= Bx[9]);
x10 = (B[10] ^= Bx[10]);
x11 = (B[11] ^= Bx[11]);
x12 = (B[12] ^= Bx[12]);
x13 = (B[13] ^= Bx[13]);
x14 = (B[14] ^= Bx[14]);
x15 = (B[15] ^= Bx[15]);
for (i = 0; i < 8; i += 2) {
#define R(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
/* Operate on columns. */
x04 ^= R(x00+x12, 7); x09 ^= R(x05+x01, 7);
x14 ^= R(x10+x06, 7); x03 ^= R(x15+x11, 7);
x08 ^= R(x04+x00, 9); x13 ^= R(x09+x05, 9);
x02 ^= R(x14+x10, 9); x07 ^= R(x03+x15, 9);
x12 ^= R(x08+x04,13); x01 ^= R(x13+x09,13);
x06 ^= R(x02+x14,13); x11 ^= R(x07+x03,13);
x00 ^= R(x12+x08,18); x05 ^= R(x01+x13,18);
x10 ^= R(x06+x02,18); x15 ^= R(x11+x07,18);
/* Operate on rows. */
x01 ^= R(x00+x03, 7); x06 ^= R(x05+x04, 7);
x11 ^= R(x10+x09, 7); x12 ^= R(x15+x14, 7);
x02 ^= R(x01+x00, 9); x07 ^= R(x06+x05, 9);
x08 ^= R(x11+x10, 9); x13 ^= R(x12+x15, 9);
x03 ^= R(x02+x01,13); x04 ^= R(x07+x06,13);
x09 ^= R(x08+x11,13); x14 ^= R(x13+x12,13);
x00 ^= R(x03+x02,18); x05 ^= R(x04+x07,18);
x10 ^= R(x09+x08,18); x15 ^= R(x14+x13,18);
#undef R
}
B[0] += x00;
B[1] += x01;
B[2] += x02;
B[3] += x03;
B[4] += x04;
B[5] += x05;
B[6] += x06;
B[7] += x07;
B[8] += x08;
B[9] += x09;
B[10] += x10;
B[11] += x11;
B[12] += x12;
B[13] += x13;
B[14] += x14;
B[15] += x15;
}
static inline void scrypt_core(uint32_t *X,uint32_t *V)
{
uint32_t i,j,k;
for (i=0; i<1024; i++)
{
memcpy(&V[i * 32],X,128);
xor_salsa8(&X[0],&X[16]);
xor_salsa8(&X[16],&X[0]);
}
for (i=0; i<1024; i++)
{
j = 32 * (X[16] & 1023);
for (k = 0; k < 32; k++)
X[k] ^= V[j + k];
xor_salsa8(&X[0],&X[16]);
xor_salsa8(&X[16],&X[0]);
}
}
/* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output
scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes
r = 1, p = 1, N = 1024
*/
bits256 scrypt_nosalt(const void *input,size_t inputlen,void *scratchpad)
{
uint32_t *V; uint32_t X[32]; bits256 result;
memset(result.bytes,0,sizeof(result));
V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));
calc_hmac_sha256((void *)X,128,(void *)input,(int32_t)inputlen,(void *)input,(int32_t)inputlen);
//PBKDF2_SHA256((const uint8_t *)input,inputlen,(const uint8_t *)input,inputlen,1,(uint8_t *)X,128);
scrypt_core(X,V);
calc_hmac_sha256((void *)result.bytes,sizeof(result),(void *)input,(int32_t)inputlen,(void *)X,128);
//PBKDF2_SHA256((const uint8_t *)input,inputlen,(uint8_t *)X,128,1,(uint8_t*)&result,32);
return result;
}
bits256 scrypt(const void *data,size_t datalen,const void *salt,size_t saltlen,void *scratchpad)
{
uint32_t *V; uint32_t X[32]; bits256 result;
memset(result.bytes,0,sizeof(result));
V = (uint32_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));
calc_hmac_sha256((void *)X,128,(void *)data,(int32_t)datalen,(void *)salt,(int32_t)saltlen);
//PBKDF2_SHA256((const uint8_t *)data,datalen,(const uint8_t *)salt,saltlen,1,(uint8_t *)X,128);
scrypt_core(X,V);
calc_hmac_sha256((void *)result.bytes,sizeof(result),(void *)data,(int32_t)datalen,(void *)X,128);
//PBKDF2_SHA256((const uint8_t *)data,datalen,(uint8_t *)X,128,1,(uint8_t *)&result,32);
return result;
}
bits256 scrypt_hash(const void *input,size_t inputlen)
{
uint8_t scratchpad[SCRYPT_BUFFER_SIZE];
return scrypt_nosalt(input,inputlen,scratchpad);
}
bits256 scrypt_salted_hash(const void *input,size_t inputlen,const void *salt,size_t saltlen)
{
uint8_t scratchpad[SCRYPT_BUFFER_SIZE];
return scrypt(input,inputlen,salt,saltlen,scratchpad);
}
bits256 scrypt_salted_multiround_hash(const void *input,size_t inputlen,const void *salt,size_t saltlen,const uint32_t nRounds)
{
uint32_t i; bits256 resultHash = scrypt_salted_hash(input,inputlen,salt,saltlen);
bits256 transitionalHash = resultHash;
for(i=1; i<nRounds; i++)
{
resultHash = scrypt_salted_hash(input,inputlen,(const void *)&transitionalHash,32);
transitionalHash = resultHash;
}
return resultHash;
}
bits256 scrypt_blockhash(const void *input)
{
uint8_t scratchpad[SCRYPT_BUFFER_SIZE];
return scrypt_nosalt(input,80,scratchpad);
}

2
iguana/SuperNET_category.c

@ -207,7 +207,7 @@ char *bitcoin_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void
char *method="",*agent="",*retstr = 0; int32_t i,j; cJSON *json,*valsobj; struct iguana_info *coin=0; struct iguana_peer *addr; char *method="",*agent="",*retstr = 0; int32_t i,j; cJSON *json,*valsobj; struct iguana_info *coin=0; struct iguana_peer *addr;
if ( (json= cJSON_Parse(ptr)) != 0 ) if ( (json= cJSON_Parse(ptr)) != 0 )
{ {
printf("bitcoinprocess.(%s)\n",jprint(json,0)); //printf("bitcoinprocess.(%s)\n",jprint(json,0));
agent = jstr(json,"agent"); agent = jstr(json,"agent");
method = jstr(json,"method"); method = jstr(json,"method");
valsobj = jobj(json,"vals"); valsobj = jobj(json,"vals");

958
iguana/chart.html

@ -1,168 +1,842 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <!DOCTYPE HTML>
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>amStock Example</title> <title>iguana</title>
<!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/jquery.dropdown.css">
<link rel="stylesheet" type="text/css" href="css/ripples.css">
<!-- Gogole Theme -->
<link rel="stylesheet" type="text/css" href="css/googleFonts.css">
<link rel="stylesheet" type="text/css" href="css/googleIcons.css">
<link rel="stylesheet" type="text/css" href="css/googleTheme.css">
<link rel="stylesheet" href="js/amcharts/style.css" type="text/css"> <link rel="stylesheet" href="js/amcharts/style.css" type="text/css">
<script src="js/amcharts/amcharts.js" type="text/javascript"></script> <script src="js/amcharts/amcharts.js" type="text/javascript"></script>
<script src="js/amcharts/serial.js" type="text/javascript"></script> <script src="js/amcharts/serial.js" type="text/javascript"></script>
<script src="js/amcharts/amstock.js" type="text/javascript"></script> <script src="js/amcharts/amstock.js" type="text/javascript"></script>
<script src="js/amcharts/plugins/dataloader/dataloader.min.js" type="text/javascript"></script>
<script> <script>
AmCharts.ready(function () {
generateChartData();
createStockChart();
});
var httpresult;
function http_handler()
{
if ( this.status == 200 && this.responseText != null )
{
alert(this.responseText);
httpresult = this.responseText;
}
}
function httpGet(url)
{
var client;
if ( window.XMLHttpRequest )
client = new XMLHttpRequest();
else client = new ActiveXObject(\"Microsoft.XMLHTTP\");
client.onload = http_handler;
client.open(\"GET\",url);
client.send();
}
AmCharts.ready(function () { createStockChart(); });
var interval,BASE= "BTCD",REL = "BTC";
function createStockChart() {
var chartData = []; var chartData = [];
var chart = AmCharts.makeChart("chartdiv",
{
"type": "serial",
"theme": "dark",
"valueAxes": [
{ "title":"BTC", "id": "vert", "axisAlpha": 0, "dashLength": 1, "position": "left"},
{ "id": "horiz", "axisAlpha": 0, "dashLength": 1, "position": "bottom", "labelFunction": function (value) {
var date = new Date(value);
return AmCharts.formatDate(date, "MMM DD HH:NN:SS");
}}
],
"graphs": [
{ "id": "g1", "lineColor": "#00FFFF", "bullet": "round", "valueField": "bid", "balloonText": "[[category]] [[h]]:[[m]]:[[s]] account:[[offerer]] id:[[orderid]] volume:[[volume]] bid:[[bid]]" },
{ "id": "g2", "lineColor": "#FF8800", "bullet": "round", "valueField": "ask", "balloonText": "[[category]] [[h]]:[[m]]:[[s]] account:[[offerer]] id:[[orderid]] volume:[[volume]] ask:[[ask]]" }],
"categoryField": "date",
"categoryAxis": { "parseDates": true, "equalSpacing": true, "dashLength": 1, "minorGridEnabled": true },
"chartScrollbar": {},
"chartCursor": {},
"dataProvider": chartData
});
function generateChartData() { var startButton = document.getElementById('start');
var firstDate = new Date(2012, 0, 1); var endButton = document.getElementById('stop');
firstDate.setDate(firstDate.getDate() - 1000); var buyButton = document.getElementById('buy');
firstDate.setHours(0, 0, 0, 0); var sellButton = document.getElementById('sell');
/*
var BTCbutton = document.getElementById('BTC');
var CNYbutton = document.getElementById('CNY');
var USDbutton = document.getElementById('USD');
var EURbutton = document.getElementById('EUR');
var JPYbutton = document.getElementById('JPY');
var GBPbutton = document.getElementById('GBP');
var AUDbutton = document.getElementById('AUD');
var CADbutton = document.getElementById('CAD');
var CHFbutton = document.getElementById('CHF');
var NZDbutton = document.getElementById('NZD');
for (var i = 0; i < 1000; i++) { USDbutton.addEventListener('click', USDrel);
var newDate = new Date(firstDate); EURbutton.addEventListener('click', EURrel);
newDate.setHours(0, i, 0, 0); JPYbutton.addEventListener('click', JPYrel);
GBPbutton.addEventListener('click', GBPrel);
AUDbutton.addEventListener('click', AUDrel);
CADbutton.addEventListener('click', CADrel);
CHFbutton.addEventListener('click', CHFrel);
NZDbutton.addEventListener('click', NZDrel);
CNYbutton.addEventListener('click', CNYrel);
BTCbutton.addEventListener('click', BTCrel);
*/
var a = Math.round(Math.random() * (40 + i)) + 100 + i; var BTCDbutton = document.getElementById('BTCD');
var b = Math.round(Math.random() * 100000000); var VPNbutton = document.getElementById('VPN');
var VRCbutton = document.getElementById('VRC');
var SYSbutton = document.getElementById('SYS');
var SuperNETbutton = document.getElementById('SuperNET');
var crypto777button = document.getElementById('crypto777');
var pangeabutton = document.getElementById('Pangea');
var InstantDEXbutton = document.getElementById('InstantDEX');
var Tradebotsbutton = document.getElementById('Tradebots');
var NXTprivacybutton = document.getElementById('NXTprivacy');
chartData.push({
date: newDate, startButton.addEventListener('click', startDemo);
value: a, endButton.addEventListener('click', endDemo);
volume: b buyButton.addEventListener('click', buyaction);
}); sellButton.addEventListener('click', sellaction);
BTCDbutton.addEventListener('click', BTCDbase);
VPNbutton.addEventListener('click', VPNbase);
SYSbutton.addEventListener('click', SYSbase);
SuperNETbutton.addEventListener('click', SuperNETbase);
crypto777button.addEventListener('click', crypto777base);
pangeabutton.addEventListener('click', Pangeabase);
InstantDEXbutton.addEventListener('click', InstantDEXbase);
Tradebotsbutton.addEventListener('click', Tradebotsbase);
NXTprivacybutton.addEventListener('click', NXTprivacybase);
function changebase(newbase)
{
BASE = newbase;
if ( chartData.length > 0 )
{
chartData.splice(0,chartData.length);
chart.validateData();
} }
} }
function BTCDbase() { changebase("BTCD"); }
function VPNbase() { changebase("VPN"); }
function SYSbase() { changebase("SYS"); }
function SuperNETbase() { changebase("SuperNET"); }
function crypto777base() { changebase("crypto777"); }
function Pangeabase() { changebase("Pangea"); }
function InstantDEXbase() { changebase("InstantDEX"); }
function Tradebotsbase() { changebase("Tradebots"); }
function NXTprivacybase() { changebase("NXTprivacy"); }
var chart; function USDrel() { REL = "USD"; }
function EURrel() { REL = "EUR"; }
function JPYrel() { REL = "JPY"; }
function GBPrel() { REL = "GBP"; }
function AUDrel() { REL = "AUD"; }
function CADrel() { REL = "CAD"; }
function CHFrel() { REL = "CHF"; }
function NZDrel() { REL = "NZD"; }
function CNYrel() { REL = "CNY"; }
function BTCrel() { REL = "CNY"; }
function startDemo() {
startButton.disabled = "disabled";
endButton.disabled = "";
interval = setInterval(getDataFromServer, 1000);
}
function endDemo() {
startButton.disabled = "";
endButton.disabled = "disabled";
clearInterval(interval);
}
function buyaction() {
alert("need to do market buy");
}
function sellaction() {
alert("need to do market sell");
}
function getDataFromServer()
{
var i,newData = [];
var request='{"agent":"InstantDEX","method":"events","base":"'+BASE+'","rel":"'+REL+'"}';
SPNAPI.makeRequest(request,
function(request,response)
{
newData = JSON.parse(response);
if ( newData.length > 0 )
{
alert(response);
chartData.push.apply(chartData, newData);
if (chartData.length > 50)
chartData.splice(0, chartData.length - 50);
chart.validateData(); //call to redraw the chart with new data
}
});
// newData = JSON.parse("[{\"h\":14,\"m\":44,\"s\":32,\"date\":1407877200000,\"bid\":30,\"ask\":35},{\"date\":1407877200000,\"bid\":40,\"ask\":44},{\"date\":1407877200000,\"bid\":49,\"ask\":45},{\"date\":1407877200000,\"ask\":28},{\"date\":1407877200000,\"ask\":52}]");
}
function createStockChart() {
chart = new AmCharts.AmStockChart();
// As we have minutely data, we should set minPeriod to "mm"
var categoryAxesSettings = new AmCharts.CategoryAxesSettings();
categoryAxesSettings.minPeriod = "mm";
chart.categoryAxesSettings = categoryAxesSettings;
// DATASETS //////////////////////////////////////////
var dataSet = new AmCharts.DataSet();
dataSet.color = "#b0de09";
dataSet.fieldMappings = [{
fromField: "value",
toField: "value"
}, {
fromField: "volume",
toField: "volume"
}];
dataSet.dataProvider = chartData;
dataSet.categoryField = "date";
// set data sets to the chart
chart.dataSets = [dataSet];
// PANELS ///////////////////////////////////////////
// first stock panel
var stockPanel1 = new AmCharts.StockPanel();
stockPanel1.showCategoryAxis = false;
stockPanel1.title = "Value";
stockPanel1.percentHeight = 70;
// graph of first stock panel
var graph1 = new AmCharts.StockGraph();
graph1.valueField = "value";
graph1.type = "smoothedLine";
graph1.lineThickness = 2;
graph1.bullet = "round";
graph1.bulletBorderColor = "#FFFFFF";
graph1.bulletBorderAlpha = 1;
graph1.bulletBorderThickness = 3;
stockPanel1.addStockGraph(graph1);
// create stock legend
var stockLegend1 = new AmCharts.StockLegend();
stockLegend1.valueTextRegular = " ";
stockLegend1.markerType = "none";
stockPanel1.stockLegend = stockLegend1;
// second stock panel
var stockPanel2 = new AmCharts.StockPanel();
stockPanel2.title = "Volume";
stockPanel2.percentHeight = 30;
var graph2 = new AmCharts.StockGraph();
graph2.valueField = "volume";
graph2.type = "column";
graph2.cornerRadiusTop = 2;
graph2.fillAlphas = 1;
stockPanel2.addStockGraph(graph2);
// create stock legend
var stockLegend2 = new AmCharts.StockLegend();
stockLegend2.valueTextRegular = " ";
stockLegend2.markerType = "none";
stockPanel2.stockLegend = stockLegend2;
// set panels to the chart
chart.panels = [stockPanel1, stockPanel2];
// OTHER SETTINGS ////////////////////////////////////
var scrollbarSettings = new AmCharts.ChartScrollbarSettings();
scrollbarSettings.graph = graph1;
scrollbarSettings.usePeriod = "10mm"; // this will improve performance
scrollbarSettings.updateOnReleaseOnly = false;
scrollbarSettings.position = "top";
chart.chartScrollbarSettings = scrollbarSettings;
var cursorSettings = new AmCharts.ChartCursorSettings();
cursorSettings.valueBalloonsEnabled = true;
chart.chartCursorSettings = cursorSettings;
// PERIOD SELECTOR ///////////////////////////////////
var periodSelector = new AmCharts.PeriodSelector();
periodSelector.position = "top";
periodSelector.dateFormat = "YYYY-MM-DD JJ:NN";
periodSelector.inputFieldWidth = 150;
periodSelector.periods = [{
period: "hh",
count: 1,
label: "1 hour"
}, {
period: "hh",
count: 2,
label: "2 hours"
}, {
period: "hh",
count: 5,
label: "5 hour"
}, {
period: "hh",
count: 12,
label: "12 hours"
}, {
period: "MAX",
label: "MAX"
}];
chart.periodSelector = periodSelector;
var panelsSettings = new AmCharts.PanelsSettings();
panelsSettings.mouseWheelZoomEnabled = true;
panelsSettings.usePrefixes = true;
chart.panelsSettings = panelsSettings;
chart.write('chartdiv');
} }
</script> </script>
</head> </head>
<body style="background-color:#FFFFFF">
<div id="chartdiv" style="width:100%; height:600px;"></div> <body data-custom-load="true" data-name="iguana" data-tools="pnacl newlib glibc clang-newlib mac" data-configs="Debug Release"
data-path="{tc}/{config}">
<!-- <div class="jumbotron" style="height:100px;">
<h> Status: <code id="statusField">NO-STATUS</code></h>
<p>
<select id="pipe_name" hidden>
<option>urand</option>
<option>Pangea</option>
<option>MGW</option>
</select>
<input type="text" id="pipe_input_box" hidden>
</p>
<p><textarea id="pipe_output" hidden></textarea></p>
</div> -->
<div class="iguana">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse">
<!--Hamburger-->
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!--<a class="navbar-brand" href="#">
<img alt="Brand" style="z-index:-1;" src="logo.png" width="25" height="25">
</a>-->
<a href="#" class="navbar-brand">Iguana</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse">
<ul class="nav navbar-nav">
<li id="welcome"> <!--<a href="#">Welcome <span class="sr-only">(current)</span></a>--></li>
<!--<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">More <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Wiki</a></li>
<li><a href="#">Wallet</a></li>
<li><a href="#">Community</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Contact</a></li>
<li role="separator" class="divider"></li>
<li><a>Upload Conf<input type="file" id="files" name="file" /></a></li>
<div id="byte_range"></div>
<div id="byte_content"></div>
</ul>
</li>-->
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<div class="container">
<!--<div id="welcome_page" class="page" style="text-align: center;">
<div class="panel panel-default">
<!-- Default panel contents
<div class="panel-heading">Welcome</div>
<div class="panel-body">
<h2>iguana</h2>
<p>
iguana is fast.
</p>
<p>
iguana does all bitcoin compatibles.
</p>
<p>
iguana is fast.
</p>
</div>
</div>
</div>-->
<!-- eyedea page is for creating front-end markup -->
<div id="Pangea_page" class="page">
<div class="row" style="margin-bottom:15px;">
<div class="col-xs-4 col-sm-3 col-md-2">
<div class="api-navpills">
</div>
</div>
<div class="col-xs-8 col-sm-9 col-md-10">
<div class="panel-group">
<div class="panel panel-default api-call-All">
<div class="panel-heading">
<h4 class="panel-title api-panel-title">Json posting form</h4>
</div>
<!-- panel-heading -->
<div class="panel-body">
<div class="row">
<div class="col-xs-9 col-sm-10 col-md-8">
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<textarea name="json_to_submit" id="json_src" cols="30" rows="5" class="result form-control" placeholder='Paste json here'></textarea>
</div>
<div class="form-group">
<button class="btn btn-primary host_pangea_request" id='submit_primary'>Host game</button>
<button class="btn btn-primary list_pangea_request" id='list_pangea'>List games</button>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-md-4 col-lg-4">
<div class="panel-body">
<h5 class='uri-link'>Response</h5>
<pre class="hljs json result">JSON response</pre>
<button class="btn btn-default clear-response">Clear response</button>
</div>
</div>
</div>
<hr>
<h3>
<span>List of games</span>
<!--<button id="clearHistory" style='float: right' class='btn btn-default'>Clear history</button>-->
</h3>
<div class="row">
<div class="col-md-12">
<table class="table" id='game_list_table'>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<!-- panel-body -->
</div>
</div>
</div>
</div>
</div>
<!--Coin Management Starts-->
<div id="Coins_page" class="page">
<div class="panel panel-default">
<div class="panel-heading">
<h3>Coin Management</h3>
</div>
<div class="panel-body">
<div class="pull-right">
<button id="Coins_reset" class="btn btn-raised" title="Reset">Reset</button>
<button id="Coins_refresh" class="btn btn-raised" title="Refresh">Refresh</button>
<button id="Coins_add" class="btn btn-raised btn-primary" type="button" data-toggle="modal" data-target="#CoinEditModal" title="Add">Add</button>
</div>
<table id="Coins_table" class="table table-hover table-condensed table-bordered ">
<thead>
<tr>
<th>Symbol</th>
<th>Description</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<!--Modal starts-->
<div class="modal fade" id="CoinEditModal" tabindex="-1" role="dialog" aria-labelledby="editCoinHeader">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="editCoinHeader">Edit Coin</h4>
</div>
<div class="modal-body">
<div id="coinEditFormContainer">
<form class="form-horizontal" id="frmCoinEdit" name="frmCoinEdit">
<div id="txtSymbolGroup" class="form-group">
<label for="txtSymbol" class="control-label col-xs-2 col-md-2">Symbol</label>
<div class="col-xs-10 col-md-10">
<input type="text" id="txtSymbol" name="txtSymbol" class="form-control input-sm" />
</div>
</div>
<div id="txtDescriptionGroup" class="form-group">
<label for="txtDescription" class="control-label col-xs-2 col-md-2">Description</label>
<div class="col-xs-10 col-md-10">
<input type="text" id="txtDescription" name="txtDescription" class="form-control input-sm" />
</div>
</div>
<div id="ddCoinStatus" class="form-group">
<label for="ddStatus" class="control-label col-xs-2 col-md-2">Status</label>
<div class="col-xs-10 col-md-10">
<select type="text" id="ddStatus" name="ddStatus" class="form-control input-sm"></select>
</div>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button id="btnClearCoinForm" type="button" class="btn btn-raised btn-default" data-dismiss="modal">Nevermind</button>
<button id="btnSaveCoinForm" type="button" class="btn btn-raised btn-primary" data-dismiss="modal">Save</button>
<!-- <button id="btnSaveCoinForm" type="button" class="btn btn-primary">Save</button> -->
</div>
</div>
</div>
</div>
<!--Modal Ends-->
<div class="row">
<div class="col-xs-9 col-sm-10 col-md-8">
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<textarea id="json_src_coin" cols="30" rows="5" class="result form-control" placeholder='Paste json here'></textarea>
</div>
<div class="form-group">
<button class="btn btn-primary submit_new_coin_test" >Add coin</button>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-md-4 col-lg-4">
<div class="panel-body">
<h5 class='uri-link'>Response</h5>
<pre class="hljs json coin_result">JSON response</pre>
<button class="btn btn-default clear-response-coin">Clear response</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!--Coin Management Ends-->
<!-- peers tab -->
<div id="Peers_page" class="page">
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<h3>
<span>Peer Management</span>
</h3>
</div>
<div class="panel-body"><div>
<button class="btn btn-xs btn-success btn-raised connect_to_peers_from_conf" >Load peers</button>
<button class="btn btn-xs btn-success btn-raised save_peersdata_to_conf" >Save Peers</button>
<button class="btn btn-xs btn-success btn-raised update_allpeer_status" >Update Peers</button>
<div class="pull-right">
<span class="checkbox"><label><input id="cbShowFavoritePeers" type="checkbox"/> Favorites</label></span>
</div></div><div class="pre-scrollable">
<table id="peersTable" class="table table-hover table-bordered pre-scrollable">
<thead>
<tr>
<th>IP Address</th>
<th>Coin Type</th>
<th>Height</th>
<th>Rank</th>
<th>Block</th>
<th>Favourite </th>
<th>Actions</th>
</tr>
</thead>
<tbody id="peersTableBody"></tbody>
</table></div>
</div>
</div>
</div>
</div>
<div id="Tradebot_page" class="page">
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<h3>
<span>Tradebot</span>
</h3>
</div>
<div class="panel-body center button_div">
<button class="btn btn-primary Tradebot_set_method_table" data-method="monitor" >monitor</button>
<button class="btn btn-primary Tradebot_set_method_table" data-method="monitorall" >monitorall</button>
<button class="btn btn-primary Tradebot_set_method_table" data-method="unmonitor" >unmonitor</button>
<button class="btn btn-primary Tradebot_set_method_table" data-method="accumulate" >accumulate</button>
<button class="btn btn-primary Tradebot_set_method_table" data-method="divest" >divest</button>
<button class="btn btn-primary Tradebot_set_method_table" data-method="activebots" >activebots</button>
<button class="btn btn-primary Tradebot_set_method_table" data-method="status" >status</button>
<button class="btn btn-primary Tradebot_set_method_table" data-method="pause" >pause</button>
<button class="btn btn-primary Tradebot_set_method_table" data-method="stop" >stop</button>
<button class="btn btn-primary Tradebot_set_method_table" data-method="resume" >resume</button>
</div>
<div class="panel-body">
<table id="tradebot_input" class="table table-hover table-bordered">
</table>
<table id="trade_output" class="table table-hover table-bordered">
</table>
</div>
</div>
</div>
</div>
<div id="Settings_page" class="page">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Settings</h3>
</div>
<div class="panel-body" >
<div class="row">
<div class="pre-scrollable">
<div class="col-xs-6 col-md-6 col-lg-6 ">
<div id="advanced_settings"></div>
</div>
<div class="col-xs-6 col-md-6 col-lg-6">
<div id="config_settings"></div>
<div class="function" id="fread" hidden>
<span>
<select class="file-handle" id="freadHandle"></select>
Count:
<input type="text" id="freadBytes">
<button>fread</button>
</span>
</div>
<div class="function" id="fwrite" hidden>
<span>
<select class="file-handle" id="fwriteHandle"></select>
Data:
<input type="text" id="fwriteData">
<button>fwrite</button>
</span>
</div>
</div></div>
</div>
<div class="row">
<div class="col-xs-6 col-md-6 col-lg-6">
<div class="form-group">
<button class="btn btn-primary _not_pressed" id="save_settings">Save</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="Debug_page" class="page">
<div class='panel panel-default'>
<div class='panel-heading'>
<h3><span>
Encrypt/decrypt JSON
</span></h3>
</div>
<div class='panel-body'>
<div class="row">
<div class="col-sm-8 col-md-8">
<form class="form-horizontal">
<div class="form-group">
<label for="debug_passphrase" class="control-label col-sm-3 col-md-3">
Passphrase
</label>
<div class="col-sm-7 col-md-7">
<input type="text" class="form-control" id='debug_passphrase'>
<span class='material-input'></span>
</div>
</div>
<div class="form-group">
<label for="debug_permanentfile" class="control-label col-sm-3 col-md-3">
Permanentfile
</label>
<div class="col-sm-7 col-md-7">
<div>
<input type="text" class="form-control" id='debug_permanentfile'>
</div>
</div>
</div>
<div class="form-group">
<label for="debug_json_src" class="control-label col-sm-3 col-md-3">
Json
</label>
<div class="col-sm-7 col-md-7">
<textarea name="" id="debug_json_src" cols="30" rows="5" class='form-control'></textarea>
<span class='material-input'></span>
</div>
</div>
<div class="form-group">
<button class="btn btn-primary" id="debug_json_encrypt">
Encrypt JSON
</button>
<button class="btn btn-primary" id="debug_json_decrypt">
Decrypt JSON
</button>
</div>
</form>
</div>
<div class="col-sm-4 col-md-4">
<h5 class="uri-link">Response</h5>
<pre class="hljs json coin_result" id="debug_json_result">JSON response</pre>
<h5 class="uri-link">File contents</h5>
<pre class="hljs" id="debug_json_file">encrypted file content</pre>
<button class="btn btn-default" id="debug_clear_response">Clear response</button>
</div>
</div>
</div>
</div>
<div class="jumbotron">
<table>
<tr >
<td><img src="" height="90" width="90" class="imagAPI" data-id="1" id="dest-imagAPI-1" /></td>
<td><img src="" height="90" width="90" class="imagAPI" data-id="2" id="dest-imagAPI-2"/></td>
<td><img src="" height="90" width="90" class="imagAPI" data-id="3" id="dest-imagAPI-3" /></td>
<td><img src="" height="90" width="90" class="imagAPI" data-id="4" id="dest-imagAPI-4" /></td>
<td><img src="" height="90" width="90" class="imagAPI" data-id="5" id="dest-imagAPI-5" /></td>
<td><img src="" height="90" width="90" class="imagAPI" data-id="6" id="dest-imagAPI-6" /></td>
<td><img src="" height="90" width="90" class="imagAPI" data-id="7" id="dest-imagAPI-7" /></td>
<td><img src="" height="90" width="90" class="imagAPI" data-id="8" id="dest-imagAPI-8" /></td>
<td><img src="" height="90" width="90" class="imagAPI" data-id="9" id="dest-imagAPI-9" /></td>
<td><img src="" height="90" width="90" class="imagAPI" data-id="10" id="dest-imagAPI-10" /></td>
</tr>
<tr>
<td align="center" ><input id="name-imagAPI-1" type="text" value="abc1.jpg" size="7"/></td>
<td align="center" ><input id="name-imagAPI-2" type="text" value="abc2.jpg" size="7"/></td>
<td align="center" ><input id="name-imagAPI-3" type="text" value="abc3.jpg" size="7"/></td>
<td align="center" ><input id="name-imagAPI-4" type="text" value="abc4.jpg" size="7"/></td>
<td align="center" ><input id="name-imagAPI-5" type="text" value="abc5.jpg" size="7"/></td>
<td align="center" ><input id="name-imagAPI-6" type="text" value="abc6.jpg" size="7"/></td>
<td align="center" ><input id="name-imagAPI-7" type="text" value="abc7.jpg" size="7"/></td>
<td align="center" ><input id="name-imagAPI-8" type="text" value="abc8.jpg" size="7"/></td>
<td align="center" ><input id="name-imagAPI-9" type="text" value="abc9.jpg" size="7"/></td>
<td align="center" ><input id="name-imagAPI-10" type="text" value="abc10.jpg" size="7"/></td>
</tr>
<tr style="display: none;">
<td><img src="images/img1.png" height="90" width="90" id="src-imagAPI-1" /></td>
<td><img src="images/img2.jpg" height="90" width="90" id="src-imagAPI-2" /></td>
<td><img src="images/img3.png" height="90" width="90" id="src-imagAPI-3" /></td>
<td><img src="images/img4.png" height="90" width="90" id="src-imagAPI-4" /></td>
<td><img src="images/img1.png" height="90" width="90" id="src-imagAPI-5" /></td>
<td><img src="images/img2.jpg" height="90" width="90" id="src-imagAPI-6" /></td>
<td><img src="images/img3.png" height="90" width="90" id="src-imagAPI-7" /></td>
<td><img src="images/img4.png" height="90" width="90" id="src-imagAPI-8" /></td>
<td><img src="images/img1.png" height="90" width="90" id="src-imagAPI-9" /></td>
<td><img src="images/img2.jpg" height="90" width="90" id="src-imagAPI-10" /></td>
</tr>
<tr><td colspan="10">
<span id="mousexy"></span>
</td>
</tr>
</table>
<div class="debuglog" hidden> <pre id="log" style="font-weight: bold"></pre></div>
</div>
</div>
<div id="Bitmap_page" class="page">
<div>
<select id="pic-changer">
<option value="none">None selected</option>
<option value="img3.jpg" data-picture="images/img3.png">Image1</option>
</select>
</div>
<div id="image-location">
</div>
<div>
<span id="bit_mousexy"></span>
</div>
</div>
<div id="Blockexplorer_page" class="page">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">
<h3>Block Explorer tab</h3>
</div>
<div class="panel-body center">
<div class="pull-right">
<span class="checkbox"><label><input id="cbChangeExternalBlocks" type="checkbox"/> Use External Blocks</label></span>
</div>
<h3>Set Active coin</h3>
<div id="BlockExpCoin">
</div>
<div >
<table id="block_input_table"></table>
</div>
<div>
<table id="block_output_table" width="500px">
</table>
</div>
<table id="appstatus" class="table table-hover table-bordered">
</table>
</div>
</div>
<style type="text/css">
#Blockexplorer_page .center {
text-align: center;
}
</style>
</div>
<div id="Instandex_page" class="page">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">
<h3>InstantDEX</h3>
<div class="chart">
<button id="start">Start</button>
<button id="stop" disabled="disabled">Stop </button>
<button id="BTCD"> BTCD</button>
<button id="VPN">VPN</button>
<button id="SYS">SYS</button>
<button id="VRC">VRC</button>
<button id="SuperNET">SuperNET</button>
<button id="crypto777">crypto777</button>
<button id="InstantDEX">InstantDEX</button>
<button id="Tradebots">Tradebots</button>
<button id="Pangea">Pangea</button>
<button id="NXTprivacy">NXTprivacy</button>
<button id="buy">BUY</button>
<button id="sell">SELL</button>
<div id="chartdiv"></div>
</div>
</div><div class="pre-scrollable">
<div class="panel-body center">
<button class="btn xyz_button_click btn-primary instantdex_set_method_table" data-method="orderbook" >orderbook</button>
<button class="btn xyz_button_click btn-primary instantdex_set_method_table" data-method="apikeypair" >API Keypair</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="setuserid" >Set Userid</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="allpairs" >Allpairs</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="balance" >Balance</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="support" >Supports</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="sell" >Sell</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="buy" >Buy</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="withdraw" >Withdraw</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="order_status" >Order status </button>
<button class="btn btn-primary instantdex_set_method_table" data-method="order_open" >Open Orders</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="order_cancel" >Cancel Order</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="trade_history" >Trade History</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="pollgap" >Pollgap</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="tradeint" >Trade integration</button>
</div>
<div class="panel-body center">
<table id="Instandex_form_table" class="table table-hover table-bordered">
</table>
</div>
<div class="panel-body center">
<table id="Instandex_output_table" class="table table-hover table-bordered" >
</table>
</div></div>
</div>
<style type="text/css">
#Blockexplorer_page .center {
text-align: center;
}
</style>
</div>
<div id="listener"></div>
</div>
</div>
<!--if android style ripple effect is not working, try temporarily deleting the following line-->
<script type="text/javascript " src="example.js "></script>
<!--jQuery-->
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<!--Bootstrap-->
<script type="text/javascript" src="js/bootstrap.js"></script>
<!--Google Theme-->
<script type="text/javascript" src='js/googleTheme.min.js'></script>
<script type="text/javascript" src='js/ripples.min.js'></script>
<script type="text/javascript" src='js/jquery.dropdown.js'></script>
<!--Iguana genric code-->
<script type="text/javascript" src="js/api.js" " charset="utf-8 "></script>
<script src="app/coin_mgmt.js "></script>
<script type="text/javascript " src="js/util.js "></script>
<script type="text/javascript " src="js/sites.js " charset="utf-8 "></script>
<script type="text/javascript " src="app/common.js "></script>
<script type="text/javascript " src="app/startup.js " ></script>
<script type="text/javascript " src="js/settings.js " charset="utf-8 "></script>
<!--Iguana tabs-->
<script src='js/form.js'></script>
<script type="text/javascript " src='js/peerlist.js'></script>
<script type="text/javascript " src="js/methods.js " charset="utf-8 "></script>
<script type="text/javascript " src="js/imgAPI.js " ></script>
<script type="text/javascript " src="js/pangea.js" ></script>
<script type="text/javascript " src="js/blockexplorer.js" ></script>
<script type="text/javascript " src="js/instantdex.js" ></script>
<script type="text/javascript " src="js/tradebot.js" ></script>
<script type="text/javascript " src="js/storage.js" ></script>
<script type="text/javascript " src="js/jquery.tablesort.js" ></script>
<script type="text/javascript " src="js/tradeintegration.js" ></script>
<script type="text/javascript " src="js/debugJson.js" ></script>
<script type="text/javascript " src="js/bitmap.js " ></script>
</body> </body>
</html> </html>

1
iguana/exchanges777.h

@ -200,5 +200,6 @@ struct bitcoin_swapinfo *instantdex_statemachinefind(struct supernet_info *myinf
char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *json); char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *json);
void tradebot_timeslices(struct exchange_info *exchange); void tradebot_timeslices(struct exchange_info *exchange);
struct instantdex_stateinfo *BTC_initFSM(int32_t *n); struct instantdex_stateinfo *BTC_initFSM(int32_t *n);
struct bitcoin_statetx *instantdex_feetx(struct supernet_info *myinfo,struct instantdex_accept *A,struct bitcoin_swapinfo *swap,struct iguana_info *coin);
#endif #endif

3
iguana/iguana777.c

@ -492,7 +492,10 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert
else hdrsi = coin->origbalanceswritten; else hdrsi = coin->origbalanceswritten;
for (i=0; i<max; i++) for (i=0; i<max; i++)
if ( (bp= coin->bundles[i]) != 0 && bp != coin->current ) if ( (bp= coin->bundles[i]) != 0 && bp != coin->current )
{
iguana_volatilespurge(coin,&bp->ramchain);
iguana_volatilesalloc(coin,&bp->ramchain,i < hdrsi); iguana_volatilesalloc(coin,&bp->ramchain,i < hdrsi);
}
for (; hdrsi<max; hdrsi++) for (; hdrsi<max; hdrsi++)
{ {
if ( (bp= coin->bundles[hdrsi]) != 0 ) if ( (bp= coin->bundles[hdrsi]) != 0 )

14
iguana/iguana777.h

@ -218,6 +218,7 @@ struct iguana_chain
char userhome[512],serverport[128],userpass[1024]; char userhome[512],serverport[128],userpass[1024];
char use_addmultisig,do_opreturn; char use_addmultisig,do_opreturn;
int32_t estblocktime; int32_t estblocktime;
bits256 PoWtarget,PoStargets[16]; int32_t numPoStargets,PoSheights[16];
}; };
struct iguana_msgaddress { uint32_t nTime; uint64_t nServices; uint8_t ip[16]; uint16_t port; } __attribute__((packed)); struct iguana_msgaddress { uint32_t nTime; uint64_t nServices; uint8_t ip[16]; uint16_t port; } __attribute__((packed));
@ -572,8 +573,8 @@ int32_t iguana_rwmem(int32_t rwflag,uint8_t *serialized,int32_t len,void *endian
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
int32_t iguana_rwvarint32(int32_t rwflag,uint8_t *serialized,uint32_t *int32p); int32_t iguana_rwvarint32(int32_t rwflag,uint8_t *serialized,uint32_t *int32p);
int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp); int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp);
int32_t iguana_rwblock(int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg); int32_t iguana_rwblock(int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg);
int32_t iguana_serialize_block(bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block); int32_t iguana_serialize_block(struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block);
void iguana_blockconv(struct iguana_block *dest,struct iguana_msgblock *msg,bits256 hash2,int32_t height); void iguana_blockconv(struct iguana_block *dest,struct iguana_msgblock *msg,bits256 hash2,int32_t height);
//void iguana_freetx(struct iguana_msgtx *tx,int32_t n); //void iguana_freetx(struct iguana_msgtx *tx,int32_t n);
int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t datalen); int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t datalen);
@ -620,6 +621,8 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi
bits256 iguana_blockhash(struct iguana_info *coin,int32_t height); bits256 iguana_blockhash(struct iguana_info *coin,int32_t height);
#define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0) #define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0)
struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag); struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag);
struct iguana_block *iguana_prevblock(struct iguana_info *coin,struct iguana_block *block,int32_t PoSflag);
uint32_t iguana_targetbits(struct iguana_info *coin,struct iguana_block *hwmchain,struct iguana_block *prev,struct iguana_block *prev2,int32_t PoSflag);
uint32_t iguana_syncs(struct iguana_info *coin); uint32_t iguana_syncs(struct iguana_info *coin);
void iguana_gotdata(struct iguana_info *coin,struct iguana_peer *addr,int32_t height); void iguana_gotdata(struct iguana_info *coin,struct iguana_peer *addr,int32_t height);
@ -801,7 +804,7 @@ int32_t SuperNET_sendmsg(struct supernet_info *myinfo,struct iguana_info *coin,s
int32_t category_peer(struct supernet_info *myinfo,struct iguana_peer *addr,bits256 category,bits256 subhash); int32_t category_peer(struct supernet_info *myinfo,struct iguana_peer *addr,bits256 category,bits256 subhash);
int32_t bitcoin_wif2priv(uint8_t *addrtypep,bits256 *privkeyp,char *wifstr); int32_t bitcoin_wif2priv(uint8_t *addrtypep,bits256 *privkeyp,char *wifstr);
int32_t bitcoin_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype); int32_t bitcoin_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype);
bits256 iguana_chaingenesis(bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t bits,uint32_t nonce,bits256 merkle_root); bits256 iguana_chaingenesis(int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t bits,uint32_t nonce,bits256 merkle_root);
int32_t iguana_send_ConnectTo(struct iguana_info *coin,struct iguana_peer *addr); int32_t iguana_send_ConnectTo(struct iguana_info *coin,struct iguana_peer *addr);
cJSON *iguana_txjson(struct iguana_info *coin,struct iguana_txid *tx,int32_t height,struct vin_info *V); cJSON *iguana_txjson(struct iguana_info *coin,struct iguana_txid *tx,int32_t height,struct vin_info *V);
char *iguana_txscan(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t recvlen,bits256 txid); char *iguana_txscan(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t recvlen,bits256 txid);
@ -984,8 +987,11 @@ struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana
void instantdex_FSMinit(); void instantdex_FSMinit();
void iguana_unspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins); void iguana_unspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins);
char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf); char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf);
char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx); char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkey);
char *iguana_pollrawtx(queue_t *Q,cJSON **vinsp,uint32_t rawtxtag,double expiration); char *iguana_pollrawtx(queue_t *Q,cJSON **vinsp,uint32_t rawtxtag,double expiration);
bits256 scrypt_blockhash(const void *input);
bits256 iguana_calcblockhash(int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),uint8_t *serialized,int32_t len);
uint32_t iguana_targetbits(struct iguana_info *coin,struct iguana_block *hwmchain,struct iguana_block *prev,struct iguana_block *prev2,int32_t PoSflag);
extern int32_t HDRnet,netBLOCKS; extern int32_t HDRnet,netBLOCKS;

2
iguana/iguana_accept.c

@ -298,7 +298,7 @@ int32_t iguana_peerhdrrequest(struct iguana_info *coin,uint8_t *serialized,int32
if ( (block= bp->blocks[i]) != 0 ) if ( (block= bp->blocks[i]) != 0 )
{ {
iguana_blockunconv(&msgB,block,1); iguana_blockunconv(&msgB,block,1);
len += iguana_rwblock(1,&checkhash2,&serialized[sizeof(struct iguana_msghdr) + len],&msgB); len += iguana_rwblock(coin->chain->hashalgo,1,&checkhash2,&serialized[sizeof(struct iguana_msghdr) + len],&msgB);
flag++; flag++;
if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 ) if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
{ {

18
iguana/iguana_blocks.c

@ -40,6 +40,18 @@ bits256 iguana_merkle(struct iguana_info *coin,bits256 *tree,int32_t txn_count)
#define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0) #define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0)
struct iguana_block *iguana_prevblock(struct iguana_info *coin,struct iguana_block *block,int32_t PoSflag)
{
int32_t hdrsi,bundlei,height; struct iguana_bundle *bp;
if ( (height= block->height - 1) < 0 )
return(0);
hdrsi = (height / coin->chain->bundlesize);
bundlei = (height % coin->chain->bundlesize);
if ( hdrsi < coin->bundlescount && (bp= coin->bundles[hdrsi]) != 0 )
return(bp->blocks[bundlei]);
else return(0);
}
void _iguana_blocklink(struct iguana_info *coin,struct iguana_block *prev,struct iguana_block *block) void _iguana_blocklink(struct iguana_info *coin,struct iguana_block *prev,struct iguana_block *block)
{ {
char str[65],str2[65]; struct iguana_block *next; char str[65],str2[65]; struct iguana_block *next;
@ -174,7 +186,7 @@ int32_t iguana_blockvalidate(struct iguana_info *coin,int32_t *validp,struct igu
{ {
bits256 hash2; uint8_t serialized[sizeof(struct iguana_msgblock) + 4096]; bits256 hash2; uint8_t serialized[sizeof(struct iguana_msgblock) + 4096];
*validp = 0; *validp = 0;
iguana_serialize_block(&hash2,serialized,block); iguana_serialize_block(coin->chain,&hash2,serialized,block);
*validp = (memcmp(hash2.bytes,block->RO.hash2.bytes,sizeof(hash2)) == 0); *validp = (memcmp(hash2.bytes,block->RO.hash2.bytes,sizeof(hash2)) == 0);
block->valid = *validp; block->valid = *validp;
char str[65]; char str2[65]; char str[65]; char str2[65];
@ -285,12 +297,12 @@ double PoW_from_compact(uint32_t nBits,uint8_t unitval) // NOT consensus safe, b
printf("illegal nBits.%x\n",nBits); printf("illegal nBits.%x\n",nBits);
return(0.); return(0.);
} }
if ( (n= ((8* (unitval-3)) - nbits)) != 0 ) // 0x1d00ffff is genesis nBits so we map that to 1. if ( (n= ((8 * (unitval-3)) - nbits)) != 0 ) // 0x1d00ffff is genesis nBits so we map that to 1.
{ {
//printf("nbits.%d -> n.%d\n",nbits,n); //printf("nbits.%d -> n.%d\n",nbits,n);
if ( n < 64 ) if ( n < 64 )
PoW /= (1LL << n); PoW /= (1LL << n);
else // very rare case efficiency not issue else // rare case efficiency not issue
{ {
for (i=0; i<n; i++) for (i=0; i<n; i++)
PoW /= 2.; PoW /= 2.;

2
iguana/iguana_bundles.c

@ -463,7 +463,7 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
{ {
if ( (fp= fopen(fname,"rb")) != 0 ) if ( (fp= fopen(fname,"rb")) != 0 )
{ {
printf("purge.(%s)\n",fname); //printf("purge.(%s)\n",fname);
fclose(fp); fclose(fp);
if ( OS_removefile(fname,0) > 0 ) if ( OS_removefile(fname,0) > 0 )
coin->peers.numfiles--, m++; coin->peers.numfiles--, m++;

58
iguana/iguana_chains.c

@ -105,10 +105,12 @@ int32_t blockhash_sha256(uint8_t *blockhashp,uint8_t *serialized,int32_t len)
int32_t blockhash_scrypt(uint8_t *blockhashp,uint8_t *serialized,int32_t len) int32_t blockhash_scrypt(uint8_t *blockhashp,uint8_t *serialized,int32_t len)
{ {
bits256 hash; if ( len == 80 )
vcalc_sha256(0,hash.bytes,serialized,len); *(bits256 *)blockhashp = scrypt_blockhash(serialized);
printf("need to implement scrypt hash here\n"); else memcpy(blockhashp,0,sizeof(*blockhashp));
exit(-1); int32_t i; for (i=0; i<32; i++)
printf("%02x",blockhashp[i]);
printf(" scrypt\n");
return(sizeof(bits256)); return(sizeof(bits256));
} }
@ -122,27 +124,37 @@ blockhashfunc iguana_hashalgo(char *hashalgostr)
return(0); return(0);
} }
bits256 iguana_chaingenesis(bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t nBits,uint32_t nonce,bits256 merkle_root) bits256 iguana_calcblockhash(int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),uint8_t *serialized,int32_t len)
{ {
struct iguana_msgblock msg; int32_t len,blockhashlen; bits256 hash2; bits256 tmp,hash2; int32_t i;
char blockhashstr[256],str3[65]; uint8_t serialized[1024],blockhash[256]; if ( (*hashalgo)(tmp.bytes,serialized,len) != sizeof(bits256) )
int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len); memset(tmp.bytes,0,sizeof(hash2));
else if ( hashalgo == blockhash_sha256 )
{
for (i=0; i<32; i++)
hash2.bytes[i] = tmp.bytes[31 - i];
} else return(tmp);
return(hash2);
}
bits256 iguana_chaingenesis(int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t nBits,uint32_t nonce,bits256 merkle_root)
{
struct iguana_msgblock msg; int32_t len; bits256 hash2; char blockhashstr[256],str3[65]; uint8_t serialized[1024];
memset(&msg,0,sizeof(msg)); memset(&msg,0,sizeof(msg));
msg.H.version = version; msg.H.version = version;
msg.H.merkle_root = merkle_root; msg.H.merkle_root = merkle_root;
msg.H.timestamp = timestamp; msg.H.timestamp = timestamp;
msg.H.bits = nBits; msg.H.bits = nBits;
msg.H.nonce = nonce; msg.H.nonce = nonce;
len = iguana_rwblock(1,&hash2,serialized,&msg); if ( hashalgostr != 0 && strcmp(hashalgostr,"sha256") != 0 )
hashalgo = iguana_hashalgo(hashalgostr);
else hashalgo = blockhash_sha256;
len = iguana_rwblock(hashalgo,1,&hash2,serialized,&msg);
blockhashstr[0] = 0; blockhashstr[0] = 0;
if ( hashalgostr != 0 && strcmp(hashalgostr,"sha256") != 0 && (hashalgo= iguana_hashalgo(hashalgostr)) != 0 ) init_hexbytes_noT(blockhashstr,hash2.bytes,sizeof(hash2));
{
if ( (blockhashlen= (*hashalgo)(blockhash,serialized,len)) > 0 )
init_hexbytes_noT(blockhashstr,blockhash,blockhashlen);
} else init_hexbytes_noT(blockhashstr,hash2.bytes,sizeof(hash2));
char str[65],str2[65]; char str[65],str2[65];
if ( bits256_cmp(genesishash,hash2) != 0 ) if ( bits256_cmp(genesishash,hash2) != 0 )
printf("WARNING: genesishash.(%s) mismatch vs calc.(%s)\n",bits256_str(str,genesishash),bits256_str(str2,genesishash)); printf("WARNING: genesishash.(%s) mismatch vs calc.(%s)\n",bits256_str(str,genesishash),bits256_str(str2,hash2));
init_hexbytes_noT(genesisblock,serialized,len); init_hexbytes_noT(genesisblock,serialized,len);
printf("v.%d t.%u %s nBits.%08x nonce.%u merkle.(%s) genesis.(%s) hash2.(%s) blockhash.(%s) size.%d\n",version,timestamp,utc_str(str3,timestamp),nBits,nonce,bits256_str(str2,merkle_root),genesisblock,bits256_str(str,hash2),blockhashstr,(int32_t)strlen(genesisblock)/2); printf("v.%d t.%u %s nBits.%08x nonce.%u merkle.(%s) genesis.(%s) hash2.(%s) blockhash.(%s) size.%d\n",version,timestamp,utc_str(str3,timestamp),nBits,nonce,bits256_str(str2,merkle_root),genesisblock,bits256_str(str,hash2),blockhashstr,(int32_t)strlen(genesisblock)/2);
return(hash2); return(hash2);
@ -316,7 +328,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
((uint8_t *)&nBits)[3] = tmp[0]; ((uint8_t *)&nBits)[3] = tmp[0];
} }
else nBits = 0x1e00ffff; else nBits = 0x1e00ffff;
hash = iguana_chaingenesis(hash,genesisblock,jstr(genesis,"hashalgo"),juint(genesis,"version"),juint(genesis,"timestamp"),nBits,juint(genesis,"nonce"),jbits256(genesis,"merkle_root")); hash = iguana_chaingenesis(chain->hashalgo,hash,genesisblock,jstr(genesis,"hashalgo"),juint(genesis,"version"),juint(genesis,"timestamp"),nBits,juint(genesis,"nonce"),jbits256(genesis,"merkle_root"));
//chain->genesis_hash = clonestr(bits256_str(str,hash)); //chain->genesis_hash = clonestr(bits256_str(str,hash));
chain->genesis_hex = clonestr(genesisblock); chain->genesis_hex = clonestr(genesisblock);
} }
@ -351,9 +363,21 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson) void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson)
{ {
int32_t i;
if ( strcmp(chain->symbol,"BTCD") == 0 )
{
chain->numPoStargets = 1;
chain->PoSheights[0] = 0;
memset(&chain->PoStargets[0],0xff,sizeof(bits256));
for (i=0; i<20; i++)
chain->PoStargets[0] = bits256_rshift(chain->PoStargets[0]);
chain->PoWtarget = bits256_from_compact(0x1e0fffff);
}
chain->hasheaders = hasheaders; chain->hasheaders = hasheaders;
chain->minoutput = 10000; chain->minoutput = 10000;
chain->hashalgo = blockhash_sha256; if ( strcmp(chain->symbol,"LTC") == 0 || strcmp(chain->symbol,"VPN") == 0 )
chain->hashalgo = blockhash_scrypt;
else chain->hashalgo = blockhash_sha256;
if ( strcmp(chain->symbol,"BTC") == 0 ) if ( strcmp(chain->symbol,"BTC") == 0 )
{ {
chain->unitval = 0x1d; chain->unitval = 0x1d;

2
iguana/iguana_exchanges.c

@ -590,6 +590,8 @@ void iguana_statemachineupdate(struct supernet_info *myinfo,struct exchange_info
portable_mutex_lock(&exchange->mutex); portable_mutex_lock(&exchange->mutex);
DL_FOREACH_SAFE(exchange->statemachines,swap,tmp) DL_FOREACH_SAFE(exchange->statemachines,swap,tmp)
{ {
if ( swap->myfee == 0 )
swap->myfee = instantdex_feetx(myinfo,&swap->mine,swap,iguana_coinfind("BTC"));
//printf("FSM.(%llu / %llu) (%s/%s) state.(%s)\n",(long long)swap->mine.orderid,(long long)swap->other.orderid,swap->mine.offer.base,swap->mine.offer.rel,swap->state->name); //printf("FSM.(%llu / %llu) (%s/%s) state.(%s)\n",(long long)swap->mine.orderid,(long long)swap->other.orderid,swap->mine.offer.base,swap->mine.offer.rel,swap->state->name);
} }
portable_mutex_unlock(&exchange->mutex); portable_mutex_unlock(&exchange->mutex);

4
iguana/iguana_init.c

@ -85,8 +85,8 @@ bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain)
return(hash2); return(hash2);
} }
decode_hex(buf,(int32_t)strlen(chain->genesis_hex)/2,(char *)chain->genesis_hex); decode_hex(buf,(int32_t)strlen(chain->genesis_hex)/2,(char *)chain->genesis_hex);
hash2 = bits256_doublesha256(0,buf,sizeof(struct iguana_msgblockhdr)); hash2 = iguana_calcblockhash(coin->chain->hashalgo,buf,sizeof(struct iguana_msgblockhdr));
iguana_rwblock(0,&hash2,buf,&msg); iguana_rwblock(coin->chain->hashalgo,0,&hash2,buf,&msg);
if ( memcmp(hash2.bytes,chain->genesis_hashdata,sizeof(hash2)) != 0 ) if ( memcmp(hash2.bytes,chain->genesis_hashdata,sizeof(hash2)) != 0 )
{ {
bits256_str(str,hash2); bits256_str(str,hash2);

6
iguana/iguana_instantdex.c

@ -1176,7 +1176,7 @@ struct bitcoin_swapinfo *bitcoin_swapinit(struct supernet_info *myinfo,struct ex
char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *argjson) char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *argjson)
{ {
struct instantdex_accept *otherap,*tmp; struct iguana_info *coin; struct bitcoin_swapinfo *swap; cJSON *newjson; int32_t isbob = 0; struct instantdex_accept *otherap,*tmp; struct bitcoin_swapinfo *swap; cJSON *newjson; int32_t isbob = 0;
*addedp = 0; *addedp = 0;
if ( exchange == 0 ) if ( exchange == 0 )
{ {
@ -1222,8 +1222,8 @@ char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_
{ {
printf("STATEMACHINEQ.(%llx / %llx)\n",(long long)swap->mine.orderid,(long long)swap->other.orderid); printf("STATEMACHINEQ.(%llx / %llx)\n",(long long)swap->mine.orderid,(long long)swap->other.orderid);
//queue_enqueue("acceptableQ",&exchange->acceptableQ,&swap->DL,0); //queue_enqueue("acceptableQ",&exchange->acceptableQ,&swap->DL,0);
if ( isbob != 0 && (coin= iguana_coinfind("BTC")) != 0 ) //if ( isbob != 0 && (coin= iguana_coinfind("BTC")) != 0 )
swap->myfee = instantdex_feetx(myinfo,&swap->mine,swap,coin); // swap->myfee = instantdex_feetx(myinfo,&swap->mine,swap,coin);
instantdex_statemachineadd(exchange,swap); instantdex_statemachineadd(exchange,swap);
*addedp = 1; *addedp = 1;
if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,argjson,1)) == 0 ) if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,argjson,1)) == 0 )

16
iguana/iguana_msg.c

@ -78,16 +78,16 @@ int32_t iguana_rwversion(int32_t rwflag,uint8_t *serialized,struct iguana_msgver
// 06000000996da490f6151ad9d05d9defc99bda58441d2b833c0da69d11e764d7c70a00003378a650b506a66b41097a0b513f2fee899788711bc6643ff976ce6dbb0b620c5f800854ffff0f1e0004de0301010000005e800854010000000000000000000000000000000000000000000000000000000000000000ffffffff03510102ffffffff0100008a5d784563011976a9145166e6e52de58dfacb18670c0030aedcf295233988ac000000000000 // 06000000996da490f6151ad9d05d9defc99bda58441d2b833c0da69d11e764d7c70a00003378a650b506a66b41097a0b513f2fee899788711bc6643ff976ce6dbb0b620c5f800854ffff0f1e0004de0301010000005e800854010000000000000000000000000000000000000000000000000000000000000000ffffffff03510102ffffffff0100008a5d784563011976a9145166e6e52de58dfacb18670c0030aedcf295233988ac000000000000
int32_t iguana_rwblock(int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg) int32_t iguana_rwblock(int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg)
{ {
int32_t len = 0; char blockhash[65]; uint64_t x; int32_t len = 0; uint64_t x;
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.version),&msg->H.version); len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.version),&msg->H.version);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.prev_block),msg->H.prev_block.bytes); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.prev_block),msg->H.prev_block.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.merkle_root),msg->H.merkle_root.bytes); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.merkle_root),msg->H.merkle_root.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.timestamp),&msg->H.timestamp); len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.timestamp),&msg->H.timestamp);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.bits),&msg->H.bits); len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.bits),&msg->H.bits);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.nonce),&msg->H.nonce); len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.nonce),&msg->H.nonce);
*hash2p = bits256_doublesha256(blockhash,serialized,len); *hash2p = iguana_calcblockhash(hashalgo,serialized,len);
//char str[65]; printf("len.%d: block version.%d timestamp.%u bits.%x nonce.%u prev.(%s) %llx blockhash.(%s) %llx\n",len,msg->H.version,msg->H.timestamp,msg->H.bits,msg->H.nonce,bits256_str(str,msg->H.prev_block),(long long)msg->H.merkle_root.txid,blockhash,(long long)hash2p->txid); //char str[65]; printf("len.%d: block version.%d timestamp.%u bits.%x nonce.%u prev.(%s) %llx blockhash.(%s) %llx\n",len,msg->H.version,msg->H.timestamp,msg->H.bits,msg->H.nonce,bits256_str(str,msg->H.prev_block),(long long)msg->H.merkle_root.txid,blockhash,(long long)hash2p->txid);
if ( rwflag != 0 ) if ( rwflag != 0 )
x = msg->txn_count; x = msg->txn_count;
@ -104,7 +104,7 @@ int32_t iguana_rwblock(int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct
return(len); return(len);
} }
int32_t iguana_serialize_block(bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block) int32_t iguana_serialize_block(struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block)
{ {
struct iguana_msgblock msg; struct iguana_msgblock msg;
memset(&msg,0,sizeof(msg)); memset(&msg,0,sizeof(msg));
@ -115,7 +115,7 @@ int32_t iguana_serialize_block(bits256 *hash2p,uint8_t serialized[sizeof(struct
msg.H.bits = block->RO.bits; msg.H.bits = block->RO.bits;
msg.H.nonce = block->RO.nonce; msg.H.nonce = block->RO.nonce;
msg.txn_count = block->RO.txn_count; msg.txn_count = block->RO.txn_count;
return(iguana_rwblock(1,hash2p,serialized,&msg)); return(iguana_rwblock(chain->hashalgo,1,hash2p,serialized,&msg));
} }
int32_t iguana_rwblockhash(int32_t rwflag,uint8_t *serialized,uint32_t *nVersionp,uint32_t *varintp,bits256 *hashes,bits256 *stophash) int32_t iguana_rwblockhash(int32_t rwflag,uint8_t *serialized,uint32_t *nVersionp,uint32_t *varintp,bits256 *hashes,bits256 *stophash)
@ -423,7 +423,7 @@ char *iguana_txscan(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t r
int32_t i,n,len; char *txbytes,vpnstr[64]; int32_t i,n,len; char *txbytes,vpnstr[64];
memset(&msg,0,sizeof(msg)); memset(&msg,0,sizeof(msg));
vpnstr[0] = 0; vpnstr[0] = 0;
len = iguana_rwblock(0,&hash2,data,&msg); len = iguana_rwblock(coin->chain->hashalgo,0,&hash2,data,&msg);
iguana_blockconv(&block,&msg,hash2,-1); iguana_blockconv(&block,&msg,hash2,-1);
for (i=0; i<msg.txn_count; i++) for (i=0; i<msg.txn_count; i++)
{ {
@ -448,7 +448,7 @@ int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struc
{ {
struct iguana_msgtx *tx; bits256 hash2; struct iguana_msgblock msg; int32_t i,n,len,numvouts,numvins; struct iguana_msgtx *tx; bits256 hash2; struct iguana_msgblock msg; int32_t i,n,len,numvouts,numvins;
memset(&msg,0,sizeof(msg)); memset(&msg,0,sizeof(msg));
len = iguana_rwblock(0,&hash2,data,&msg); len = iguana_rwblock(coin->chain->hashalgo,0,&hash2,data,&msg);
iguana_blockconv(&txdata->block,&msg,hash2,-1); iguana_blockconv(&txdata->block,&msg,hash2,-1);
tx = iguana_memalloc(mem,msg.txn_count*sizeof(*tx),1); tx = iguana_memalloc(mem,msg.txn_count*sizeof(*tx),1);
for (i=numvins=numvouts=0; i<msg.txn_count; i++) for (i=numvins=numvouts=0; i<msg.txn_count; i++)
@ -676,7 +676,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
blocks = mycalloc('i',1,sizeof(*blocks) * n); blocks = mycalloc('i',1,sizeof(*blocks) * n);
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
len += iguana_rwblock(0,&hash2,&data[len],&msg); len += iguana_rwblock(coin->chain->hashalgo,0,&hash2,&data[len],&msg);
iguana_blockconv(&blocks[i],&msg,hash2,-1); iguana_blockconv(&blocks[i],&msg,hash2,-1);
} }
iguana_gotheadersM(coin,addr,blocks,n); iguana_gotheadersM(coin,addr,blocks,n);

9
iguana/iguana_payments.c

@ -274,13 +274,14 @@ cJSON *iguana_inputsjson(struct supernet_info *myinfo,struct iguana_info *coin,i
return(vins); return(vins);
} }
char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx) char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkeys)
{ {
cJSON *privkeys; struct vin_info *V; char *signedtx = 0; struct iguana_msgtx msgtx; int32_t numinputs; struct vin_info *V; char *signedtx = 0; struct iguana_msgtx msgtx; int32_t numinputs;
*completedp = 0; *completedp = 0;
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 && (privkeys= iguana_privkeysjson(myinfo,coin,vins)) != 0 ) if ( (numinputs= cJSON_GetArraySize(vins)) > 0 && (privkeys != 0 || (privkeys= iguana_privkeysjson(myinfo,coin,vins)) != 0) )
{ {
memset(&msgtx,0,sizeof(msgtx)); memset(&msgtx,0,sizeof(msgtx));
//printf("SIGN.(%s) priv.(%s)\n",jprint(vins,0),jprint(privkeys,0));
if ( (V= calloc(numinputs,sizeof(*V))) != 0 ) if ( (V= calloc(numinputs,sizeof(*V))) != 0 )
{ {
if ( iguana_signrawtransaction(myinfo,coin,&msgtx,&signedtx,signedtxidp,V,numinputs,rawtx,vins,privkeys) > 0 ) if ( iguana_signrawtransaction(myinfo,coin,&msgtx,&signedtx,signedtxidp,V,numinputs,rawtx,vins,privkeys) > 0 )
@ -516,7 +517,7 @@ char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *
init_hexbytes_noT(spendscriptstr,spendscript,spendlen); init_hexbytes_noT(spendscriptstr,spendscript,spendlen);
if ( (rawtx= iguana_rawtxissue(myinfo,rand(),coin->symbol,&vins,locktime,satoshis,coin->changeaddr,txfee,addresses,minconf,spendscriptstr,15000)) != 0 ) if ( (rawtx= iguana_rawtxissue(myinfo,rand(),coin->symbol,&vins,locktime,satoshis,coin->changeaddr,txfee,addresses,minconf,spendscriptstr,15000)) != 0 )
{ {
if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx)) != 0 ) if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx,0)) != 0 )
{ {
iguana_unspentslock(myinfo,coin,vins); iguana_unspentslock(myinfo,coin,vins);
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();

18
iguana/iguana_ramchain.c

@ -2298,7 +2298,7 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
{ {
static const bits256 zero; static const bits256 zero;
struct iguana_blockRO *B; struct iguana_txid *T; int32_t i,firsti = 1; char fname[512]; struct iguana_blockRO *B; struct iguana_txid *T; int32_t i,firsti = 1; char fname[512];
struct iguana_block *block; struct iguana_ramchain *mapchain; struct iguana_block *block,*prev,*prev2; struct iguana_ramchain *mapchain;
memset(ramchain,0,sizeof(*ramchain)); memset(ramchain,0,sizeof(*ramchain));
if ( (mapchain= iguana_ramchain_map(coin,fname,bp,bp->n,ramchain,0,0,bp->hashes[0],zero,0,0,extraflag,1)) != 0 ) if ( (mapchain= iguana_ramchain_map(coin,fname,bp,bp->n,ramchain,0,0,bp->hashes[0],zero,0,0,extraflag,1)) != 0 )
{ {
@ -2307,12 +2307,16 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
//ramcoder_test(mapchain->H.data,mapchain->H.data->allocsize); //ramcoder_test(mapchain->H.data,mapchain->H.data->allocsize);
B = RAMCHAIN_PTR(ramchain->H.data,Boffset); B = RAMCHAIN_PTR(ramchain->H.data,Boffset);
T = RAMCHAIN_PTR(ramchain->H.data,Toffset); T = RAMCHAIN_PTR(ramchain->H.data,Toffset);
//B = (void *)(long)((long)mapchain->H.data + mapchain->H.data->Boffset); prev = prev2 = 0;
//T = (void *)(long)((long)mapchain->H.data + mapchain->H.data->Toffset);
for (i=0; i<bp->n; i++) for (i=0; i<bp->n; i++)
{ {
if ( (block= bp->blocks[i]) != 0 || (block= iguana_blockhashset("bundleload",coin,bp->bundleheight+i,bp->hashes[i],1)) != 0 ) if ( (block= bp->blocks[i]) != 0 || (block= iguana_blockhashset("bundleload",coin,bp->bundleheight+i,bp->hashes[i],1)) != 0 )
{ {
if ( bits256_to_compact(bits256_from_compact(block->RO.bits)) != block->RO.bits )
{
char str[65];
printf("nbits calc error %x -> %s -> %x\n",block->RO.bits,bits256_str(str,bits256_from_compact(block->RO.bits)),bits256_to_compact(bits256_from_compact(block->RO.bits)));
}
block->queued = 1; block->queued = 1;
block->txvalid = 1; block->txvalid = 1;
block->height = bp->bundleheight + i; block->height = bp->bundleheight + i;
@ -2322,13 +2326,21 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
block->RO = B[i]; block->RO = B[i];
//printf("%x ",(int32_t)B[i].hash2.ulongs[3]); //printf("%x ",(int32_t)B[i].hash2.ulongs[3]);
iguana_hash2set(coin,"bundleload",bp,i,block->RO.hash2); iguana_hash2set(coin,"bundleload",bp,i,block->RO.hash2);
bp->blocks[i] = block;
//if ( bits256_nonz(bp->hashes[i]) == 0 ) //if ( bits256_nonz(bp->hashes[i]) == 0 )
// bp->hashes[i] = B[i].hash2; // bp->hashes[i] = B[i].hash2;
if ( (prev= block->hh.prev) != 0 )
prev2 = prev->hh.prev;
if ( strcmp(coin->symbol,"BTCD") == 0 && bp->bundleheight > 20000 && prev != 0 && iguana_targetbits(coin,block,prev,prev2,1) != block->RO.bits )
{
printf("nbits target error %x != %x ht.%d\n",iguana_targetbits(coin,block,prev,prev2,1),block->RO.bits,block->height);
} //else printf(">>>>>>>>>> matched nbits %x ht.%d\n",block->RO.bits,block->height);
if ( bp->bundleheight+i == coin->blocks.hwmchain.height+1 ) if ( bp->bundleheight+i == coin->blocks.hwmchain.height+1 )
{ {
//printf("try extend.%d\n",bp->bundleheight+i); //printf("try extend.%d\n",bp->bundleheight+i);
//_iguana_chainlink(coin,block); wrong context //_iguana_chainlink(coin,block); wrong context
} }
prev2 = prev, prev = block;
} }
} }
//printf("mapped bundle.%d\n",bp->bundleheight); //printf("mapped bundle.%d\n",bp->bundleheight);

9
iguana/iguana_sign.c

@ -743,7 +743,7 @@ void iguana_ensure_privkey(struct supernet_info *myinfo,struct iguana_info *coin
uint8_t pubkey33[33]; struct iguana_waccount *wacct; struct iguana_waddress *waddr,addr; char coinaddr[128]; uint8_t pubkey33[33]; struct iguana_waccount *wacct; struct iguana_waddress *waddr,addr; char coinaddr[128];
bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey); bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey);
bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33); bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33);
//printf("privkey for (%s)\n",coinaddr); printf("privkey for (%s)\n",coinaddr);
if ( myinfo->expiration != 0 && ((waddr= iguana_waddresssearch(myinfo,coin,&wacct,coinaddr)) == 0 || bits256_nonz(waddr->privkey) == 0) ) if ( myinfo->expiration != 0 && ((waddr= iguana_waddresssearch(myinfo,coin,&wacct,coinaddr)) == 0 || bits256_nonz(waddr->privkey) == 0) )
{ {
if ( waddr == 0 ) if ( waddr == 0 )
@ -758,10 +758,10 @@ void iguana_ensure_privkey(struct supernet_info *myinfo,struct iguana_info *coin
waddr->privkey = privkey; waddr->privkey = privkey;
if ( bitcoin_priv2wif(waddr->wifstr,waddr->privkey,coin->chain->wiftype) > 0 ) if ( bitcoin_priv2wif(waddr->wifstr,waddr->privkey,coin->chain->wiftype) > 0 )
{ {
if ( waddr->wiftype != coin->chain->wiftype ) if ( 0 && waddr->wiftype != coin->chain->wiftype )
printf("ensurepriv warning: mismatched wiftype %02x != %02x\n",waddr->wiftype,coin->chain->wiftype); printf("ensurepriv warning: mismatched wiftype %02x != %02x\n",waddr->wiftype,coin->chain->wiftype);
if ( waddr->addrtype != coin->chain->pubtype ) if ( 0 && waddr->addrtype != coin->chain->pubtype )
printf("ensurepriv warning: mismatched wiftype %02x != %02x\n",waddr->addrtype,coin->chain->pubtype); printf("ensurepriv warning: mismatched addrtype %02x != %02x\n",waddr->addrtype,coin->chain->pubtype);
} }
} }
} }
@ -1066,6 +1066,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
item = jitem(privkeys,i); item = jitem(privkeys,i);
privkeystr = jstr(item,0); privkeystr = jstr(item,0);
privkey = iguana_str2priv(myinfo,coin,privkeystr); privkey = iguana_str2priv(myinfo,coin,privkeystr);
V->signers[i].privkey = privkey;
if ( bits256_nonz(privkey) != 0 ) if ( bits256_nonz(privkey) != 0 )
iguana_ensure_privkey(myinfo,coin,privkey); iguana_ensure_privkey(myinfo,coin,privkey);
} }

324
iguana/iguana_stake.c

@ -1,25 +1,101 @@
#ifdef reference
// modify time.1462237906 modifier.baed58b98a00e41d // modify time.1462237906 modifier.baed58b98a00e41d
#include "iguana777.h"
#define CENT (SATOSHIDEN / 100)
#define COIN_YEAR_REWARD ((int64_t)5 * CENT) // 5% per year
#define NCOINBASEMATURITY 100
#define STAKE_TIMESTAMP_MASK 15
#define NTARGETSPACING 60 // BitcoinDark - 1 minute
#define NTARGETTIMESPAN (60 * NTARGETSPACING) // BitcoinDark - every 1 hour
#define NINTERVAL_MSPACING (((NTARGETTIMESPAN / NTARGETSPACING) - 1) * NTARGETSPACING)
#define NINTERVAL_PSPACING (((NTARGETTIMESPAN / NTARGETSPACING) + 1) * NTARGETSPACING)
static const int64_t COIN_YEAR_REWARD = 5 * CENT; // 5% per year #define NSTAKESPLITAGE (1 * 24 * NTARGETTIMESPAN)
int nCoinbaseMaturity = 100; #define NSTAKE_MINAGE (8 * NTARGETTIMESPAN) // BitcoinDark - 8 hours
static const int STAKE_TIMESTAMP_MASK = 15; #define NSTAKEMAXAGE ((int64_t)-1)
#define NMAXSTAKESEARCHINTERVAL 60
#define NSTAKECOMBINETHRESHOLD (1000 * COIN)
// MODIFIER_INTERVAL_RATIO:
// ratio of group interval length between the last group and the first group // ratio of group interval length between the last group and the first group
static const int MODIFIER_INTERVAL_RATIO = 3; #define MODIFIER_INTERVAL_RATIO 3
#define NMODIFIERINTERVAL (10 * NTARGETSPACING) // BitcoinDark - time to elapse before new modifier is
CBigNum bnProofOfStakeLimit(~uint256(0) >> 20); // miner's coin stake reward based on coin age spent (coin-days)
CBigNum bnProofOfStakeLimitV2(~uint256(0) >> 48); int64_t iguana_POSreward(int64_t nCoinAge, int64_t nFees)
{
int64_t nSubsidy = (nCoinAge * COIN_YEAR_REWARD * 33) / (365 * 33 + 8);
return(nSubsidy + nFees);
}
// maximum nBits value could possible be required nTime after
uint32_t iguana_maxbits(bits256 targetval,uint32_t nBits,int64_t nTime)
{
bits256 bitsval;
bitsval = bits256_from_compact(nBits);
bitsval = bits256_lshift(bitsval);
while ( nTime > 0 && bits256_cmp(bitsval,targetval) < 0 )
{
bitsval = bits256_rshift(bitsval); // Maximum 200% adjustment per day...
nTime -= 24 * 60 * 60;
}
if ( bits256_cmp(bitsval,targetval) > 0 )
bitsval = targetval;
return(bits256_to_compact(bitsval));
}
bits256 iguana_targetval(struct iguana_info *coin,int32_t height,int32_t PoSflag)
{
int32_t i; bits256 targetval;
if ( PoSflag == 0 )
return(coin->chain->PoWtarget);
else
{
targetval = coin->chain->PoStargets[0];
for (i=0; i<coin->chain->numPoStargets; i++)
{
if ( height < coin->chain->PoSheights[i] )
break;
targetval = coin->chain->PoStargets[i];
}
}
return(targetval);
}
// minimum amount of stake that could possibly be required nTime after
// minimum proof-of-stake required was nBase
uint32_t iguana_minstake(struct iguana_info *coin,int32_t height,uint32_t nBits,int64_t nTime,uint32_t nBlockTime)
{
return(iguana_maxbits(iguana_targetval(coin,height,1),nBits,nTime));
}
uint32_t iguana_targetbits(struct iguana_info *coin,struct iguana_block *hwmchain,struct iguana_block *prev,struct iguana_block *prev2,int32_t PoSflag)
{
bits256 mpz_muldivcmp(bits256 oldval,int32_t mulval,int32_t divval,bits256 cmpval);
bits256 targetval; int32_t gap;
if ( hwmchain->height <= 2 )
return(hwmchain->RO.bits);
targetval = iguana_targetval(coin,hwmchain->height,PoSflag);
if ( prev != 0 )
{
if ( prev2 != 0 )
{
//if ( prev->RO.timestamp != 0 && prev2->RO.timestamp != 0 ) skip check for compatiblity
{
if ( (gap= prev->RO.timestamp - prev2->RO.timestamp) < 0 )
gap = NTARGETSPACING;
// ppcoin: target change every block, retarget with exponential moving toward target spacing
targetval = mpz_muldivcmp(bits256_from_compact(prev->RO.bits),NINTERVAL_MSPACING + (gap << 1),NINTERVAL_PSPACING,targetval);
}
}
}
return(bits256_to_compact(targetval));
}
unsigned int nTargetSpacing = 1 * 60; // BitcoinDark - 1 minute #ifdef reference
static const int64_t nTargetTimespan = 60 * 60; // BitcoinDark - every 1 hour
unsigned int nStakeMinAge = 8 * 60 * 60; // BitcoinDark - 8 hours
unsigned int nStakeMaxAge = -1;
unsigned int nModifierInterval = 10 * 60; // BitcoinDark - time to elapse before new modifier is
unsigned int nStakeSplitAge = 1 * 24 * 60 * 60; CBigNum bnProofOfStakeLimit(~uint256(0) >> 20);
int64_t nStakeCombineThreshold = 1000 * COIN; CBigNum bnProofOfStakeLimitV2(~uint256(0) >> 48);
enum enum
{ {
@ -29,26 +105,24 @@ enum
}; };
uint64_t nStakeModifier; // hash modifier for proof-of-stake uint64_t nStakeModifier; // hash modifier for proof-of-stake
unsigned int nStakeModifierChecksum; // checksum of index; in-memeory only uint32_t nStakeModifierChecksum; // checksum of index; in-memory only
uint256 CBlockIndex::GetBlockTrust() const uint256 CBlockIndex::GetBlockTrust() const
{ {
CBigNum bnTarget; CBigNum bnTarget;
bnTarget.SetCompact(nBits); bnTarget.SetCompact(nBits);
if (bnTarget <= 0) if (bnTarget <= 0)
return 0; return 0;
return ((CBigNum(1)<<256) / (bnTarget+1)).getuint256(); return ((CBigNum(1)<<256) / (bnTarget+1)).getuint256();
} }
unsigned int GetStakeEntropyBit() const uint32_t GetStakeEntropyBit() const
{ {
return ((nFlags & BLOCK_STAKE_ENTROPY) >> 1); return ((nFlags & BLOCK_STAKE_ENTROPY) >> 1);
} }
bool SetStakeEntropyBit(unsigned int nEntropyBit) bool SetStakeEntropyBit(uint32_t nEntropyBit)
{ {
if (nEntropyBit > 1) if (nEntropyBit > 1)
return false; return false;
@ -68,80 +142,6 @@ void SetStakeModifier(uint64_t nModifier, bool fGeneratedStakeModifier)
nFlags |= BLOCK_STAKE_MODIFIER; nFlags |= BLOCK_STAKE_MODIFIER;
} }
// miner's coin stake reward based on coin age spent (coin-days)
int64_t GetProofOfStakeReward(int64_t nCoinAge, int64_t nFees)
{
int64_t nSubsidy = nCoinAge * COIN_YEAR_REWARD * 33 / (365 * 33 + 8);
return(nSubsidy + nFees);
}
//
// maximum nBits value could possible be required nTime after
//
unsigned int ComputeMaxBits(CBigNum bnTargetLimit, unsigned int nBase, int64_t nTime)
{
CBigNum bnResult;
bnResult.SetCompact(nBase);
bnResult *= 2;
while (nTime > 0 && bnResult < bnTargetLimit)
{
// Maximum 200% adjustment per day...
bnResult *= 2;
nTime -= 24 * 60 * 60;
}
if (bnResult > bnTargetLimit)
bnResult = bnTargetLimit;
return bnResult.GetCompact();
}
//
// minimum amount of stake that could possibly be required nTime after
// minimum proof-of-stake required was nBase
//
unsigned int ComputeMinStake(unsigned int nBase, int64_t nTime, unsigned int nBlockTime)
{
return ComputeMaxBits(bnProofOfStakeLimit, nBase, nTime);
}
static CBigNum GetProofOfStakeLimit(int nHeight)
{
if(IsPoSV2(nHeight))
return bnProofOfStakeLimitV2;
else
return bnProofOfStakeLimit;
}
unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake)
{
CBigNum bnTargetLimit = fProofOfStake ? GetProofOfStakeLimit(pindexLast->nHeight) : bnProofOfWorkLimit;
if (pindexLast == NULL)
return bnTargetLimit.GetCompact(); // genesis block
const CBlockIndex* pindexPrev = GetLastBlockIndex(pindexLast, fProofOfStake);
if (pindexPrev->pprev == NULL)
return bnTargetLimit.GetCompact(); // first block
const CBlockIndex* pindexPrevPrev = GetLastBlockIndex(pindexPrev->pprev, fProofOfStake);
if (pindexPrevPrev->pprev == NULL)
return bnTargetLimit.GetCompact(); // second block
int64_t nActualSpacing = pindexPrev->GetBlockTime() - pindexPrevPrev->GetBlockTime();
if (nActualSpacing < 0)
nActualSpacing = nTargetSpacing;
// ppcoin: target change every block
// ppcoin: retarget with exponential moving toward target spacing
CBigNum bnNew;
bnNew.SetCompact(pindexPrev->nBits);
int64_t nInterval = nTargetTimespan / nTargetSpacing;
bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing);
bnNew /= ((nInterval + 1) * nTargetSpacing);
if (bnNew <= 0 || bnNew > bnTargetLimit)
bnNew = bnTargetLimit;
return bnNew.GetCompact();
}
// ppcoin: total coin age spent in transaction, in the unit of coin-days. // ppcoin: total coin age spent in transaction, in the unit of coin-days.
// Only those coins meeting minimum age requirement counts. As those // Only those coins meeting minimum age requirement counts. As those
// transactions not in main chain are not currently indexed so we // transactions not in main chain are not currently indexed so we
@ -168,7 +168,7 @@ bool CTransaction::GetCoinAge(CTxDB& txdb, uint64_t& nCoinAge) const
CBlock block; CBlock block;
if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false)) if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
return false; // unable to read block of previous transaction return false; // unable to read block of previous transaction
if (block.GetBlockTime() + nStakeMinAge > nTime) if (block.GetBlockTime() + NSTAKE_MINAGE > nTime)
continue; // only count coins meeting min age requirement continue; // only count coins meeting min age requirement
int64_t nValueIn = txPrev.vout[txin.prevout.n].nValue; int64_t nValueIn = txPrev.vout[txin.prevout.n].nValue;
@ -206,13 +206,12 @@ bool CBlock::GetCoinAge(uint64_t& nCoinAge) const
} }
// Get time weight // Get time weight
int64_t GetWeight(int64_t nIntervalBeginning, int64_t nIntervalEnd) int64_t GetWeight(int64_t nIntervalBeginning,int64_t nIntervalEnd)
{ {
// Kernel hash weight starts from 0 at the min age // Kernel hash weight starts from 0 at the min age
// this change increases active coins participating the hash and helps // this change increases active coins participating the hash and helps
// to secure the network when proof-of-stake difficulty is low // to secure the network when proof-of-stake difficulty is low
return min(nIntervalEnd - nIntervalBeginning - NSTAKE_MINAGE,NSTAKEMAXAGE);
return min(nIntervalEnd - nIntervalBeginning - nStakeMinAge, (int64_t)nStakeMaxAge);
} }
// Get the last stake modifier and its generation time from a given block // Get the last stake modifier and its generation time from a given block
@ -230,50 +229,44 @@ static bool GetLastStakeModifier(const CBlockIndex* pindex, uint64_t& nStakeModi
} }
// Get selection interval section (in seconds) // Get selection interval section (in seconds)
static int64_t GetStakeModifierSelectionIntervalSection(int nSection) static int64_t GetStakeModifierSelectionIntervalSection(int32_t nSection)
{ {
assert (nSection >= 0 && nSection < 64); assert (nSection >= 0 && nSection < 64);
return (nModifierInterval * 63 / (63 + ((63 - nSection) * (MODIFIER_INTERVAL_RATIO - 1)))); return (NMODIFIERINTERVAL * 63 / (63 + ((63 - nSection) * (MODIFIER_INTERVAL_RATIO - 1))));
} }
// Get stake modifier selection interval (in seconds) // Get stake modifier selection interval (in seconds)
static int64_t GetStakeModifierSelectionInterval() static int64_t GetStakeModifierSelectionInterval()
{ {
int64_t nSelectionInterval = 0; int64_t nSelectionInterval = 0;
for (int nSection=0; nSection<64; nSection++) for (int32_t nSection=0; nSection<64; nSection++)
nSelectionInterval += GetStakeModifierSelectionIntervalSection(nSection); nSelectionInterval += GetStakeModifierSelectionIntervalSection(nSection);
return nSelectionInterval; return nSelectionInterval;
} }
// select a block from the candidate blocks in vSortedByTimestamp, excluding // select a block from the candidate blocks in vSortedByTimestamp, excluding
// already selected blocks in vSelectedBlocks, and with timestamp up to // already selected blocks in vSelectedBlocks, and with timestamp up to nSelectionIntervalStop.
// nSelectionIntervalStop. static bool SelectBlockFromCandidates(vector<pair<int64_t, uint256> >& vSortedByTimestamp, map<uint256, const CBlockIndex*>& mapSelectedBlocks,int64_t nSelectionIntervalStop, uint64_t nStakeModifierPrev, const CBlockIndex **pindexSelected)
static bool SelectBlockFromCandidates(vector<pair<int64_t, uint256> >& vSortedByTimestamp, map<uint256, const CBlockIndex*>& mapSelectedBlocks,
int64_t nSelectionIntervalStop, uint64_t nStakeModifierPrev, const CBlockIndex** pindexSelected)
{ {
bool fSelected = false; bool fSelected = false; uint256 hashBest = 0;
uint256 hashBest = 0;
*pindexSelected = (const CBlockIndex*) 0; *pindexSelected = (const CBlockIndex*) 0;
BOOST_FOREACH(const PAIRTYPE(int64_t, uint256)& item, vSortedByTimestamp) BOOST_FOREACH(const PAIRTYPE(int64_t, uint256)&item, vSortedByTimestamp)
{ {
if (!mapBlockIndex.count(item.second)) if (!mapBlockIndex.count(item.second))
return error("SelectBlockFromCandidates: failed to find block index for candidate block %s", item.second.ToString().c_str()); return error("SelectBlockFromCandidates: failed to find block index for candidate block %s", item.second.ToString().c_str());
const CBlockIndex* pindex = mapBlockIndex[item.second]; const CBlockIndex *pindex = mapBlockIndex[item.second];
if (fSelected && pindex->GetBlockTime() > nSelectionIntervalStop) if ( fSelected && pindex->GetBlockTime() > nSelectionIntervalStop )
break; break;
if (mapSelectedBlocks.count(pindex->GetBlockHash()) > 0) if (mapSelectedBlocks.count(pindex->GetBlockHash()) > 0)
continue; continue;
// compute the selection hash by hashing its proof-hash and the // compute the selection hash by hashing its proof-hash and the previous proof-of-stake modifier
// previous proof-of-stake modifier
CDataStream ss(SER_GETHASH, 0); CDataStream ss(SER_GETHASH, 0);
ss << pindex->hashProof << nStakeModifierPrev; ss << pindex->hashProof << nStakeModifierPrev;
uint256 hashSelection = Hash(ss.begin(), ss.end()); uint256 hashSelection = Hash(ss.begin(), ss.end());
// the selection hash is divided by 2**32 so that proof-of-stake block // the selection hash is divided by 2**32 so that proof-of-stake block is always favored over proof-of-work block. this is to preserve the energy efficiency property
// is always favored over proof-of-work block. this is to preserve if ( pindex->IsProofOfStake() )
// the energy efficiency property
if (pindex->IsProofOfStake())
hashSelection >>= 32; hashSelection >>= 32;
if (fSelected && hashSelection < hashBest) if ( fSelected && hashSelection < hashBest )
{ {
hashBest = hashSelection; hashBest = hashSelection;
*pindexSelected = (const CBlockIndex*) pindex; *pindexSelected = (const CBlockIndex*) pindex;
@ -321,21 +314,21 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod
{ {
printf("ComputeNextStakeModifier: prev modifier=0x%016"PRIx64" time=%s\n", nStakeModifier, DateTimeStrFormat(nModifierTime).c_str()); printf("ComputeNextStakeModifier: prev modifier=0x%016"PRIx64" time=%s\n", nStakeModifier, DateTimeStrFormat(nModifierTime).c_str());
} }
if (nModifierTime / nModifierInterval >= pindexPrev->GetBlockTime() / nModifierInterval) if (nModifierTime / NMODIFIERINTERVAL >= pindexPrev->GetBlockTime() / NMODIFIERINTERVAL)
return true; return true;
// Sort candidate blocks by timestamp // Sort candidate blocks by timestamp
vector<pair<int64_t, uint256> > vSortedByTimestamp; vector<pair<int64_t, uint256> > vSortedByTimestamp;
vSortedByTimestamp.reserve(64 * nModifierInterval / nTargetSpacing); vSortedByTimestamp.reserve(64 * (NMODIFIERINTERVAL / NTARGETSPACING));
int64_t nSelectionInterval = GetStakeModifierSelectionInterval(); int64_t nSelectionInterval = GetStakeModifierSelectionInterval();
int64_t nSelectionIntervalStart = (pindexPrev->GetBlockTime() / nModifierInterval) * nModifierInterval - nSelectionInterval; int64_t nSelectionIntervalStart = (pindexPrev->GetBlockTime() / NMODIFIERINTERVAL) * NMODIFIERINTERVAL - nSelectionInterval;
const CBlockIndex* pindex = pindexPrev; const CBlockIndex* pindex = pindexPrev;
while (pindex && pindex->GetBlockTime() >= nSelectionIntervalStart) while (pindex && pindex->GetBlockTime() >= nSelectionIntervalStart)
{ {
vSortedByTimestamp.push_back(make_pair(pindex->GetBlockTime(), pindex->GetBlockHash())); vSortedByTimestamp.push_back(make_pair(pindex->GetBlockTime(), pindex->GetBlockHash()));
pindex = pindex->pprev; pindex = pindex->pprev;
} }
int nHeightFirstCandidate = pindex ? (pindex->nHeight + 1) : 0; int32_t nHeightFirstCandidate = pindex ? (pindex->nHeight + 1) : 0;
reverse(vSortedByTimestamp.begin(), vSortedByTimestamp.end()); reverse(vSortedByTimestamp.begin(), vSortedByTimestamp.end());
sort(vSortedByTimestamp.begin(), vSortedByTimestamp.end()); sort(vSortedByTimestamp.begin(), vSortedByTimestamp.end());
@ -343,7 +336,7 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod
uint64_t nStakeModifierNew = 0; uint64_t nStakeModifierNew = 0;
int64_t nSelectionIntervalStop = nSelectionIntervalStart; int64_t nSelectionIntervalStop = nSelectionIntervalStart;
map<uint256, const CBlockIndex*> mapSelectedBlocks; map<uint256, const CBlockIndex*> mapSelectedBlocks;
for (int nRound=0; nRound<min(64, (int)vSortedByTimestamp.size()); nRound++) for (int32_t nRound=0; nRound<min(64, (int)vSortedByTimestamp.size()); nRound++)
{ {
// add an interval section to the current selection round // add an interval section to the current selection round
nSelectionIntervalStop += GetStakeModifierSelectionIntervalSection(nRound); nSelectionIntervalStop += GetStakeModifierSelectionIntervalSection(nRound);
@ -407,11 +400,9 @@ static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifi
{ {
if (!pindex->pnext) if (!pindex->pnext)
{ // reached best block; may happen if node is behind on block chain { // reached best block; may happen if node is behind on block chain
if (fPrintProofOfStake || (pindex->GetBlockTime() + nStakeMinAge - nStakeModifierSelectionInterval > GetAdjustedTime())) if (fPrintProofOfStake || (pindex->GetBlockTime() + NSTAKE_MINAGE - nStakeModifierSelectionInterval > GetAdjustedTime()))
return error("GetKernelStakeModifier() : reached best block %s at height %d from block %s", return error("GetKernelStakeModifier() : reached best block %s at height %d from block %s",pindex->GetBlockHash().ToString().c_str(), pindex->nHeight, hashBlockFrom.ToString().c_str());
pindex->GetBlockHash().ToString().c_str(), pindex->nHeight, hashBlockFrom.ToString().c_str()); else return false;
else
return false;
} }
pindex = pindex->pnext; pindex = pindex->pnext;
if (pindex->GeneratedStakeModifier()) if (pindex->GeneratedStakeModifier())
@ -445,13 +436,13 @@ static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifi
// quantities so as to generate blocks faster, degrading the system back into // quantities so as to generate blocks faster, degrading the system back into
// a proof-of-work situation. // a proof-of-work situation.
// //
bool CheckStakeKernelHashV1(unsigned int nBits, const CBlock& blockFrom, unsigned int nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, unsigned int nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake) bool CheckStakeKernelHashV1(uint32_t nBits, const CBlock& blockFrom,uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout,uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake)
{ {
if (nTimeTx < txPrev.nTime) // Transaction timestamp violation if (nTimeTx < txPrev.nTime) // Transaction timestamp violation
return error("CheckStakeKernelHash() : nTime violation"); return error("CheckStakeKernelHash() : nTime violation");
unsigned int nTimeBlockFrom = blockFrom.GetBlockTime(); uint32_t nTimeBlockFrom = blockFrom.GetBlockTime();
if (nTimeBlockFrom + nStakeMinAge > nTimeTx) // Min age requirement if (nTimeBlockFrom + NSTAKE_MINAGE > nTimeTx) // Min age requirement
return error("CheckStakeKernelHash() : min age violation"); return error("CheckStakeKernelHash() : min age violation");
CBigNum bnTargetPerCoinDay; CBigNum bnTargetPerCoinDay;
@ -466,7 +457,7 @@ bool CheckStakeKernelHashV1(unsigned int nBits, const CBlock& blockFrom, unsigne
// Calculate hash // Calculate hash
CDataStream ss(SER_GETHASH, 0); CDataStream ss(SER_GETHASH, 0);
uint64_t nStakeModifier = 0; uint64_t nStakeModifier = 0;
int nStakeModifierHeight = 0; int32_t nStakeModifierHeight = 0;
int64_t nStakeModifierTime = 0; int64_t nStakeModifierTime = 0;
if ( !GetKernelStakeModifier(hashBlockFrom, nStakeModifier, nStakeModifierHeight, nStakeModifierTime, fPrintProofOfStake) ) if ( !GetKernelStakeModifier(hashBlockFrom, nStakeModifier, nStakeModifierHeight, nStakeModifierTime, fPrintProofOfStake) )
@ -504,7 +495,7 @@ bool CheckStakeKernelHashV1(unsigned int nBits, const CBlock& blockFrom, unsigne
return true; return true;
} }
bool CheckStakeKernelHash(CBlockIndex* pindexPrev, unsigned int nBits, const CBlock& blockFrom, unsigned int nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, unsigned int nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake) bool CheckStakeKernelHash(CBlockIndex* pindexPrev, uint32_t nBits, const CBlock& blockFrom, uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake)
{ {
if (IsPoSV2(pindexPrev->nHeight+1)) if (IsPoSV2(pindexPrev->nHeight+1))
return CheckStakeKernelHashV2(pindexPrev, nBits, blockFrom.GetBlockTime(), txPrev, prevout, nTimeTx, hashProofOfStake, targetProofOfStake, fPrintProofOfStake); return CheckStakeKernelHashV2(pindexPrev, nBits, blockFrom.GetBlockTime(), txPrev, prevout, nTimeTx, hashProofOfStake, targetProofOfStake, fPrintProofOfStake);
@ -512,10 +503,9 @@ bool CheckStakeKernelHash(CBlockIndex* pindexPrev, unsigned int nBits, const CBl
return CheckStakeKernelHashV1(nBits, blockFrom, nTxPrevOffset, txPrev, prevout, nTimeTx, hashProofOfStake, targetProofOfStake, fPrintProofOfStake); return CheckStakeKernelHashV1(nBits, blockFrom, nTxPrevOffset, txPrev, prevout, nTimeTx, hashProofOfStake, targetProofOfStake, fPrintProofOfStake);
} }
bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, int64_t nFees, CTransaction& txNew, CKey& key) bool CWallet::CreateCoinStake(const CKeyStore& keystore, uint32_t nBits, int64_t nSearchInterval, int64_t nFees, CTransaction& txNew, CKey& key)
{ {
CBlockIndex* pindexPrev = pindexBest; CBigNum bnTargetPerCoinDay; CBlockIndex *pindexPrev = pindexBest;
CBigNum bnTargetPerCoinDay;
bnTargetPerCoinDay.SetCompact(nBits); bnTargetPerCoinDay.SetCompact(nBits);
txNew.vin.clear(); txNew.vin.clear();
@ -528,12 +518,10 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
// Choose coins to use // Choose coins to use
int64_t nBalance = GetBalance(); int64_t nBalance = GetBalance();
if (nBalance <= nReserveBalance) if (nBalance <= nReserveBalance)
return false; return false;
vector<const CWalletTx*> vwtxPrev; vector<const CWalletTx*> vwtxPrev;
set<pair<const CWalletTx*,unsigned int> > setCoins; set<pair<const CWalletTx*,unsigned int> > setCoins;
int64_t nValueIn = 0; int64_t nValueIn = 0;
@ -564,15 +552,14 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
continue; continue;
} }
static int nMaxStakeSearchInterval = 60; if (block.GetBlockTime() + NSTAKE_MINAGE > txNew.nTime - NMAXSTAKESEARCHINTERVAL)
if (block.GetBlockTime() + nStakeMinAge > txNew.nTime - nMaxStakeSearchInterval)
continue; // only count coins meeting min age requirement continue; // only count coins meeting min age requirement
bool fKernelFound = false; bool fKernelFound = false;
for (unsigned int n=0; n<min(nSearchInterval,(int64_t)nMaxStakeSearchInterval) && !fKernelFound && !fShutdown && pindexPrev == pindexBest; n++) for (uint32_t n=0; n<min(nSearchInterval,(int64_t)NMAXSTAKESEARCHINTERVAL) && !fKernelFound && !fShutdown && pindexPrev == pindexBest; n++)
{ {
// Search backward in time from the given txNew timestamp // Search backward in time from the given txNew timestamp
// Search nSearchInterval seconds back up to nMaxStakeSearchInterval // Search nSearchInterval seconds back up to NMAXSTAKESEARCHINTERVAL
uint256 hashProofOfStake = 0, targetProofOfStake = 0; uint256 hashProofOfStake = 0, targetProofOfStake = 0;
COutPoint prevoutStake = COutPoint(pcoin.first->GetHash(), pcoin.second); COutPoint prevoutStake = COutPoint(pcoin.first->GetHash(), pcoin.second);
if (CheckStakeKernelHash(pindexPrev, nBits, block, txindex.pos.nTxPos - txindex.pos.nBlockPos, *pcoin.first, prevoutStake, txNew.nTime - n, hashProofOfStake, targetProofOfStake)) if (CheckStakeKernelHash(pindexPrev, nBits, block, txindex.pos.nTxPos - txindex.pos.nBlockPos, *pcoin.first, prevoutStake, txNew.nTime - n, hashProofOfStake, targetProofOfStake))
@ -653,29 +640,26 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
{ {
// Attempt to add more inputs // Attempt to add more inputs: Only add coins of the same key/address as kernel
// Only add coins of the same key/address as kernel
if (txNew.vout.size() == 2 && ((pcoin.first->vout[pcoin.second].scriptPubKey == scriptPubKeyKernel || pcoin.first->vout[pcoin.second].scriptPubKey == txNew.vout[1].scriptPubKey)) if (txNew.vout.size() == 2 && ((pcoin.first->vout[pcoin.second].scriptPubKey == scriptPubKeyKernel || pcoin.first->vout[pcoin.second].scriptPubKey == txNew.vout[1].scriptPubKey))
&& pcoin.first->GetHash() != txNew.vin[0].prevout.hash) && pcoin.first->GetHash() != txNew.vin[0].prevout.hash)
{ {
int64_t nTimeWeight = GetWeight((int64_t)pcoin.first->nTime, (int64_t)txNew.nTime); int64_t nTimeWeight = GetWeight((int64_t)pcoin.first->nTime, (int64_t)txNew.nTime);
// Stop adding more inputs if already too many inputs // Stop adding more inputs if already too many inputs
if (txNew.vin.size() >= 100) if (txNew.vin.size() >= 100)
break; break;
// Stop adding more inputs if value is already pretty significant // Stop adding more inputs if value is already pretty significant
if (nCredit >= nStakeCombineThreshold) if (nCredit >= NSTAKECOMBINETHRESHOLD)
break; break;
// Stop adding inputs if reached reserve limit // Stop adding inputs if reached reserve limit
if (nCredit + pcoin.first->vout[pcoin.second].nValue > nBalance - nReserveBalance) if (nCredit + pcoin.first->vout[pcoin.second].nValue > nBalance - nReserveBalance)
break; break;
// Do not add additional significant input // Do not add additional significant input
if (pcoin.first->vout[pcoin.second].nValue >= nStakeCombineThreshold) if (pcoin.first->vout[pcoin.second].nValue >= NSTAKECOMBINETHRESHOLD)
continue; continue;
// Do not add input that is still too young // Do not add input that is still too young
if (nTimeWeight < nStakeMinAge) if (nTimeWeight < NSTAKE_MINAGE)
continue; continue;
txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second)); txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
nCredit += pcoin.first->vout[pcoin.second].nValue; nCredit += pcoin.first->vout[pcoin.second].nValue;
vwtxPrev.push_back(pcoin.first); vwtxPrev.push_back(pcoin.first);
@ -689,7 +673,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
if (!txNew.GetCoinAge(txdb, nCoinAge)) if (!txNew.GetCoinAge(txdb, nCoinAge))
return error("CreateCoinStake : failed to calculate coin age"); return error("CreateCoinStake : failed to calculate coin age");
int64_t nReward = GetProofOfStakeReward(nCoinAge, nFees); int64_t nReward = iguana_POSreward(nCoinAge, nFees);
if (nReward <= 0) if (nReward <= 0)
return false; return false;
@ -701,12 +685,10 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
{ {
txNew.vout[1].nValue = (nCredit / 2 / CENT) * CENT; txNew.vout[1].nValue = (nCredit / 2 / CENT) * CENT;
txNew.vout[2].nValue = nCredit - txNew.vout[1].nValue; txNew.vout[2].nValue = nCredit - txNew.vout[1].nValue;
} } else txNew.vout[1].nValue = nCredit;
else
txNew.vout[1].nValue = nCredit;
// Sign // Sign
int nIn = 0; int32_t nIn = 0;
BOOST_FOREACH(const CWalletTx* pcoin, vwtxPrev) BOOST_FOREACH(const CWalletTx* pcoin, vwtxPrev)
{ {
if (!SignSignature(*this, *pcoin, txNew, nIn++)) if (!SignSignature(*this, *pcoin, txNew, nIn++))
@ -714,7 +696,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
} }
// Limit size // Limit size
unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION); uint32_t nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
if (nBytes >= MAX_BLOCK_SIZE_GEN/5) if (nBytes >= MAX_BLOCK_SIZE_GEN/5)
return error("CreateCoinStake : exceeded coinstake size limit"); return error("CreateCoinStake : exceeded coinstake size limit");
@ -723,7 +705,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
} }
// Check kernel hash target and coinstake signature // Check kernel hash target and coinstake signature
bool CheckProofOfStake(CBlockIndex* pindexPrev, const CTransaction& tx, unsigned int nBits, uint256& hashProofOfStake, uint256& targetProofOfStake) bool CheckProofOfStake(CBlockIndex* pindexPrev, const CTransaction& tx, uint32_t nBits, uint256& hashProofOfStake, uint256& targetProofOfStake)
{ {
if (!tx.IsCoinStake()) if (!tx.IsCoinStake())
return error("CheckProofOfStake() : called on non-coinstake %s", tx.GetHash().ToString().c_str()); return error("CheckProofOfStake() : called on non-coinstake %s", tx.GetHash().ToString().c_str());
@ -761,7 +743,7 @@ bool CheckCoinStakeTimestamp(int64_t nTimeBlock, int64_t nTimeTx)
} }
// Get stake modifier checksum // Get stake modifier checksum
unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex) uint32_t GetStakeModifierChecksum(const CBlockIndex* pindex)
{ {
//assert (pindex->pprev || pindex->GetBlockHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet)); //assert (pindex->pprev || pindex->GetBlockHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet));
// Hash previous checksum with flags, hashProofOfStake and nStakeModifier // Hash previous checksum with flags, hashProofOfStake and nStakeModifier
@ -775,7 +757,7 @@ unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex)
} }
// Check stake modifier hard checkpoints // Check stake modifier hard checkpoints
bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum) bool CheckStakeModifierCheckpoints(int32_t nHeight, uint32_t nStakeModifierChecksum)
{ {
MapModifierCheckpoints& checkpoints = (fTestNet ? mapStakeModifierCheckpointsTestNet : mapStakeModifierCheckpoints); MapModifierCheckpoints& checkpoints = (fTestNet ? mapStakeModifierCheckpointsTestNet : mapStakeModifierCheckpoints);
@ -783,44 +765,33 @@ bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierCheck
return nStakeModifierChecksum == checkpoints[nHeight]; return nStakeModifierChecksum == checkpoints[nHeight];
return true; return true;
} }
// novacoin: attempt to generate suitable proof-of-stake // novacoin: attempt to generate suitable proof-of-stake
bool CBlock::SignBlock(CWallet& wallet, int64_t nFees) bool CBlock::SignBlock(CWallet& wallet, int64_t nFees)
{ {
// if we are trying to sign // if we are trying to sign something except proof-of-stake block template
// something except proof-of-stake block template
if (!vtx[0].vout[0].IsEmpty()) if (!vtx[0].vout[0].IsEmpty())
return false; return false;
// if we are trying to sign a complete proof-of-stake block
// if we are trying to sign
// a complete proof-of-stake block
if (IsProofOfStake()) if (IsProofOfStake())
return true; return true;
static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // startup timestamp static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // startup timestamp
CKey key; CTransaction txCoinStake; int64_t nSearchTime = txCoinStake.nTime; // search to current time
CKey key;
CTransaction txCoinStake;
int64_t nSearchTime = txCoinStake.nTime; // search to current time
if (nSearchTime > nLastCoinStakeSearchTime) if (nSearchTime > nLastCoinStakeSearchTime)
{ {
if (wallet.CreateCoinStake(wallet, nBits, nSearchTime-nLastCoinStakeSearchTime, nFees, txCoinStake, key)) if (wallet.CreateCoinStake(wallet, nBits, nSearchTime-nLastCoinStakeSearchTime, nFees, txCoinStake, key))
{ {
if (txCoinStake.nTime >= max(pindexBest->GetPastTimeLimit()+1, PastDrift(pindexBest->GetBlockTime()))) if (txCoinStake.nTime >= max(pindexBest->GetPastTimeLimit()+1, PastDrift(pindexBest->GetBlockTime())))
{ {
// make sure coinstake would meet timestamp protocol // make sure coinstake would meet timestamp protocol as it would be the same as the block timestamp
// as it would be the same as the block timestamp
vtx[0].nTime = nTime = txCoinStake.nTime; vtx[0].nTime = nTime = txCoinStake.nTime;
nTime = max(pindexBest->GetPastTimeLimit()+1, GetMaxTransactionTime()); nTime = max(pindexBest->GetPastTimeLimit()+1, GetMaxTransactionTime());
nTime = max(GetBlockTime(), PastDrift(pindexBest->GetBlockTime())); nTime = max(GetBlockTime(), PastDrift(pindexBest->GetBlockTime()));
// we have to make sure that we have no future timestamps in // we have to make sure that we have no future timestamps in our transactions set
// our transactions set
for (vector<CTransaction>::iterator it = vtx.begin(); it != vtx.end();) for (vector<CTransaction>::iterator it = vtx.begin(); it != vtx.end();)
if (it->nTime > nTime) { it = vtx.erase(it); } else { ++it; } if (it->nTime > nTime) { it = vtx.erase(it); } else { ++it; }
vtx.insert(vtx.begin() + 1, txCoinStake); vtx.insert(vtx.begin() + 1, txCoinStake);
hashMerkleRoot = BuildMerkleTree(); hashMerkleRoot = BuildMerkleTree();
// append a signature to our block // append a signature to our block
return key.Sign(GetHash(), vchBlockSig); return key.Sign(GetHash(), vchBlockSig);
} }
@ -836,15 +807,11 @@ bool CBlock::CheckBlockSignature() const
{ {
if (IsProofOfWork()) if (IsProofOfWork())
return vchBlockSig.empty(); return vchBlockSig.empty();
vector<valtype> vSolutions; vector<valtype> vSolutions;
txnouttype whichType; txnouttype whichType;
const CTxOut& txout = vtx[1].vout[1]; const CTxOut& txout = vtx[1].vout[1];
if (!Solver(txout.scriptPubKey, whichType, vSolutions)) if (!Solver(txout.scriptPubKey, whichType, vSolutions))
return false; return false;
if (whichType == TX_PUBKEY) if (whichType == TX_PUBKEY)
{ {
valtype& vchPubKey = vSolutions[0]; valtype& vchPubKey = vSolutions[0];
@ -855,7 +822,6 @@ bool CBlock::CheckBlockSignature() const
return false; return false;
return key.Verify(GetHash(), vchBlockSig); return key.Verify(GetHash(), vchBlockSig);
} }
return false; return false;
} }

4
iguana/iguana_tx.c

@ -230,7 +230,7 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int
{ {
iguana_blockunconv(&msgB,block,0); iguana_blockunconv(&msgB,block,0);
msgB.txn_count = block->RO.txn_count; msgB.txn_count = block->RO.txn_count;
total = iguana_rwblock(1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&msgB); total = iguana_rwblock(coin->chain->hashalgo,1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&msgB);
if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 ) if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
{ {
static int counter; static int counter;
@ -368,7 +368,7 @@ cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int3
msg.H.bits = block->RO.bits; msg.H.bits = block->RO.bits;
msg.H.nonce = block->RO.nonce; msg.H.nonce = block->RO.nonce;
msg.txn_count = 0;//block->RO.txn_count; msg.txn_count = 0;//block->RO.txn_count;
len = iguana_rwblock(1,&hash2,serialized,&msg); len = iguana_rwblock(coin->chain->hashalgo,1,&hash2,serialized,&msg);
init_hexbytes_noT(hexstr,serialized,len); init_hexbytes_noT(hexstr,serialized,len);
jaddstr(json,"blockheader",hexstr); jaddstr(json,"blockheader",hexstr);
if ( txidsflag != 0 ) if ( txidsflag != 0 )

2
iguana/iguana_volatiles.c

@ -89,6 +89,8 @@ struct iguana_utxo iguana_utxofind(struct iguana_info *coin,int16_t spent_hdrsi,
if ( (bp= coin->bundles[spent_hdrsi]) == 0 ) if ( (bp= coin->bundles[spent_hdrsi]) == 0 )
return(utxo); return(utxo);
ramchain = (bp == coin->current) ? &coin->RTramchain : &bp->ramchain; ramchain = (bp == coin->current) ? &coin->RTramchain : &bp->ramchain;
if ( ramchain->H.data == 0 )
return(utxo);
val = ((uint64_t)spent_hdrsi << 32) | spent_unspentind; val = ((uint64_t)spent_hdrsi << 32) | spent_unspentind;
if ( spent_unspentind > 0 && spent_unspentind < ramchain->H.data->numunspents ) if ( spent_unspentind > 0 && spent_unspentind < ramchain->H.data->numunspents )
{ {

6
iguana/iguana_wallet.c

@ -182,10 +182,10 @@ struct iguana_waddress *iguana_waddresssearch(struct supernet_info *myinfo,struc
{ {
if ( bitcoin_priv2wif(waddr->wifstr,waddr->privkey,coin->chain->wiftype) > 0 ) if ( bitcoin_priv2wif(waddr->wifstr,waddr->privkey,coin->chain->wiftype) > 0 )
{ {
if ( waddr->wiftype != coin->chain->wiftype ) if ( 0 && waddr->wiftype != coin->chain->wiftype )
printf("waddresssearch warning: mismatched wiftype %02x != %02x\n",waddr->wiftype,coin->chain->wiftype); printf("waddresssearch warning: mismatched wiftype %02x != %02x\n",waddr->wiftype,coin->chain->wiftype);
if ( waddr->addrtype != coin->chain->pubtype ) if ( 0 && waddr->addrtype != coin->chain->pubtype )
printf("waddresssearch warning: mismatched wiftype %02x != %02x\n",waddr->addrtype,coin->chain->pubtype); printf("waddresssearch warning: mismatched addrtype %02x != %02x\n",waddr->addrtype,coin->chain->pubtype);
} }
} }
(*wacctp) = wacct; (*wacctp) = wacct;

2
iguana/js/api.js

@ -153,7 +153,7 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
SPNAPI.useGETRequest=function(request){ SPNAPI.useGETRequest=function(request){
if(request.method && (request.method==='apikeypair' || request.method==='setuserid' || request.method==='encryptjson' || request.method==='decryptjson')){ if(request.method && (request.method==='apikeypair' || request.method==='setuserid' || request.method==='encryptjson' || request.method==='decryptjson')){
return false; return true;
}else{ }else{
return true; return true;
} }

59
iguana/js/blockexplorer.js

@ -36,64 +36,7 @@ document.getElementById('BlockExpCoin').innerHTML = html;
* to start RPC for particular coin * to start RPC for particular coin
*/ */
var callBlockEXPRPC=function(coin){ var callBlockEXPRds
var request="{\"agent\":\"SuperNET\",\"method\":\"bitcoinrpc\",\"setcoin\":\""+coin+"\"}";
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.result && response.result==='set bitcoin RPC coin'){
blockExp_input_table();
}
});
};
/*
*
* @param {type} height
* @returns {undefined}
* Function gets the blockhash when called and is stored in global variable
* (initially height is set to zero)
*
*/
var filterInt = function (value) {
if(/^(\-|\+)?([0-9]+|Infinity)$/.test(value))
return Number(value);
return "NaN";
};
var getBlockhash= function(height){
var height=($('#BlockExp_height').val());
/*
if (height === "NaN" || height ==='Infinity') {
height=0;
}*/
var request="{\"agent\":\"ramchain\",\"method\":\"getblockhash\",\"height\":\""+height+"\"}";
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.result){
BlockHash=response.result;
//Blockhashoutput
document.getElementById('block_output_table').innerHTML='<tr><td >'+'Blockhash is:</td><td width="300px"> '+BlockHash+'</td></tr>';
$('#BlockExp_blockhash').val(BlockHash);
}
});
};
/*
*
* @param {type} hash
* @returns {undefined}
* Function gets Block for a paritculat blockhash
* and store inside global varianle
*
*/
var getBlock= function(hash){ var getBlock= function(hash){
var inputhash=$('#BlockExp_blockhash').val(); var inputhash=$('#BlockExp_blockhash').val();
if(inputhash!==hash){ if(inputhash!==hash){

13
iguana/main.c

@ -1148,9 +1148,14 @@ void iguana_appletests(struct supernet_info *myinfo)
{ {
char *str; char *str;
//iguana_chaingenesis(1,1403138561,0x1e0fffff,8359109,bits256_conv("fd1751cc6963d88feca94c0d01da8883852647a37a0a67ce254d62dd8c9d5b2b")); // BTCD //iguana_chaingenesis(1,1403138561,0x1e0fffff,8359109,bits256_conv("fd1751cc6963d88feca94c0d01da8883852647a37a0a67ce254d62dd8c9d5b2b")); // BTCD
//iguana_chaingenesis(1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN if ( 0 )
//char genesisblock[1024]; {
//iguana_chaingenesis(genesisblock,"sha256",1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC char genesisblock[1024];
iguana_chaingenesis(0,bits256_conv("00000ac7d764e7119da60d3c832b1d4458da9bc9ef9d5dd0d91a15f690a46d99"),genesisblock,"scrypt",1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN
iguana_chaingenesis(0,bits256_conv("12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2"),genesisblock,"scrypt",1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC
getchar();
}
if ( 1 ) if ( 1 )
{ {
//void ztest(); ztest(); //void ztest(); ztest();
@ -1159,7 +1164,7 @@ void iguana_appletests(struct supernet_info *myinfo)
//int32_t iguana_schnorr_test(void *ctx); //int32_t iguana_schnorr_test(void *ctx);
//iguana_schnorr_test(myinfo->ctx); getchar(); //iguana_schnorr_test(myinfo->ctx); getchar();
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":-1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":64,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":100}"),0,myinfo->rpcport)) != 0 ) if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":64,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":100}"),0,myinfo->rpcport)) != 0 )
{ {
free(str); free(str);
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":-1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":64,\"newcoin\":\"BTC\",\"active\":0,\"numhelpers\":4,\"poll\":100}"),0,myinfo->rpcport)) != 0 ) if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":-1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":64,\"newcoin\":\"BTC\",\"active\":0,\"numhelpers\":4,\"poll\":100}"),0,myinfo->rpcport)) != 0 )

2
iguana/mingw32

@ -1,4 +1,4 @@
include ../mingw.path include ../mingw.path
LIBS := ../win/libsecp256k1.a ../win/libcrypto.a ../win/libssl.a /usr/share/mingw-w64/lib/libpthread.a ../agents/win32/libcrypto777.a ../win/libcurldll.a /usr/i586-mingw32msvc/lib/libws2_32.a /usr/i586-mingw32msvc/lib/libgdi32.a -I/usr/mingw32/include -I/usr/i386/include -I/usr/i386/include/curl -I/home/user/SuperNET/iguana -I/home/user/SuperNET/includes -I/home/user/SuperNET/crypto777 LIBS := /usr/share/mingw-w64/lib/libpthread.a ../agents/win32/libcrypto777.a /usr/i586-mingw32msvc/lib/libws2_32.a /usr/i586-mingw32msvc/lib/libgdi32.a -I/usr/mingw32/include -I/usr/i386/include -I/home/user/SuperNET/iguana -I/home/user/SuperNET/includes -I/home/user/SuperNET/crypto777
include mingw include mingw

577
iguana/mini-gmp.c

File diff suppressed because it is too large

148
iguana/mini-gmp.h

@ -55,18 +55,18 @@ void mp_get_memory_functions (void *(**) (size_t),
void *(**) (void *, size_t, size_t), void *(**) (void *, size_t, size_t),
void (**) (void *, size_t)); void (**) (void *, size_t));
typedef unsigned long mp_limb_t; typedef uint64_t mp_limb_t;
typedef long mp_size_t; typedef int64_t mp_size_t;
typedef unsigned long mp_bitcnt_t; typedef uint64_t mp_bitcnt_t;
typedef mp_limb_t *mp_ptr; typedef mp_limb_t *mp_ptr;
typedef const mp_limb_t *mp_srcptr; typedef const mp_limb_t *mp_srcptr;
typedef struct typedef struct
{ {
int _mp_alloc; /* Number of *limbs* allocated and pointed int32_t _mp_alloc; /* Number of *limbs* allocated and pointed
to by the _mp_d field. */ to by the _mp_d field. */
int _mp_size; /* abs(_mp_size) is the number of limbs the int32_t _mp_size; /* abs(_mp_size) is the number of limbs the
last field points to. If _mp_size is last field points to. If _mp_size is
negative this is a negative number. */ negative this is a negative number. */
mp_limb_t *_mp_d; /* Pointer to the limbs. */ mp_limb_t *_mp_d; /* Pointer to the limbs. */
@ -77,14 +77,14 @@ typedef __mpz_struct mpz_t[1];
typedef __mpz_struct *mpz_ptr; typedef __mpz_struct *mpz_ptr;
typedef const __mpz_struct *mpz_srcptr; typedef const __mpz_struct *mpz_srcptr;
extern const int mp_bits_per_limb; extern const int32_t mp_bits_per_limb;
void mpn_copyi (mp_ptr, mp_srcptr, mp_size_t); void mpn_copyi (mp_ptr, mp_srcptr, mp_size_t);
void mpn_copyd (mp_ptr, mp_srcptr, mp_size_t); void mpn_copyd (mp_ptr, mp_srcptr, mp_size_t);
void mpn_zero (mp_ptr, mp_size_t); void mpn_zero (mp_ptr, mp_size_t);
int mpn_cmp (mp_srcptr, mp_srcptr, mp_size_t); int32_t mpn_cmp (mp_srcptr, mp_srcptr, mp_size_t);
int mpn_zero_p (mp_srcptr, mp_size_t); int32_t mpn_zero_p (mp_srcptr, mp_size_t);
mp_limb_t mpn_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); mp_limb_t mpn_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
mp_limb_t mpn_add_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); mp_limb_t mpn_add_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
@ -101,11 +101,11 @@ mp_limb_t mpn_submul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t); void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t);
int mpn_perfect_square_p (mp_srcptr, mp_size_t); int32_t mpn_perfect_square_p (mp_srcptr, mp_size_t);
mp_size_t mpn_sqrtrem (mp_ptr, mp_ptr, mp_srcptr, mp_size_t); mp_size_t mpn_sqrtrem (mp_ptr, mp_ptr, mp_srcptr, mp_size_t);
mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int); mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, uint32_t);
mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int); mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, uint32_t);
mp_bitcnt_t mpn_scan0 (mp_srcptr, mp_bitcnt_t); mp_bitcnt_t mpn_scan0 (mp_srcptr, mp_bitcnt_t);
mp_bitcnt_t mpn_scan1 (mp_srcptr, mp_bitcnt_t); mp_bitcnt_t mpn_scan1 (mp_srcptr, mp_bitcnt_t);
@ -115,42 +115,42 @@ mp_bitcnt_t mpn_popcount (mp_srcptr, mp_size_t);
mp_limb_t mpn_invert_3by2 (mp_limb_t, mp_limb_t); mp_limb_t mpn_invert_3by2 (mp_limb_t, mp_limb_t);
#define mpn_invert_limb(x) mpn_invert_3by2 ((x), 0) #define mpn_invert_limb(x) mpn_invert_3by2 ((x), 0)
size_t mpn_get_str (unsigned char *, int, mp_ptr, mp_size_t); size_t mpn_get_str (uint8_t *, int32_t, mp_ptr, mp_size_t);
mp_size_t mpn_set_str (mp_ptr, const unsigned char *, size_t, int); mp_size_t mpn_set_str (mp_ptr, const uint8_t *, size_t, int32_t);
void mpz_init (mpz_t); void mpz_init (mpz_t);
void mpz_init2 (mpz_t, mp_bitcnt_t); void mpz_init2 (mpz_t, mp_bitcnt_t);
void mpz_clear (mpz_t); void mpz_clear (mpz_t);
#define mpz_odd_p(z) (((z)->_mp_size != 0) & (int) (z)->_mp_d[0]) #define mpz_odd_p(z) (((z)->_mp_size != 0) & (int32_t) (z)->_mp_d[0])
#define mpz_even_p(z) (! mpz_odd_p (z)) #define mpz_even_p(z) (! mpz_odd_p (z))
int mpz_sgn (const mpz_t); int32_t mpz_sgn (const mpz_t);
int mpz_cmp_si (const mpz_t, long); int32_t mpz_cmp_si (const mpz_t, int64_t);
int mpz_cmp_ui (const mpz_t, unsigned long); int32_t mpz_cmp_ui (const mpz_t, uint64_t);
int mpz_cmp (const mpz_t, const mpz_t); int32_t mpz_cmp (const mpz_t, const mpz_t);
int mpz_cmpabs_ui (const mpz_t, unsigned long); int32_t mpz_cmpabs_ui (const mpz_t, uint64_t);
int mpz_cmpabs (const mpz_t, const mpz_t); int32_t mpz_cmpabs (const mpz_t, const mpz_t);
int mpz_cmp_d (const mpz_t, double); int32_t mpz_cmp_d (const mpz_t, double);
int mpz_cmpabs_d (const mpz_t, double); int32_t mpz_cmpabs_d (const mpz_t, double);
void mpz_abs (mpz_t, const mpz_t); void mpz_abs (mpz_t, const mpz_t);
void mpz_neg (mpz_t, const mpz_t); void mpz_neg (mpz_t, const mpz_t);
void mpz_swap (mpz_t, mpz_t); void mpz_swap (mpz_t, mpz_t);
void mpz_add_ui (mpz_t, const mpz_t, unsigned long); void mpz_add_ui (mpz_t, const mpz_t, uint64_t);
void mpz_add (mpz_t, const mpz_t, const mpz_t); void mpz_add (mpz_t, const mpz_t, const mpz_t);
void mpz_sub_ui (mpz_t, const mpz_t, unsigned long); void mpz_sub_ui (mpz_t, const mpz_t, uint64_t);
void mpz_ui_sub (mpz_t, unsigned long, const mpz_t); void mpz_ui_sub (mpz_t, uint64_t, const mpz_t);
void mpz_sub (mpz_t, const mpz_t, const mpz_t); void mpz_sub (mpz_t, const mpz_t, const mpz_t);
void mpz_mul_si (mpz_t, const mpz_t, long int); void mpz_mul_si (mpz_t, const mpz_t, int64_t);
void mpz_mul_ui (mpz_t, const mpz_t, unsigned long int); void mpz_mul_ui (mpz_t, const mpz_t, uint64_t);
void mpz_mul (mpz_t, const mpz_t, const mpz_t); void mpz_mul (mpz_t, const mpz_t, const mpz_t);
void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t); void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
void mpz_addmul_ui (mpz_t, const mpz_t, unsigned long int); void mpz_addmul_ui (mpz_t, const mpz_t, uint64_t);
void mpz_addmul (mpz_t, const mpz_t, const mpz_t); void mpz_addmul (mpz_t, const mpz_t, const mpz_t);
void mpz_submul_ui (mpz_t, const mpz_t, unsigned long int); void mpz_submul_ui (mpz_t, const mpz_t, uint64_t);
void mpz_submul (mpz_t, const mpz_t, const mpz_t); void mpz_submul (mpz_t, const mpz_t, const mpz_t);
void mpz_cdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t); void mpz_cdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);
@ -174,53 +174,53 @@ void mpz_mod (mpz_t, const mpz_t, const mpz_t);
void mpz_divexact (mpz_t, const mpz_t, const mpz_t); void mpz_divexact (mpz_t, const mpz_t, const mpz_t);
int mpz_divisible_p (const mpz_t, const mpz_t); int32_t mpz_divisible_p (const mpz_t, const mpz_t);
int mpz_congruent_p (const mpz_t, const mpz_t, const mpz_t); int32_t mpz_congruent_p (const mpz_t, const mpz_t, const mpz_t);
unsigned long mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long); uint64_t mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uint64_t);
unsigned long mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long); uint64_t mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uint64_t);
unsigned long mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, unsigned long); uint64_t mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uint64_t);
unsigned long mpz_cdiv_q_ui (mpz_t, const mpz_t, unsigned long); uint64_t mpz_cdiv_q_ui (mpz_t, const mpz_t, uint64_t);
unsigned long mpz_fdiv_q_ui (mpz_t, const mpz_t, unsigned long); uint64_t mpz_fdiv_q_ui (mpz_t, const mpz_t, uint64_t);
unsigned long mpz_tdiv_q_ui (mpz_t, const mpz_t, unsigned long); uint64_t mpz_tdiv_q_ui (mpz_t, const mpz_t, uint64_t);
unsigned long mpz_cdiv_r_ui (mpz_t, const mpz_t, unsigned long); uint64_t mpz_cdiv_r_ui (mpz_t, const mpz_t, uint64_t);
unsigned long mpz_fdiv_r_ui (mpz_t, const mpz_t, unsigned long); uint64_t mpz_fdiv_r_ui (mpz_t, const mpz_t, uint64_t);
unsigned long mpz_tdiv_r_ui (mpz_t, const mpz_t, unsigned long); uint64_t mpz_tdiv_r_ui (mpz_t, const mpz_t, uint64_t);
unsigned long mpz_cdiv_ui (const mpz_t, unsigned long); uint64_t mpz_cdiv_ui (const mpz_t, uint64_t);
unsigned long mpz_fdiv_ui (const mpz_t, unsigned long); uint64_t mpz_fdiv_ui (const mpz_t, uint64_t);
unsigned long mpz_tdiv_ui (const mpz_t, unsigned long); uint64_t mpz_tdiv_ui (const mpz_t, uint64_t);
unsigned long mpz_mod_ui (mpz_t, const mpz_t, unsigned long); uint64_t mpz_mod_ui (mpz_t, const mpz_t, uint64_t);
void mpz_divexact_ui (mpz_t, const mpz_t, unsigned long); void mpz_divexact_ui (mpz_t, const mpz_t, uint64_t);
int mpz_divisible_ui_p (const mpz_t, unsigned long); int32_t mpz_divisible_ui_p (const mpz_t, uint64_t);
unsigned long mpz_gcd_ui (mpz_t, const mpz_t, unsigned long); uint64_t mpz_gcd_ui (mpz_t, const mpz_t, uint64_t);
void mpz_gcd (mpz_t, const mpz_t, const mpz_t); void mpz_gcd (mpz_t, const mpz_t, const mpz_t);
void mpz_gcdext (mpz_t, mpz_t, mpz_t, const mpz_t, const mpz_t); void mpz_gcdext (mpz_t, mpz_t, mpz_t, const mpz_t, const mpz_t);
void mpz_lcm_ui (mpz_t, const mpz_t, unsigned long); void mpz_lcm_ui (mpz_t, const mpz_t, uint64_t);
void mpz_lcm (mpz_t, const mpz_t, const mpz_t); void mpz_lcm (mpz_t, const mpz_t, const mpz_t);
int mpz_invert (mpz_t, const mpz_t, const mpz_t); int32_t mpz_invert (mpz_t, const mpz_t, const mpz_t);
void mpz_sqrtrem (mpz_t, mpz_t, const mpz_t); void mpz_sqrtrem (mpz_t, mpz_t, const mpz_t);
void mpz_sqrt (mpz_t, const mpz_t); void mpz_sqrt (mpz_t, const mpz_t);
int mpz_perfect_square_p (const mpz_t); int32_t mpz_perfect_square_p (const mpz_t);
void mpz_pow_ui (mpz_t, const mpz_t, unsigned long); void mpz_pow_ui (mpz_t, const mpz_t, uint64_t);
void mpz_ui_pow_ui (mpz_t, unsigned long, unsigned long); void mpz_ui_pow_ui (mpz_t, uint64_t, uint64_t);
void mpz_powm (mpz_t, const mpz_t, const mpz_t, const mpz_t); void mpz_powm (mpz_t, const mpz_t, const mpz_t, const mpz_t);
void mpz_powm_ui (mpz_t, const mpz_t, unsigned long, const mpz_t); void mpz_powm_ui (mpz_t, const mpz_t, uint64_t, const mpz_t);
void mpz_rootrem (mpz_t, mpz_t, const mpz_t, unsigned long); void mpz_rootrem (mpz_t, mpz_t, const mpz_t, uint64_t);
int mpz_root (mpz_t, const mpz_t, unsigned long); int32_t mpz_root (mpz_t, const mpz_t, uint64_t);
void mpz_fac_ui (mpz_t, unsigned long); void mpz_fac_ui (mpz_t, uint64_t);
void mpz_bin_uiui (mpz_t, unsigned long, unsigned long); void mpz_bin_uiui (mpz_t, uint64_t, uint64_t);
int mpz_probab_prime_p (const mpz_t, int); int32_t mpz_probab_prime_p (const mpz_t, int32_t);
int mpz_tstbit (const mpz_t, mp_bitcnt_t); int32_t mpz_tstbit (const mpz_t, mp_bitcnt_t);
void mpz_setbit (mpz_t, mp_bitcnt_t); void mpz_setbit (mpz_t, mp_bitcnt_t);
void mpz_clrbit (mpz_t, mp_bitcnt_t); void mpz_clrbit (mpz_t, mp_bitcnt_t);
void mpz_combit (mpz_t, mp_bitcnt_t); void mpz_combit (mpz_t, mp_bitcnt_t);
@ -235,10 +235,10 @@ mp_bitcnt_t mpz_hamdist (const mpz_t, const mpz_t);
mp_bitcnt_t mpz_scan0 (const mpz_t, mp_bitcnt_t); mp_bitcnt_t mpz_scan0 (const mpz_t, mp_bitcnt_t);
mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t); mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t);
int mpz_fits_slong_p (const mpz_t); int32_t mpz_fits_slong_p (const mpz_t);
int mpz_fits_ulong_p (const mpz_t); int32_t mpz_fits_ulong_p (const mpz_t);
long int mpz_get_si (const mpz_t); int64_t mpz_get_si (const mpz_t);
unsigned long int mpz_get_ui (const mpz_t); uint64_t mpz_get_ui (const mpz_t);
double mpz_get_d (const mpz_t); double mpz_get_d (const mpz_t);
size_t mpz_size (const mpz_t); size_t mpz_size (const mpz_t);
mp_limb_t mpz_getlimbn (const mpz_t, mp_size_t); mp_limb_t mpz_getlimbn (const mpz_t, mp_size_t);
@ -252,20 +252,20 @@ mpz_srcptr mpz_roinit_n (mpz_t, mp_srcptr, mp_size_t);
#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }} #define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
void mpz_set_si (mpz_t, signed long int); void mpz_set_si (mpz_t, int64_t);
void mpz_set_ui (mpz_t, unsigned long int); void mpz_set_ui (mpz_t, uint64_t);
void mpz_set (mpz_t, const mpz_t); void mpz_set (mpz_t, const mpz_t);
void mpz_set_d (mpz_t, double); void mpz_set_d (mpz_t, double);
void mpz_init_set_si (mpz_t, signed long int); void mpz_init_set_si (mpz_t, int64_t);
void mpz_init_set_ui (mpz_t, unsigned long int); void mpz_init_set_ui (mpz_t, uint64_t);
void mpz_init_set (mpz_t, const mpz_t); void mpz_init_set (mpz_t, const mpz_t);
void mpz_init_set_d (mpz_t, double); void mpz_init_set_d (mpz_t, double);
size_t mpz_sizeinbase (const mpz_t, int); size_t mpz_sizeinbase (const mpz_t, int32_t);
char *mpz_get_str (char *, int, const mpz_t); char *mpz_get_str (char *, int32_t, const mpz_t);
int mpz_set_str (mpz_t, const char *, int); int32_t mpz_set_str (mpz_t, const char *, int32_t);
int mpz_init_set_str (mpz_t, const char *, int); int32_t mpz_init_set_str (mpz_t, const char *, int32_t);
/* This long list taken from gmp.h. */ /* This long list taken from gmp.h. */
/* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4, /* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4,
@ -285,11 +285,11 @@ int mpz_init_set_str (mpz_t, const char *, int);
|| defined (_STDIO_H_INCLUDED) /* QNX4 */ \ || defined (_STDIO_H_INCLUDED) /* QNX4 */ \
|| defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \ || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \
|| defined (__STDIO_LOADED) /* VMS */ || defined (__STDIO_LOADED) /* VMS */
size_t mpz_out_str (FILE *, int, const mpz_t); size_t mpz_out_str (FILE *, int32_t, const mpz_t);
#endif #endif
void mpz_import (mpz_t, size_t, int, size_t, int, size_t, const void *); void mpz_import (mpz_t, size_t, int32_t, size_t, int32_t, size_t, const void *);
void *mpz_export (void *, size_t *, int, size_t, int, size_t, const mpz_t); void *mpz_export (void *, size_t *, int32_t, size_t, int32_t, size_t, const mpz_t);
#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT) #define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
#define GMP_NAIL_BITS 0 #define GMP_NAIL_BITS 0
#define GMP_NUMB_BITS (GMP_LIMB_BITS - GMP_NAIL_BITS) #define GMP_NUMB_BITS (GMP_LIMB_BITS - GMP_NAIL_BITS)

20
iguana/swaps/iguana_BTCswap.c

@ -109,16 +109,21 @@ void iguana_addinputs(struct iguana_info *coin,struct bitcoin_spend *spend,cJSON
struct bitcoin_statetx *instantdex_signtx(struct supernet_info *myinfo,struct iguana_info *coin,uint32_t locktime,char *scriptstr,int64_t satoshis,int64_t txfee,int32_t minconf,int32_t myside) struct bitcoin_statetx *instantdex_signtx(struct supernet_info *myinfo,struct iguana_info *coin,uint32_t locktime,char *scriptstr,int64_t satoshis,int64_t txfee,int32_t minconf,int32_t myside)
{ {
struct iguana_waddress *waddr; struct bitcoin_statetx *tx=0; uint8_t pubkey33[33]; char coinaddr[64]; char *rawtx,*signedtx,*retstr; bits256 signedtxid; uint32_t rawtxtag; int32_t flag,completed; cJSON *valsobj,*vins,*retjson,*argjson,*addresses = cJSON_CreateArray(); struct iguana_waddress *waddr; struct iguana_waccount *wacct; struct bitcoin_statetx *tx=0; uint8_t pubkey33[33]; char coinaddr[64],wifstr[64]; char *rawtx,*signedtx,*retstr; bits256 signedtxid; uint32_t rawtxtag; int32_t flag,completed; cJSON *valsobj,*vins,*retjson,*privkey,*argjson,*addresses;
if ( coin->changeaddr[0] == 0 )
{
if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 ) if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 )
return(0); return(0);
privkey = cJSON_CreateArray();
addresses = cJSON_CreateArray();
if ( coin->changeaddr[0] == 0 )
bitcoin_address(coin->changeaddr,coin->chain->pubtype,waddr->rmd160,20); bitcoin_address(coin->changeaddr,coin->chain->pubtype,waddr->rmd160,20);
}
bitcoin_pubkey33(myinfo->ctx,pubkey33,myinfo->persistent_priv); bitcoin_pubkey33(myinfo->ctx,pubkey33,myinfo->persistent_priv);
bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33); bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33);
printf("%s persistent.(%s) (%s) change.(%s) scriptstr.(%s)\n",coin->symbol,myinfo->myaddr.BTC,coinaddr,coin->changeaddr,scriptstr); printf("%s persistent.(%s) (%s) change.(%s) scriptstr.(%s)\n",coin->symbol,myinfo->myaddr.BTC,coinaddr,coin->changeaddr,scriptstr);
if ( (waddr= iguana_waddresssearch(myinfo,coin,&wacct,coinaddr)) != 0 )
{
bitcoin_priv2wif(wifstr,waddr->privkey,coin->chain->wiftype);
jaddistr(privkey,waddr->wifstr);
}
jaddistr(addresses,coinaddr); jaddistr(addresses,coinaddr);
valsobj = cJSON_CreateObject(); valsobj = cJSON_CreateObject();
jaddstr(valsobj,"coin",coin->symbol); jaddstr(valsobj,"coin",coin->symbol);
@ -132,7 +137,7 @@ struct bitcoin_statetx *instantdex_signtx(struct supernet_info *myinfo,struct ig
jaddnum(argjson,"timeout",15000); jaddnum(argjson,"timeout",15000);
if ( (retstr= iguana_rawtx(myinfo,coin,argjson,0,coin->changeaddr,addresses,valsobj,scriptstr)) != 0 ) if ( (retstr= iguana_rawtx(myinfo,coin,argjson,0,coin->changeaddr,addresses,valsobj,scriptstr)) != 0 )
{ {
printf("feetx got.(%s)\n",retstr); //printf("feetx got.(%s)\n",retstr);
flag = 0; flag = 0;
if ( (retjson= cJSON_Parse(retstr)) != 0 ) if ( (retjson= cJSON_Parse(retstr)) != 0 )
{ {
@ -148,9 +153,10 @@ struct bitcoin_statetx *instantdex_signtx(struct supernet_info *myinfo,struct ig
flag = 2; flag = 2;
} }
} }
if ( flag != 0 ) if ( flag != 0 && vins != 0 )
{ {
if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx)) != 0 ) //printf("vins.(%s)\n",jprint(vins,0));
if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx,privkey)) != 0 )
{ {
iguana_unspentslock(myinfo,coin,vins); iguana_unspentslock(myinfo,coin,vins);
tx = calloc(1,sizeof(*tx) + strlen(rawtx) + 1); tx = calloc(1,sizeof(*tx) + strlen(rawtx) + 1);

2
iguana/tests/decoderawtransaction

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"method\":\"decoderawtransaction\",\"params\":[\"0100000011533957010252b9534fe0186625e3075606f9b547e223830af04b3fb9dab2aaadc7cad5300100000000ffffffff0280969800000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac700c023b000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000\"]}" curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"decoderawtransaction\",\"params\":[\"01000000016def80687bd97e9b932827a9fa8ce20d7e0c9032b3bc3a211a830e80ac0f5d560100000000ffffffff02bb280000000000002308d7019f135580dfb27576a914ca1e04745e8ca0c60d8c5881531d51bec470743f88acb5469800000000001976a9145513ce20df70c082324da1781c222a4d68dfe87988ac00000000\"]}"

1
includes/curve25519.h

@ -76,5 +76,6 @@ uint64_t acct777_sign(struct acct777_sig *sig,bits256 privkey,bits256 otherpubke
uint64_t acct777_validate(struct acct777_sig *sig,bits256 privkey,bits256 pubkey); uint64_t acct777_validate(struct acct777_sig *sig,bits256 privkey,bits256 pubkey);
uint64_t acct777_signtx(struct acct777_sig *sig,bits256 privkey,uint32_t timestamp,uint8_t *data,int32_t datalen); uint64_t acct777_signtx(struct acct777_sig *sig,bits256 privkey,uint32_t timestamp,uint8_t *data,int32_t datalen);
uint64_t acct777_swaptx(bits256 privkey,struct acct777_sig *sig,uint32_t timestamp,uint8_t *data,int32_t datalen); uint64_t acct777_swaptx(bits256 privkey,struct acct777_sig *sig,uint32_t timestamp,uint8_t *data,int32_t datalen);
void calc_hmac_sha256(uint8_t *mac,int32_t maclen,uint8_t *key,int32_t key_size,uint8_t *message,int32_t len);
#endif #endif

Loading…
Cancel
Save