diff --git a/android/Android_Readme.md b/OSlibs/android/Android_Readme.md similarity index 100% rename from android/Android_Readme.md rename to OSlibs/android/Android_Readme.md diff --git a/android/include/curl/Makefile b/OSlibs/android/include/curl/Makefile similarity index 100% rename from android/include/curl/Makefile rename to OSlibs/android/include/curl/Makefile diff --git a/android/include/curl/Makefile.am b/OSlibs/android/include/curl/Makefile.am similarity index 100% rename from android/include/curl/Makefile.am rename to OSlibs/android/include/curl/Makefile.am diff --git a/android/include/curl/Makefile.in b/OSlibs/android/include/curl/Makefile.in similarity index 100% rename from android/include/curl/Makefile.in rename to OSlibs/android/include/curl/Makefile.in diff --git a/android/include/curl/curl.h b/OSlibs/android/include/curl/curl.h similarity index 100% rename from android/include/curl/curl.h rename to OSlibs/android/include/curl/curl.h diff --git a/android/include/curl/curlbuild.h b/OSlibs/android/include/curl/curlbuild.h similarity index 100% rename from android/include/curl/curlbuild.h rename to OSlibs/android/include/curl/curlbuild.h diff --git a/android/include/curl/curlbuild.h.cmake b/OSlibs/android/include/curl/curlbuild.h.cmake similarity index 100% rename from android/include/curl/curlbuild.h.cmake rename to OSlibs/android/include/curl/curlbuild.h.cmake diff --git a/android/include/curl/curlbuild.h.in b/OSlibs/android/include/curl/curlbuild.h.in similarity index 100% rename from android/include/curl/curlbuild.h.in rename to OSlibs/android/include/curl/curlbuild.h.in diff --git a/android/include/curl/curlrules.h b/OSlibs/android/include/curl/curlrules.h similarity index 100% rename from android/include/curl/curlrules.h rename to OSlibs/android/include/curl/curlrules.h diff --git a/android/include/curl/curlver.h b/OSlibs/android/include/curl/curlver.h similarity index 100% rename from android/include/curl/curlver.h rename to OSlibs/android/include/curl/curlver.h diff --git a/android/include/curl/easy.h b/OSlibs/android/include/curl/easy.h similarity index 100% rename from android/include/curl/easy.h rename to OSlibs/android/include/curl/easy.h diff --git a/android/include/curl/mprintf.h b/OSlibs/android/include/curl/mprintf.h similarity index 100% rename from android/include/curl/mprintf.h rename to OSlibs/android/include/curl/mprintf.h diff --git a/android/include/curl/multi.h b/OSlibs/android/include/curl/multi.h similarity index 100% rename from android/include/curl/multi.h rename to OSlibs/android/include/curl/multi.h diff --git a/android/include/curl/stamp-h2 b/OSlibs/android/include/curl/stamp-h2 similarity index 100% rename from android/include/curl/stamp-h2 rename to OSlibs/android/include/curl/stamp-h2 diff --git a/android/include/curl/stdcheaders.h b/OSlibs/android/include/curl/stdcheaders.h similarity index 100% rename from android/include/curl/stdcheaders.h rename to OSlibs/android/include/curl/stdcheaders.h diff --git a/android/include/curl/typecheck-gcc.h b/OSlibs/android/include/curl/typecheck-gcc.h similarity index 100% rename from android/include/curl/typecheck-gcc.h rename to OSlibs/android/include/curl/typecheck-gcc.h diff --git a/android/include/openssl/aes.h b/OSlibs/android/include/openssl/aes.h similarity index 100% rename from android/include/openssl/aes.h rename to OSlibs/android/include/openssl/aes.h diff --git a/android/include/openssl/asn1.h b/OSlibs/android/include/openssl/asn1.h similarity index 100% rename from android/include/openssl/asn1.h rename to OSlibs/android/include/openssl/asn1.h diff --git a/android/include/openssl/asn1_mac.h b/OSlibs/android/include/openssl/asn1_mac.h similarity index 100% rename from android/include/openssl/asn1_mac.h rename to OSlibs/android/include/openssl/asn1_mac.h diff --git a/android/include/openssl/asn1t.h b/OSlibs/android/include/openssl/asn1t.h similarity index 100% rename from android/include/openssl/asn1t.h rename to OSlibs/android/include/openssl/asn1t.h diff --git a/android/include/openssl/bio.h b/OSlibs/android/include/openssl/bio.h similarity index 100% rename from android/include/openssl/bio.h rename to OSlibs/android/include/openssl/bio.h diff --git a/android/include/openssl/blowfish.h b/OSlibs/android/include/openssl/blowfish.h similarity index 100% rename from android/include/openssl/blowfish.h rename to OSlibs/android/include/openssl/blowfish.h diff --git a/android/include/openssl/bn.h b/OSlibs/android/include/openssl/bn.h similarity index 100% rename from android/include/openssl/bn.h rename to OSlibs/android/include/openssl/bn.h diff --git a/android/include/openssl/buffer.h b/OSlibs/android/include/openssl/buffer.h similarity index 100% rename from android/include/openssl/buffer.h rename to OSlibs/android/include/openssl/buffer.h diff --git a/android/include/openssl/camellia.h b/OSlibs/android/include/openssl/camellia.h similarity index 100% rename from android/include/openssl/camellia.h rename to OSlibs/android/include/openssl/camellia.h diff --git a/android/include/openssl/cast.h b/OSlibs/android/include/openssl/cast.h similarity index 100% rename from android/include/openssl/cast.h rename to OSlibs/android/include/openssl/cast.h diff --git a/android/include/openssl/cmac.h b/OSlibs/android/include/openssl/cmac.h similarity index 100% rename from android/include/openssl/cmac.h rename to OSlibs/android/include/openssl/cmac.h diff --git a/android/include/openssl/cms.h b/OSlibs/android/include/openssl/cms.h similarity index 100% rename from android/include/openssl/cms.h rename to OSlibs/android/include/openssl/cms.h diff --git a/android/include/openssl/comp.h b/OSlibs/android/include/openssl/comp.h similarity index 100% rename from android/include/openssl/comp.h rename to OSlibs/android/include/openssl/comp.h diff --git a/android/include/openssl/conf.h b/OSlibs/android/include/openssl/conf.h similarity index 100% rename from android/include/openssl/conf.h rename to OSlibs/android/include/openssl/conf.h diff --git a/android/include/openssl/conf_api.h b/OSlibs/android/include/openssl/conf_api.h similarity index 100% rename from android/include/openssl/conf_api.h rename to OSlibs/android/include/openssl/conf_api.h diff --git a/android/include/openssl/cryptlib.h b/OSlibs/android/include/openssl/cryptlib.h similarity index 100% rename from android/include/openssl/cryptlib.h rename to OSlibs/android/include/openssl/cryptlib.h diff --git a/android/include/openssl/crypto.h b/OSlibs/android/include/openssl/crypto.h similarity index 100% rename from android/include/openssl/crypto.h rename to OSlibs/android/include/openssl/crypto.h diff --git a/android/include/openssl/curl.h b/OSlibs/android/include/openssl/curl.h similarity index 100% rename from android/include/openssl/curl.h rename to OSlibs/android/include/openssl/curl.h diff --git a/android/include/openssl/curlbuild.h b/OSlibs/android/include/openssl/curlbuild.h similarity index 100% rename from android/include/openssl/curlbuild.h rename to OSlibs/android/include/openssl/curlbuild.h diff --git a/android/include/openssl/curlrules.h b/OSlibs/android/include/openssl/curlrules.h similarity index 100% rename from android/include/openssl/curlrules.h rename to OSlibs/android/include/openssl/curlrules.h diff --git a/android/include/openssl/curlver.h b/OSlibs/android/include/openssl/curlver.h similarity index 100% rename from android/include/openssl/curlver.h rename to OSlibs/android/include/openssl/curlver.h diff --git a/android/include/openssl/des.h b/OSlibs/android/include/openssl/des.h similarity index 100% rename from android/include/openssl/des.h rename to OSlibs/android/include/openssl/des.h diff --git a/android/include/openssl/des_old.h b/OSlibs/android/include/openssl/des_old.h similarity index 100% rename from android/include/openssl/des_old.h rename to OSlibs/android/include/openssl/des_old.h diff --git a/android/include/openssl/dh.h b/OSlibs/android/include/openssl/dh.h similarity index 100% rename from android/include/openssl/dh.h rename to OSlibs/android/include/openssl/dh.h diff --git a/android/include/openssl/dsa.h b/OSlibs/android/include/openssl/dsa.h similarity index 100% rename from android/include/openssl/dsa.h rename to OSlibs/android/include/openssl/dsa.h diff --git a/android/include/openssl/dso.h b/OSlibs/android/include/openssl/dso.h similarity index 100% rename from android/include/openssl/dso.h rename to OSlibs/android/include/openssl/dso.h diff --git a/android/include/openssl/dtls1.h b/OSlibs/android/include/openssl/dtls1.h similarity index 100% rename from android/include/openssl/dtls1.h rename to OSlibs/android/include/openssl/dtls1.h diff --git a/android/include/openssl/e_os.h b/OSlibs/android/include/openssl/e_os.h similarity index 100% rename from android/include/openssl/e_os.h rename to OSlibs/android/include/openssl/e_os.h diff --git a/android/include/openssl/e_os2.h b/OSlibs/android/include/openssl/e_os2.h similarity index 100% rename from android/include/openssl/e_os2.h rename to OSlibs/android/include/openssl/e_os2.h diff --git a/android/include/openssl/easy.h b/OSlibs/android/include/openssl/easy.h similarity index 100% rename from android/include/openssl/easy.h rename to OSlibs/android/include/openssl/easy.h diff --git a/android/include/openssl/ebcdic.h b/OSlibs/android/include/openssl/ebcdic.h similarity index 100% rename from android/include/openssl/ebcdic.h rename to OSlibs/android/include/openssl/ebcdic.h diff --git a/android/include/openssl/ec.h b/OSlibs/android/include/openssl/ec.h similarity index 100% rename from android/include/openssl/ec.h rename to OSlibs/android/include/openssl/ec.h diff --git a/android/include/openssl/ecdh.h b/OSlibs/android/include/openssl/ecdh.h similarity index 100% rename from android/include/openssl/ecdh.h rename to OSlibs/android/include/openssl/ecdh.h diff --git a/android/include/openssl/ecdsa.h b/OSlibs/android/include/openssl/ecdsa.h similarity index 100% rename from android/include/openssl/ecdsa.h rename to OSlibs/android/include/openssl/ecdsa.h diff --git a/android/include/openssl/engine.h b/OSlibs/android/include/openssl/engine.h similarity index 100% rename from android/include/openssl/engine.h rename to OSlibs/android/include/openssl/engine.h diff --git a/android/include/openssl/err.h b/OSlibs/android/include/openssl/err.h similarity index 100% rename from android/include/openssl/err.h rename to OSlibs/android/include/openssl/err.h diff --git a/android/include/openssl/evp.h b/OSlibs/android/include/openssl/evp.h similarity index 100% rename from android/include/openssl/evp.h rename to OSlibs/android/include/openssl/evp.h diff --git a/android/include/openssl/fips_err.h b/OSlibs/android/include/openssl/fips_err.h similarity index 100% rename from android/include/openssl/fips_err.h rename to OSlibs/android/include/openssl/fips_err.h diff --git a/android/include/openssl/hmac.h b/OSlibs/android/include/openssl/hmac.h similarity index 100% rename from android/include/openssl/hmac.h rename to OSlibs/android/include/openssl/hmac.h diff --git a/android/include/openssl/idea.h b/OSlibs/android/include/openssl/idea.h similarity index 100% rename from android/include/openssl/idea.h rename to OSlibs/android/include/openssl/idea.h diff --git a/android/include/openssl/krb5_asn.h b/OSlibs/android/include/openssl/krb5_asn.h similarity index 100% rename from android/include/openssl/krb5_asn.h rename to OSlibs/android/include/openssl/krb5_asn.h diff --git a/android/include/openssl/kssl.h b/OSlibs/android/include/openssl/kssl.h similarity index 100% rename from android/include/openssl/kssl.h rename to OSlibs/android/include/openssl/kssl.h diff --git a/android/include/openssl/lhash.h b/OSlibs/android/include/openssl/lhash.h similarity index 100% rename from android/include/openssl/lhash.h rename to OSlibs/android/include/openssl/lhash.h diff --git a/android/include/openssl/md32_common.h b/OSlibs/android/include/openssl/md32_common.h similarity index 100% rename from android/include/openssl/md32_common.h rename to OSlibs/android/include/openssl/md32_common.h diff --git a/android/include/openssl/md4.h b/OSlibs/android/include/openssl/md4.h similarity index 100% rename from android/include/openssl/md4.h rename to OSlibs/android/include/openssl/md4.h diff --git a/android/include/openssl/md5.h b/OSlibs/android/include/openssl/md5.h similarity index 100% rename from android/include/openssl/md5.h rename to OSlibs/android/include/openssl/md5.h diff --git a/android/include/openssl/mdc2.h b/OSlibs/android/include/openssl/mdc2.h similarity index 100% rename from android/include/openssl/mdc2.h rename to OSlibs/android/include/openssl/mdc2.h diff --git a/android/include/openssl/modes.h b/OSlibs/android/include/openssl/modes.h similarity index 100% rename from android/include/openssl/modes.h rename to OSlibs/android/include/openssl/modes.h diff --git a/android/include/openssl/mprintf.h b/OSlibs/android/include/openssl/mprintf.h similarity index 100% rename from android/include/openssl/mprintf.h rename to OSlibs/android/include/openssl/mprintf.h diff --git a/android/include/openssl/multi.h b/OSlibs/android/include/openssl/multi.h similarity index 100% rename from android/include/openssl/multi.h rename to OSlibs/android/include/openssl/multi.h diff --git a/android/include/openssl/o_dir.h b/OSlibs/android/include/openssl/o_dir.h similarity index 100% rename from android/include/openssl/o_dir.h rename to OSlibs/android/include/openssl/o_dir.h diff --git a/android/include/openssl/o_str.h b/OSlibs/android/include/openssl/o_str.h similarity index 100% rename from android/include/openssl/o_str.h rename to OSlibs/android/include/openssl/o_str.h diff --git a/android/include/openssl/o_time.h b/OSlibs/android/include/openssl/o_time.h similarity index 100% rename from android/include/openssl/o_time.h rename to OSlibs/android/include/openssl/o_time.h diff --git a/android/include/openssl/obj_mac.h b/OSlibs/android/include/openssl/obj_mac.h similarity index 100% rename from android/include/openssl/obj_mac.h rename to OSlibs/android/include/openssl/obj_mac.h diff --git a/android/include/openssl/objects.h b/OSlibs/android/include/openssl/objects.h similarity index 100% rename from android/include/openssl/objects.h rename to OSlibs/android/include/openssl/objects.h diff --git a/android/include/openssl/ocsp.h b/OSlibs/android/include/openssl/ocsp.h similarity index 100% rename from android/include/openssl/ocsp.h rename to OSlibs/android/include/openssl/ocsp.h diff --git a/android/include/openssl/opensslconf.h b/OSlibs/android/include/openssl/opensslconf.h similarity index 100% rename from android/include/openssl/opensslconf.h rename to OSlibs/android/include/openssl/opensslconf.h diff --git a/android/include/openssl/opensslv.h b/OSlibs/android/include/openssl/opensslv.h similarity index 100% rename from android/include/openssl/opensslv.h rename to OSlibs/android/include/openssl/opensslv.h diff --git a/android/include/openssl/ossl_typ.h b/OSlibs/android/include/openssl/ossl_typ.h similarity index 100% rename from android/include/openssl/ossl_typ.h rename to OSlibs/android/include/openssl/ossl_typ.h diff --git a/android/include/openssl/pem.h b/OSlibs/android/include/openssl/pem.h similarity index 100% rename from android/include/openssl/pem.h rename to OSlibs/android/include/openssl/pem.h diff --git a/android/include/openssl/pem2.h b/OSlibs/android/include/openssl/pem2.h similarity index 100% rename from android/include/openssl/pem2.h rename to OSlibs/android/include/openssl/pem2.h diff --git a/android/include/openssl/pkcs12.h b/OSlibs/android/include/openssl/pkcs12.h similarity index 100% rename from android/include/openssl/pkcs12.h rename to OSlibs/android/include/openssl/pkcs12.h diff --git a/android/include/openssl/pkcs7.h b/OSlibs/android/include/openssl/pkcs7.h similarity index 100% rename from android/include/openssl/pkcs7.h rename to OSlibs/android/include/openssl/pkcs7.h diff --git a/android/include/openssl/pqueue.h b/OSlibs/android/include/openssl/pqueue.h similarity index 100% rename from android/include/openssl/pqueue.h rename to OSlibs/android/include/openssl/pqueue.h diff --git a/android/include/openssl/rand.h b/OSlibs/android/include/openssl/rand.h similarity index 100% rename from android/include/openssl/rand.h rename to OSlibs/android/include/openssl/rand.h diff --git a/android/include/openssl/rc2.h b/OSlibs/android/include/openssl/rc2.h similarity index 100% rename from android/include/openssl/rc2.h rename to OSlibs/android/include/openssl/rc2.h diff --git a/android/include/openssl/rc4.h b/OSlibs/android/include/openssl/rc4.h similarity index 100% rename from android/include/openssl/rc4.h rename to OSlibs/android/include/openssl/rc4.h diff --git a/android/include/openssl/ripemd.h b/OSlibs/android/include/openssl/ripemd.h similarity index 100% rename from android/include/openssl/ripemd.h rename to OSlibs/android/include/openssl/ripemd.h diff --git a/android/include/openssl/rsa.h b/OSlibs/android/include/openssl/rsa.h similarity index 100% rename from android/include/openssl/rsa.h rename to OSlibs/android/include/openssl/rsa.h diff --git a/android/include/openssl/safestack.h b/OSlibs/android/include/openssl/safestack.h similarity index 100% rename from android/include/openssl/safestack.h rename to OSlibs/android/include/openssl/safestack.h diff --git a/android/include/openssl/seed.h b/OSlibs/android/include/openssl/seed.h similarity index 100% rename from android/include/openssl/seed.h rename to OSlibs/android/include/openssl/seed.h diff --git a/android/include/openssl/sha.h b/OSlibs/android/include/openssl/sha.h similarity index 100% rename from android/include/openssl/sha.h rename to OSlibs/android/include/openssl/sha.h diff --git a/android/include/openssl/srp.h b/OSlibs/android/include/openssl/srp.h similarity index 100% rename from android/include/openssl/srp.h rename to OSlibs/android/include/openssl/srp.h diff --git a/android/include/openssl/srtp.h b/OSlibs/android/include/openssl/srtp.h similarity index 100% rename from android/include/openssl/srtp.h rename to OSlibs/android/include/openssl/srtp.h diff --git a/android/include/openssl/ssl.h b/OSlibs/android/include/openssl/ssl.h similarity index 100% rename from android/include/openssl/ssl.h rename to OSlibs/android/include/openssl/ssl.h diff --git a/android/include/openssl/ssl2.h b/OSlibs/android/include/openssl/ssl2.h similarity index 100% rename from android/include/openssl/ssl2.h rename to OSlibs/android/include/openssl/ssl2.h diff --git a/android/include/openssl/ssl23.h b/OSlibs/android/include/openssl/ssl23.h similarity index 100% rename from android/include/openssl/ssl23.h rename to OSlibs/android/include/openssl/ssl23.h diff --git a/android/include/openssl/ssl3.h b/OSlibs/android/include/openssl/ssl3.h similarity index 100% rename from android/include/openssl/ssl3.h rename to OSlibs/android/include/openssl/ssl3.h diff --git a/android/include/openssl/stack.h b/OSlibs/android/include/openssl/stack.h similarity index 100% rename from android/include/openssl/stack.h rename to OSlibs/android/include/openssl/stack.h diff --git a/android/include/openssl/stdcheaders.h b/OSlibs/android/include/openssl/stdcheaders.h similarity index 100% rename from android/include/openssl/stdcheaders.h rename to OSlibs/android/include/openssl/stdcheaders.h diff --git a/android/include/openssl/symhacks.h b/OSlibs/android/include/openssl/symhacks.h similarity index 100% rename from android/include/openssl/symhacks.h rename to OSlibs/android/include/openssl/symhacks.h diff --git a/android/include/openssl/tls1.h b/OSlibs/android/include/openssl/tls1.h similarity index 100% rename from android/include/openssl/tls1.h rename to OSlibs/android/include/openssl/tls1.h diff --git a/android/include/openssl/ts.h b/OSlibs/android/include/openssl/ts.h similarity index 100% rename from android/include/openssl/ts.h rename to OSlibs/android/include/openssl/ts.h diff --git a/android/include/openssl/txt_db.h b/OSlibs/android/include/openssl/txt_db.h similarity index 100% rename from android/include/openssl/txt_db.h rename to OSlibs/android/include/openssl/txt_db.h diff --git a/android/include/openssl/typecheck-gcc.h b/OSlibs/android/include/openssl/typecheck-gcc.h similarity index 100% rename from android/include/openssl/typecheck-gcc.h rename to OSlibs/android/include/openssl/typecheck-gcc.h diff --git a/android/include/openssl/ui.h b/OSlibs/android/include/openssl/ui.h similarity index 100% rename from android/include/openssl/ui.h rename to OSlibs/android/include/openssl/ui.h diff --git a/android/include/openssl/ui_compat.h b/OSlibs/android/include/openssl/ui_compat.h similarity index 100% rename from android/include/openssl/ui_compat.h rename to OSlibs/android/include/openssl/ui_compat.h diff --git a/android/include/openssl/vms_rms.h b/OSlibs/android/include/openssl/vms_rms.h similarity index 100% rename from android/include/openssl/vms_rms.h rename to OSlibs/android/include/openssl/vms_rms.h diff --git a/android/include/openssl/whrlpool.h b/OSlibs/android/include/openssl/whrlpool.h similarity index 100% rename from android/include/openssl/whrlpool.h rename to OSlibs/android/include/openssl/whrlpool.h diff --git a/android/include/openssl/x509.h b/OSlibs/android/include/openssl/x509.h similarity index 100% rename from android/include/openssl/x509.h rename to OSlibs/android/include/openssl/x509.h diff --git a/android/include/openssl/x509_vfy.h b/OSlibs/android/include/openssl/x509_vfy.h similarity index 100% rename from android/include/openssl/x509_vfy.h rename to OSlibs/android/include/openssl/x509_vfy.h diff --git a/android/include/openssl/x509v3.h b/OSlibs/android/include/openssl/x509v3.h similarity index 100% rename from android/include/openssl/x509v3.h rename to OSlibs/android/include/openssl/x509v3.h diff --git a/android/include/openssl/zconf.h b/OSlibs/android/include/openssl/zconf.h similarity index 100% rename from android/include/openssl/zconf.h rename to OSlibs/android/include/openssl/zconf.h diff --git a/android/include/openssl/zlib.h b/OSlibs/android/include/openssl/zlib.h similarity index 100% rename from android/include/openssl/zlib.h rename to OSlibs/android/include/openssl/zlib.h diff --git a/android/lib/libcrypto.so b/OSlibs/android/lib/libcrypto.so similarity index 100% rename from android/lib/libcrypto.so rename to OSlibs/android/lib/libcrypto.so diff --git a/android/lib/libcurl.a b/OSlibs/android/lib/libcurl.a similarity index 100% rename from android/lib/libcurl.a rename to OSlibs/android/lib/libcurl.a diff --git a/android/lib/libssl.so b/OSlibs/android/lib/libssl.so similarity index 100% rename from android/lib/libssl.so rename to OSlibs/android/lib/libssl.so diff --git a/android/set_android_env.sh b/OSlibs/android/set_android_env.sh similarity index 100% rename from android/set_android_env.sh rename to OSlibs/android/set_android_env.sh diff --git a/ios/iOS_Readme.md b/OSlibs/ios/iOS_Readme.md similarity index 100% rename from ios/iOS_Readme.md rename to OSlibs/ios/iOS_Readme.md diff --git a/ios/lib/libcrypto.a b/OSlibs/ios/lib/libcrypto.a similarity index 100% rename from ios/lib/libcrypto.a rename to OSlibs/ios/lib/libcrypto.a diff --git a/ios/lib/libcurl.a b/OSlibs/ios/lib/libcurl.a similarity index 100% rename from ios/lib/libcurl.a rename to OSlibs/ios/lib/libcurl.a diff --git a/ios/lib/libssl.a b/OSlibs/ios/lib/libssl.a similarity index 100% rename from ios/lib/libssl.a rename to OSlibs/ios/lib/libssl.a diff --git a/osx/libcrypto.a b/OSlibs/osx/libcrypto.a similarity index 100% rename from osx/libcrypto.a rename to OSlibs/osx/libcrypto.a diff --git a/osx/libcurl.a b/OSlibs/osx/libcurl.a similarity index 100% rename from osx/libcurl.a rename to OSlibs/osx/libcurl.a diff --git a/osx/libgmp.a b/OSlibs/osx/libgmp.a similarity index 100% rename from osx/libgmp.a rename to OSlibs/osx/libgmp.a diff --git a/osx/libsecp256k1.a b/OSlibs/osx/libsecp256k1.a similarity index 100% rename from osx/libsecp256k1.a rename to OSlibs/osx/libsecp256k1.a diff --git a/osx/libssl.a b/OSlibs/osx/libssl.a similarity index 100% rename from osx/libssl.a rename to OSlibs/osx/libssl.a diff --git a/win/libcrypto.a b/OSlibs/win/libcrypto.a similarity index 100% rename from win/libcrypto.a rename to OSlibs/win/libcrypto.a diff --git a/win/libcurl.a b/OSlibs/win/libcurl.a similarity index 100% rename from win/libcurl.a rename to OSlibs/win/libcurl.a diff --git a/win/libcurldll.a b/OSlibs/win/libcurldll.a similarity index 100% rename from win/libcurldll.a rename to OSlibs/win/libcurldll.a diff --git a/win/libpthreadGC2.a b/OSlibs/win/libpthreadGC2.a similarity index 100% rename from win/libpthreadGC2.a rename to OSlibs/win/libpthreadGC2.a diff --git a/win/libpthreadGC2_64.a b/OSlibs/win/libpthreadGC2_64.a similarity index 100% rename from win/libpthreadGC2_64.a rename to OSlibs/win/libpthreadGC2_64.a diff --git a/win/libsecp256k1.a b/OSlibs/win/libsecp256k1.a similarity index 100% rename from win/libsecp256k1.a rename to OSlibs/win/libsecp256k1.a diff --git a/win/libssl.a b/OSlibs/win/libssl.a similarity index 100% rename from win/libssl.a rename to OSlibs/win/libssl.a diff --git a/win/mingw.c b/OSlibs/win/mingw.c similarity index 100% rename from win/mingw.c rename to OSlibs/win/mingw.c diff --git a/win/mingw.h b/OSlibs/win/mingw.h similarity index 100% rename from win/mingw.h rename to OSlibs/win/mingw.h diff --git a/win/mman.h b/OSlibs/win/mman.h similarity index 100% rename from win/mman.h rename to OSlibs/win/mman.h diff --git a/win/pthread.h b/OSlibs/win/pthread.h similarity index 100% rename from win/pthread.h rename to OSlibs/win/pthread.h diff --git a/win/pthreadGC2.dll b/OSlibs/win/pthreadGC2.dll similarity index 100% rename from win/pthreadGC2.dll rename to OSlibs/win/pthreadGC2.dll diff --git a/win/pthreadGC2_64.dll b/OSlibs/win/pthreadGC2_64.dll similarity index 100% rename from win/pthreadGC2_64.dll rename to OSlibs/win/pthreadGC2_64.dll diff --git a/win/sched.h b/OSlibs/win/sched.h similarity index 100% rename from win/sched.h rename to OSlibs/win/sched.h diff --git a/win/semaphore.h b/OSlibs/win/semaphore.h similarity index 100% rename from win/semaphore.h rename to OSlibs/win/semaphore.h diff --git a/README.md b/README.md index 1271d57ed..9760387fb 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,15 @@ #SuperNET Client "iguana" +Codebase is going under radical changes now and versions from mid-May should be used unless you are doing advanced testing. There will be four layers: + +gecko: abstracted bitcoin compatible blockchains that run via basilisk lite mode or as iguana core full network peers. I will try to get a geckochain to simultaneously have both virtual basilisk nodes and private iguana nodes, but at first will probably need to choose which mode a new chain will be and transition between the two via special suspend and resume functions that allow migration from virtual to physical. Each specific geckochain will be able to be enhanced into a datachain. + +basilisk: abstracted crypto transactions layer, which has a reference implementation for bitcoin protocol via the iguana nodes, but can be expanded to support any coin protocol that can support the required functions. Since it works with bitcoin protocol, any 2.0 coin with at least bitcoin level functionality should be able to create a basilisk interface. + +iguana: most efficient bitcoin core implementation that can simultaneously be full peers for multiple bitcoin blockchains. Special support being added to virtualize blockchains so all can share the same peers. The iguana peers identify as a supernet node, regardless of which coin, so by having nodes that support multiple coins, supernet peers are propagated across all coins. non-iguana peers wont get any non-standard packets so it is interoperable with all the existing bitcoin and bitcoin clone networks + +komodo: this is the top secret project I cant talk about publicly yet + > #TL;DR# > > ```sudo apt-get update; sudo apt-get install git build-essential; git clone https://github.com/jl777/SuperNET; cd SuperNET; ./m_onetime m_unix;``` diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 85f96d226..a86c42cff 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -66,19 +66,21 @@ uint8_t *get_dataptr(uint8_t **ptrp,int32_t *datalenp,uint8_t *space,int32_t spa if ( hexstr != 0 && (*datalenp= is_hexstr(hexstr,0)) > 0 ) { *datalenp >>= 1; - if ( *datalenp+sizeof(struct iguana_msghdr)+sizeof(basilisktag) <= spacesize ) + if ( (*datalenp+BASILISK_HDROFFSET) <= spacesize ) { - memset(space,0,sizeof(struct iguana_msghdr)+sizeof(basilisktag)); - data = &space[sizeof(struct iguana_msghdr)+sizeof(basilisktag)]; - } else *ptrp = data = calloc(1,*datalenp + sizeof(struct iguana_msghdr)+sizeof(basilisktag)); - decode_hex(&data[sizeof(struct iguana_msghdr)+sizeof(basilisktag)],*datalenp,hexstr); + memset(space,0,BASILISK_HDROFFSET); + data = &space[BASILISK_HDROFFSET]; + } else *ptrp = data = calloc(1,*datalenp + BASILISK_HDROFFSET); + decode_hex(&data[BASILISK_HDROFFSET],*datalenp,hexstr); } - return(data); + if ( data != 0 ) + return(&data[BASILISK_HDROFFSET]); + else return(data); } uint8_t *basilisk_jsondata(uint8_t **ptrp,uint8_t *space,int32_t spacesize,int32_t *datalenp,char *symbol,cJSON *sendjson,uint32_t basilisktag) { - char *sendstr,*hexstr; uint8_t *data; bits256 pubkey; int32_t i,datalen,hexlen=0,extrasize,havepubkey=1; + char *sendstr,*hexstr; uint8_t *data; bits256 pubkey; int32_t i,datalen,hexlen=0,havepubkey=1; if ( jobj(sendjson,"coin") == 0 ) jaddstr(sendjson,"coin",symbol); if ( jobj(sendjson,"pubkey") != 0 ) @@ -88,18 +90,17 @@ uint8_t *basilisk_jsondata(uint8_t **ptrp,uint8_t *space,int32_t spacesize,int32 } if ( (hexstr= jstr(sendjson,"data")) != 0 && (hexlen= is_hexstr(hexstr,0)) > 0 ) hexlen >>= 1; - extrasize = (int32_t)(sizeof(struct iguana_msghdr) + sizeof(basilisktag)); *ptrp = 0; sendstr = jprint(sendjson,0); datalen = (int32_t)strlen(sendstr) + 1; - if ( (datalen + extrasize + hexlen + havepubkey*(sizeof(pubkey)+1)) <= spacesize ) + if ( (datalen + BASILISK_HDROFFSET + hexlen + havepubkey*(sizeof(pubkey)+1)) <= spacesize ) data = space; else { - data = calloc(1,datalen + extrasize + hexlen + havepubkey*(sizeof(pubkey)+1)); + data = calloc(1,datalen + BASILISK_HDROFFSET + hexlen + havepubkey*(sizeof(pubkey)+1)); *ptrp = data; } - data += extrasize; + data += BASILISK_HDROFFSET; memcpy(data,sendstr,datalen); free(sendstr); if ( havepubkey != 0 || hexlen != 0 ) @@ -156,46 +157,9 @@ struct basilisk_item *basilisk_itemcreate(struct supernet_info *myinfo,char *CMD return(ptr); } -/*int32_t basilisk_sendPUB(struct supernet_info *myinfo,uint32_t basilisktag,uint8_t *data,int32_t datalen) // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag) -{ - int32_t i,j,r,r2,s,k,val,l,n=0; uint32_t *alreadysent; struct iguana_info *coin; struct iguana_peer *addr; - alreadysent = calloc(IGUANA_MAXPEERS * IGUANA_MAXCOINS,sizeof(*alreadysent)); - r = rand(), r2 = rand(); - for (k=0; kpeers.active[i]) != 0 && addr->ipbits != 0 && addr->usock >= 0 && addr->basilisk != 0 ) - { - for (s=0; sipbits ) - break; - if ( s == n ) - { - printf("pub (%s) addr->supernet.%u to (%s).%d\n",(char *)&data[4],addr->supernet,addr->ipaddr,addr->A.port); - if ( (val= iguana_queue_send(addr,0,&data[-sizeof(struct iguana_msghdr)],"SuperNETpub",datalen)) >= datalen ) - { - alreadysent[n++] = (uint32_t)addr->ipbits; - if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS ) - break; - } - } - } - } - if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS ) - break; - } - free(alreadysent); - return(n); -}*/ - int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t *basilisktagp,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout,uint32_t nBits) // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag) { - int32_t i,j,r,r2,k,l,s,val,n=0,offset,havepubkey=0,retval = -1; char cmd[12]; struct iguana_info *coin; struct iguana_peer *addr; bits256 pubkey; uint32_t *alreadysent; + int32_t i,r,l,s,val,n=0,offset,havepubkey=0,retval = -1; char cmd[12]; struct iguana_info *coin,*tmp; struct iguana_peer *addr; bits256 pubkey; uint32_t *alreadysent; if ( fanout <= 0 ) fanout = BASILISK_MINFANOUT; else if ( fanout > BASILISK_MAXFANOUT ) @@ -235,11 +199,11 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ data -= sizeof(*basilisktagp), datalen += sizeof(*basilisktagp); memset(cmd,0,sizeof(cmd)); sprintf(cmd,"SuperNET%s",type); - r = rand(), r2 = rand(); - for (k=0; kallcoins,coin,tmp) { - j = (r2 + k) % IGUANA_MAXCOINS; - if ( (coin= Coins[j]) == 0 || coin->peers == 0 ) + if ( coin->peers == 0 ) continue; if ( coin->RELAYNODE == 0 && coin->VALIDATENODE == 0 ) cmd[0] = 's'; @@ -247,15 +211,17 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ for (l=0; lpeers->active[i]) != 0 && addr->usock >= 0 ) + addr = &coin->peers->active[i]; + if ( addr->usock >= 0 ) { for (s=0; sipbits ) break; //printf("%s s.%d vs n.%d\n",addr->ipaddr,s,n); + printf("[%s] send %s.(%s) addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",cmd,type,(char *)&data[4],addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast"); if ( s == n && (addr->supernet != 0 || addr->basilisk != 0) && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) ) { - printf("[%s] send %s.(%s) addr->supernet.%u to (%s).%d destip.%s\n",cmd,type,(char *)&data[4],addr->supernet,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast"); + printf("[%s] send %s.(%s) addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",cmd,type,(char *)&data[4],addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast"); if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 ) { void *ptr; uint8_t *cipher,space[8192]; int32_t cipherlen; bits256 privkey; @@ -292,10 +258,32 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS ) break; } + //portable_mutex_unlock(&Allcoins_mutex); free(alreadysent); return(n); } +int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *virt,char *blockstr) +{ + struct iguana_txblock txdata; int32_t recvlen,n,len = -1;; struct iguana_msghdr H; uint8_t *data,space[16384],*allocptr; + if ( virt->TXMEM.ptr == 0 ) + iguana_meminit(&virt->TXMEM,virt->name,0,IGUANA_MAXPACKETSIZE * 2,0); + iguana_memreset(&virt->TXMEM); + if ( (data= get_dataptr(&allocptr,&recvlen,space,sizeof(space),blockstr)) != 0 ) + { + memset(&txdata,0,sizeof(txdata)); + if ( (n= iguana_gentxarray(virt,&virt->TXMEM,&txdata,&len,data,recvlen)) == recvlen ) + { + len = n; + memset(&H,0,sizeof(H)); + iguana_gotblockM(virt,&virt->internaladdr,&txdata,virt->TXMEM.ptr,&H,data,recvlen); + } + } + if ( allocptr != 0 ) + free(allocptr); + return(len); +} + void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t datalen,char *type,int32_t encrypted) { uint32_t ipbits,basilisktag; int32_t i,havepubkey,msglen,len=0; void *ptr = 0; uint8_t space[8192]; bits256 senderpub,pubkey,hash,hash2; struct supernet_info *myinfo = _myinfo; @@ -747,6 +735,179 @@ HASH_ARRAY_STRING(basilisk,VPNlogout,pubkey,vals,hexstr) #include "../includes/iguana_apiundefs.h" +void basilisks_loop(void *arg) +{ + basilisk_metricfunc metricfunc; struct iguana_info *btcd,*virt,*hhtmp; struct basilisk_item *ptr,*tmp,*pending,*parent; int32_t i,iter,maxmillis,done,flag,n; cJSON *valsobj,*retjson; uint32_t now; struct supernet_info *myinfo = arg; + //uint8_t *blockspace; struct OS_memspace RAWMEM; + //memset(&RAWMEM,0,sizeof(RAWMEM)); + //blockspace = calloc(1,IGUANA_MAXPACKETSIZE); + iter = 0; + while ( 1 ) + { + iter++; + if ( (ptr= queue_dequeue(&myinfo->basilisks.submitQ,0)) != 0 ) + { + if ( ptr->finished == 0 ) + HASH_ADD(hh,myinfo->basilisks.issued,basilisktag,sizeof(ptr->basilisktag),ptr); + else free(ptr); + continue; + } + if ( (ptr= queue_dequeue(&myinfo->basilisks.resultsQ,0)) != 0 ) + { + HASH_FIND(hh,myinfo->basilisks.issued,&ptr->basilisktag,sizeof(ptr->basilisktag),pending); + if ( pending != 0 ) + { + if ( (n= pending->numresults) < sizeof(pending->results)/sizeof(*pending->results) ) + { + pending->numresults++; + if ( (metricfunc= pending->metricfunc) == 0 ) + pending->metrics[n] = n + 1; + else if ( (pending->metrics[n]= (*metricfunc)(myinfo,pending,ptr->retstr)) != 0. ) + pending->childrendone++; + printf("%u Add results[%d] <- (%s) metric %f\n",pending->basilisktag,n,ptr->retstr,pending->metrics[n]); + pending->results[n] = ptr->retstr; + if ( strcmp(ptr->CMD,"SEQ") == 0 ) + { + if ( (retjson= cJSON_Parse(ptr->retstr)) != 0 ) + { + gecko_seqresult(myinfo,ptr->retstr); + free_json(retjson); + } + } + } + } + free(ptr); + continue; + } + flag = 0; + HASH_ITER(hh,myinfo->basilisks.issued,pending,tmp) + { + //printf("pending.%u numresults.%d m %f func.%p\n",pending->basilisktag,pending->numresults,pending->metrics[0],pending->metricfunc); + if ( (metricfunc= pending->metricfunc) != 0 ) + { + for (i=0; inumresults; i++) + if ( pending->metrics[i] == 0. && pending->results[i] != 0 ) + { + if ( (pending->metrics[i]= (*metricfunc)(myinfo,pending,pending->results[i])) != 0 ) + pending->childrendone++; + // printf("iter.%d %p.[%d] poll metrics.%u metric %f\n",iter,pending,i,pending->basilisktag,pending->metrics[i]); + flag++; + } + } + basilisk_iscomplete(pending); + if ( OS_milliseconds() > pending->expiration ) + { + if ( pending->finished == 0 ) + { + if ( (parent= pending->parent) != 0 ) + { + pending->parent = 0; + parent->childrendone++; + } + pending->finished = (uint32_t)time(NULL); + if ( pending->retstr == 0 ) + pending->retstr = clonestr("{\"error\":\"basilisk timeout\"}"); + printf("timeout call metrics.%u lag %f - %f\n",pending->basilisktag,OS_milliseconds(),pending->expiration); + for (i=0; inumresults; i++) + if ( (metricfunc= pending->metricfunc) != 0 ) + pending->metrics[i] = (*metricfunc)(myinfo,pending,pending->results[i]); + flag++; + } + } + if ( pending->finished != 0 && time(NULL) > pending->finished+60 ) + { + if ( pending->dependents == 0 || pending->childrendone >= pending->numchildren ) + { + HASH_DELETE(hh,myinfo->basilisks.issued,pending); + if ( pending->dependents != 0 ) + free(pending->dependents); + printf("HASH_DELETE free ptr.%u\n",pending->basilisktag); + for (i=0; inumresults; i++) + if ( pending->results[i] != 0 ) + free(pending->results[i]); + if ( pending->vals != 0 ) + free_json(pending->vals); + free(pending); + flag++; + } + } + } + if ( (btcd= iguana_coinfind("BTCD")) != 0 ) + { + done = 3; + if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 ) + { + if ( (now= (uint32_t)time(NULL)) > btcd->SEQ.BTCD.lastupdate+10 ) + { + if ( gecko_sequpdate("BTCD",now) >= 0 ) + done &= ~1; + btcd->SEQ.BTCD.lastupdate = (uint32_t)time(NULL); + } + } + if ( (now= (uint32_t)time(NULL)) > btcd->SEQ.BTC.lastupdate+30 ) + { + if ( gecko_sequpdate("BTC",now) >= 0 ) + done &= ~2; + btcd->SEQ.BTC.lastupdate = (uint32_t)time(NULL); + } + if ( done != 3 ) + { + valsobj = cJSON_CreateObject(); + if ( btcd->RELAYNODE == 0 && btcd->VALIDATENODE == 0 ) + { + jaddnum(valsobj,"BTCD",btcd->SEQ.BTCD.numstamps+GECKO_FIRSTPOSSIBLEBTCD); + basilisk_standardservice("SEQ",myinfo,GENESIS_PUBKEY,valsobj,0,0); + flag++; + } + if ( (done & 2) == 0 ) + { + free_json(valsobj); + valsobj = cJSON_CreateObject(); + jaddnum(valsobj,"BTC",btcd->SEQ.BTC.numstamps+GECKO_FIRSTPOSSIBLEBTC); + basilisk_standardservice("SEQ",myinfo,GENESIS_PUBKEY,valsobj,0,0); + flag++; + } + free_json(valsobj); + } + if ( flag == 0 && myinfo->allcoins_numvirts > 0 ) + { + char mineraddr[64]; + maxmillis = (1000 / myinfo->allcoins_numvirts) + 1; + //portable_mutex_lock(&Allcoins_mutex); + HASH_ITER(hh,myinfo->allcoins,virt,hhtmp) + { + if ( iguana_processrecv(myinfo,virt) == 0 ) + { + bitcoin_address(mineraddr,virt->chain->pubtype,myinfo->persistent_pubkey33,33); + //printf("mine.%s %s\n",virt->symbol,mineraddr); + gecko_miner(myinfo,btcd,virt,maxmillis,mineraddr); + } + flag++; + } + //portable_mutex_unlock(&Allcoins_mutex); + } + } + //for (i=0; iRELAYNODE == 0 && coin->VALIDATENODE == 0 && coin->active != 0 && coin->chain->userpass[0] != 0 && coin->MAXPEERS == 1 ) + // basilisk_bitcoinscan(coin,blockspace,&RAWMEM); + if ( flag == 0 ) + usleep(10000); + } +} + +void basilisks_init(struct supernet_info *myinfo) +{ + //bits256 basiliskhash; + iguana_initQ(&myinfo->basilisks.submitQ,"submitQ"); + iguana_initQ(&myinfo->basilisks.resultsQ,"resultsQ"); + //basiliskhash = calc_categoryhashes(0,"basilisk",0); + //myinfo->basilisk_category = basiliskhash; + //category_subscribe(myinfo,basiliskhash,GENESIS_PUBKEY); + //category_processfunc(basiliskhash,GENESIS_PUBKEY,basilisk_hexmsg); + //category_processfunc(basiliskhash,myinfo->myaddr.persistent,basilisk_hexmsg); + myinfo->basilisks.launched = iguana_launch(iguana_coinfind("BTCD"),"basilisks_loop",basilisks_loop,myinfo,IGUANA_PERMTHREAD); +} + void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t senderipbits,char *type,uint32_t basilisktag,uint8_t *data,int32_t datalen,bits256 pubkey) { cJSON *valsobj; char *symbol,*retstr=0,remoteaddr[64],CMD[4],cmd[4]; int32_t origlen,from_basilisk,i,timeoutmillis,numrequired,jsonlen; uint8_t *origdata; struct iguana_info *coin=0; @@ -754,13 +915,14 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender { { (void *)"RUN", &basilisk_respond_dispatch }, // higher level protocol handler, pass through { (void *)"BYE", &basilisk_respond_goodbye }, // disconnect - - // private chains - { (void *)"NEW", &basilisk_respond_newprivatechain }, // creates new virtual private chain + + // gecko chains + { (void *)"NEW", &basilisk_respond_newgeckochain }, // creates new virtual gecko chain { (void *)"SEQ", &basilisk_respond_hashstamps }, // BTCD and BTC recent hashes from timestamp - { (void *)"VTX", &basilisk_respond_privatetx }, // adding field to one relay propagates to all others - { (void *)"BLK", &basilisk_respond_privateblock }, // any relay can be queried - + { (void *)"VTX", &basilisk_respond_geckotx }, + { (void *)"BLK", &basilisk_respond_geckoblock }, + { (void *)"GEN", &basilisk_respond_geckogenesis }, + // unencrypted low level functions, used by higher level protocols and virtual network funcs { (void *)"ADD", &basilisk_respond_addrelay }, // relays register with each other bus { (void *)"PUB", &basilisk_respond_publish }, // adds to global list of published items @@ -869,156 +1031,4 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender free(retstr); } -void basilisks_loop(void *arg) -{ - basilisk_metricfunc metricfunc; struct iguana_info *btcd; struct basilisk_item *ptr,*tmp,*pending,*parent; int32_t i,iter,done,flag,n; cJSON *valsobj,*retjson; uint32_t now; struct supernet_info *myinfo = arg; - //uint8_t *blockspace; struct OS_memspace RAWMEM; - //memset(&RAWMEM,0,sizeof(RAWMEM)); - //blockspace = calloc(1,IGUANA_MAXPACKETSIZE); - iter = 0; - while ( 1 ) - { - iter++; - if ( (btcd= iguana_coinfind("BTCD")) != 0 ) - { - done = 3; - if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 ) - { - if ( (now= (uint32_t)time(NULL)) > btcd->SEQ.BTCD.lastupdate+10 ) - { - if ( basilisk_update("BTCD",now) >= 0 ) - done &= ~1; - btcd->SEQ.BTCD.lastupdate = (uint32_t)time(NULL); - } - } - if ( (now= (uint32_t)time(NULL)) > btcd->SEQ.BTC.lastupdate+30 ) - { - if ( basilisk_update("BTC",now) >= 0 ) - done &= ~2; - btcd->SEQ.BTC.lastupdate = (uint32_t)time(NULL); - } - if ( done != 3 ) - { - valsobj = cJSON_CreateObject(); - if ( btcd->RELAYNODE == 0 && btcd->VALIDATENODE == 0 ) - { - jaddnum(valsobj,"BTCD",btcd->SEQ.BTCD.numstamps+BASILISK_FIRSTPOSSIBLEBTCD); - basilisk_standardservice("SEQ",myinfo,GENESIS_PUBKEY,valsobj,0,0); - } - if ( (done & 2) == 0 ) - { - free_json(valsobj); - valsobj = cJSON_CreateObject(); - jaddnum(valsobj,"BTC",btcd->SEQ.BTC.numstamps+BASILISK_FIRSTPOSSIBLEBTC); - basilisk_standardservice("SEQ",myinfo,GENESIS_PUBKEY,valsobj,0,0); - } - free_json(valsobj); - } - } - //for (i=0; iRELAYNODE == 0 && coin->VALIDATENODE == 0 && coin->active != 0 && coin->chain->userpass[0] != 0 && coin->MAXPEERS == 1 ) - // basilisk_bitcoinscan(coin,blockspace,&RAWMEM); - if ( (ptr= queue_dequeue(&myinfo->basilisks.submitQ,0)) != 0 ) - { - if ( ptr->finished == 0 ) - HASH_ADD(hh,myinfo->basilisks.issued,basilisktag,sizeof(ptr->basilisktag),ptr); - else free(ptr); - continue; - } - if ( (ptr= queue_dequeue(&myinfo->basilisks.resultsQ,0)) != 0 ) - { - HASH_FIND(hh,myinfo->basilisks.issued,&ptr->basilisktag,sizeof(ptr->basilisktag),pending); - if ( pending != 0 ) - { - if ( (n= pending->numresults) < sizeof(pending->results)/sizeof(*pending->results) ) - { - pending->numresults++; - if ( (metricfunc= pending->metricfunc) == 0 ) - pending->metrics[n] = n + 1; - else if ( (pending->metrics[n]= (*metricfunc)(myinfo,pending,ptr->retstr)) != 0. ) - pending->childrendone++; - printf("%u Add results[%d] <- (%s) metric %f\n",pending->basilisktag,n,ptr->retstr,pending->metrics[n]); - pending->results[n] = ptr->retstr; - if ( strcmp(ptr->CMD,"SEQ") == 0 ) - { - if ( (retjson= cJSON_Parse(ptr->retstr)) != 0 ) - { - basilisk_seqresult(myinfo,ptr->retstr); - free_json(retjson); - } - } - } - } - free(ptr); - continue; - } - flag = 0; - HASH_ITER(hh,myinfo->basilisks.issued,pending,tmp) - { - //printf("pending.%u numresults.%d m %f func.%p\n",pending->basilisktag,pending->numresults,pending->metrics[0],pending->metricfunc); - if ( (metricfunc= pending->metricfunc) != 0 ) - { - for (i=0; inumresults; i++) - if ( pending->metrics[i] == 0. && pending->results[i] != 0 ) - { - if ( (pending->metrics[i]= (*metricfunc)(myinfo,pending,pending->results[i])) != 0 ) - pending->childrendone++; - // printf("iter.%d %p.[%d] poll metrics.%u metric %f\n",iter,pending,i,pending->basilisktag,pending->metrics[i]); - flag++; - } - } - basilisk_iscomplete(pending); - if ( OS_milliseconds() > pending->expiration ) - { - if ( pending->finished == 0 ) - { - if ( (parent= pending->parent) != 0 ) - { - pending->parent = 0; - parent->childrendone++; - } - pending->finished = (uint32_t)time(NULL); - if ( pending->retstr == 0 ) - pending->retstr = clonestr("{\"error\":\"basilisk timeout\"}"); - printf("timeout call metrics.%u lag %f - %f\n",pending->basilisktag,OS_milliseconds(),pending->expiration); - for (i=0; inumresults; i++) - if ( (metricfunc= pending->metricfunc) != 0 ) - pending->metrics[i] = (*metricfunc)(myinfo,pending,pending->results[i]); - } - } - if ( pending->finished != 0 && time(NULL) > pending->finished+60 ) - { - if ( pending->dependents == 0 || pending->childrendone >= pending->numchildren ) - { - HASH_DELETE(hh,myinfo->basilisks.issued,pending); - if ( pending->dependents != 0 ) - free(pending->dependents); - printf("HASH_DELETE free ptr.%u\n",pending->basilisktag); - for (i=0; inumresults; i++) - if ( pending->results[i] != 0 ) - free(pending->results[i]); - if ( pending->vals != 0 ) - free_json(pending->vals); - free(pending); - flag++; - } - } - } - if ( flag == 0 ) - usleep(50000); - else usleep(10000); - } -} -void basilisks_init(struct supernet_info *myinfo) -{ - //bits256 basiliskhash; - iguana_initQ(&myinfo->basilisks.submitQ,"submitQ"); - iguana_initQ(&myinfo->basilisks.resultsQ,"resultsQ"); - //basiliskhash = calc_categoryhashes(0,"basilisk",0); - //myinfo->basilisk_category = basiliskhash; - //category_subscribe(myinfo,basiliskhash,GENESIS_PUBKEY); - //category_processfunc(basiliskhash,GENESIS_PUBKEY,basilisk_hexmsg); - //category_processfunc(basiliskhash,myinfo->myaddr.persistent,basilisk_hexmsg); - myinfo->basilisks.launched = iguana_launch(iguana_coinfind("BTCD"),"basilisks_loop",basilisks_loop,myinfo,IGUANA_PERMTHREAD); -} diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index f1628df81..18c8d00de 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -21,23 +21,11 @@ #define BASILISK_TIMEOUT 30000 #define BASILISK_MINFANOUT 8 #define BASILISK_MAXFANOUT 64 +#define BASILISK_DEFAULTDIFF 0x1effffff #define BASILISK_MAXFUTUREBLOCK 60 #define BASILISK_MAXBLOCKLAG 600 -#define BASILISK_MAXBTCGAP 9 -#define BASILISK_MAXBTCDGAP 18 - -#define BASILISK_DEFAULTVERSION 1 -#define BASILISK_DEFAULTDIFF 0x1effffff -#define BASILISK_DEFAULTDIFFSTR "1effffff" - -#define BASILISK_FIRSTPOSSIBLEBTC 414000 -#define BASILISK_FIRSTPOSSIBLEBTCD 1100000 -#define BASILISK_MAXNAMELEN 64 - -struct hashstamp { bits256 hash2; uint32_t timestamp; int32_t height; }; -struct basilisk_sequence { struct hashstamp *stamps; int32_t lastupdate,maxstamps,numstamps,lasti,longestchain; }; -struct basilisk_sequences { struct basilisk_sequence BTC,BTCD; }; +#define BASILISK_HDROFFSET ((int32_t)(sizeof(struct iguana_msghdr)+sizeof(basilisktag))) struct basilisk_value { bits256 txid; int64_t value; int32_t height; int16_t vout; char coinaddr[64]; }; @@ -57,6 +45,7 @@ struct basilisk_info }; void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t senderipbits,char *type,uint32_t basilisktag,uint8_t *data,int32_t datalen,bits256 pubkey); +int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t *basilisktagp,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout,uint32_t nBits); // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag) void basilisks_init(struct supernet_info *myinfo); void basilisk_p2p(void *myinfo,void *_addr,char *ipaddr,uint8_t *data,int32_t datalen,char *type,int32_t encrypted); @@ -68,10 +57,6 @@ uint8_t *get_dataptr(uint8_t **ptrp,int32_t *datalenp,uint8_t *space,int32_t spa char *basilisk_addhexstr(char **ptrp,cJSON *valsobj,char *strbuf,int32_t strsize,uint8_t *data,int32_t datalen); char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,bits256 hash,cJSON *valsobj,char *hexstr,int32_t blockflag); // client side -char *basilisk_respond_hashstamps(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk); -char *basilisk_respond_newprivatechain(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk); -char *basilisk_respond_privatetx(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk); -char *basilisk_respond_privateblock(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk); void basilisk_request_goodbye(struct supernet_info *myinfo); int32_t basilisk_update(char *symbol,uint32_t reftimestamp); diff --git a/basilisk/basilisk_CMD.c b/basilisk/basilisk_CMD.c index b2a2c2642..fd8f12558 100755 --- a/basilisk/basilisk_CMD.c +++ b/basilisk/basilisk_CMD.c @@ -13,7 +13,7 @@ * * ******************************************************************************/ -#include "../iguana/iguana777.h" +// included from basilisk.c char *basilisk_respond_goodbye(struct supernet_info *myinfo,char *CMD,void *_addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index c984fb9bb..a67259a1a 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -591,7 +591,7 @@ void *basilisk_bitcoinrawtx(struct basilisk_item *Lptr,struct supernet_info *myi { if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 ) { - if ( (txobj= bitcoin_txcreate(coin->chain->txhastimestamp,locktime)) != 0 ) + if ( (txobj= bitcoin_txcreate(coin->chain->isPoS,locktime,locktime==0?coin->chain->normal_txversion:coin->chain->locktime_txversion)) != 0 ) { spendlen = (int32_t)strlen(spendscriptstr) >> 1; decode_hex(buf,spendlen,spendscriptstr); diff --git a/basilisk/basilisk_privatechains.c b/basilisk/basilisk_privatechains.c deleted file mode 100755 index fcba3ea52..000000000 --- a/basilisk/basilisk_privatechains.c +++ /dev/null @@ -1,695 +0,0 @@ -/****************************************************************************** - * Copyright © 2014-2016 The SuperNET Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * SuperNET software, including this file may be copied, modified, propagated * - * or distributed except according to the terms contained in the LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -#include "../iguana/iguana777.h" - -/*int32_t basilist_validateblock(cJSON *valsobj) - { - uint32_t now,timestamp; - now = (uint32_t)time(NULL); - if ( (timestamp= juint(valsobj,"timestamp")) < now-BASILISK_MAXBLOCKLAG || timestamp > now+BASILISK_MAXFUTUREBLOCK ) - return(-1); - if ( bits256_nonz(prevhash) == 0 ) - prevhash = coin->blocks.hwmchain.RO.hash2; - if ( (prevblock= iguana_blockfind("setfield",coin,prevhash)) == 0 ) - return(clonestr("{\"error\":\"couldnt find prevhash\"}")); - if ( (prev2= iguana_blockfind("setfield",coin,prevblock->RO.prev_block)) == 0 ) - return(clonestr("{\"error\":\"couldnt find prevhash2\"}")); - nonce = juint(valsobj,"nonce"); - nBits = iguana_targetbits(coin,&coin->blocks.hwmchain,prevblock,prev2,1,coin->chain->targetspacing,coin->chain->targettimespan); - blocktx = basilisk_block(myinfo,coin,&block,1,timestamp,&nonce,prevhash,nBits,prevblock->height+1,0,0,data,datalen,btcdhash,jobj(valsobj,"coinbase")); - - return(0); - }*/ - -int32_t basilisk_hashstampsfind(struct hashstamp *stamps,int32_t max,struct basilisk_sequence *seq,bits256 hash,uint32_t reftimestamp) -{ - int32_t j,i = 0,foundflag = -1,gap = -1; uint32_t timestamp; - if ( seq->stamps == 0 ) - return(-1); - if ( seq->stamps[seq->lasti].timestamp < reftimestamp && seq->lasti >= 3 ) - i = seq->lasti - 3; - for (; inumstamps; i++) - { - if ( (timestamp= seq->stamps[i].timestamp) == 0 || timestamp > reftimestamp ) - { - memset(stamps,0,sizeof(*stamps) * max); - for (j=0; j=0; j++) - stamps[j] = seq->stamps[i - j]; - return(gap); - } - if ( foundflag < 0 && bits256_cmp(hash,seq->stamps[i].hash2) == 0 ) - { - seq->lasti = i; - foundflag = i; - gap = 0; - } - else if ( foundflag >= 0 ) - gap++; - } - return(-1); -} - -bits256 basilisk_hashstampscalc(struct iguana_info *btcd,bits256 *btchashp,uint32_t reftimestamp) -{ - struct hashstamp BTCDstamps[BASILISK_MAXBTCDGAP],BTCstamps[BASILISK_MAXBTCGAP]; bits256 btcdhash; - btcdhash = *btchashp = GENESIS_PUBKEY; - if ( basilisk_hashstampsfind(BTCDstamps,BASILISK_MAXBTCDGAP,&btcd->SEQ.BTCD,btcdhash,reftimestamp) < 0 ) - { - btcdhash = BTCDstamps[BASILISK_MAXBTCDGAP >> 1].hash2; - if ( basilisk_hashstampsfind(BTCstamps,BASILISK_MAXBTCGAP,&btcd->SEQ.BTC,*btchashp,reftimestamp) < 0 ) - *btchashp = BTCstamps[BASILISK_MAXBTCGAP >> 1].hash2; - } - return(btcdhash); -} - -// have local coin -int32_t basilisk_hashstampsreverse(struct iguana_info *coin,struct basilisk_sequence *seq,int32_t firstpossible,int32_t max,struct iguana_block *block,uint32_t reftimestamp) -{ - uint32_t timestamp; int32_t j,offset; - while ( block != 0 && (timestamp= block->RO.timestamp) > reftimestamp ) - block = iguana_blockfind("hashstamps",coin,block->RO.prev_block); - if ( block == 0 ) - return(-1); - offset = (block->height - firstpossible); - for (j=0; jstamps[offset].hash2 = block->RO.hash2; - seq->stamps[offset].timestamp = block->RO.timestamp; - seq->stamps[offset].height = block->height; - if ( offset-- < 0 || (block= iguana_blockfind("revstamp",coin,block->RO.prev_block)) == 0 ) - return(block == 0 ? -1 : j); - } - return(j); -} - -int32_t basilisk_hashstampset(struct iguana_info *coin,struct hashstamp *stamp,int32_t height) -{ - struct iguana_block *block; struct iguana_bundle *bp; - if ( height >= 0 && height < coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 ) - { - if ( (block= bp->blocks[height % coin->chain->bundlesize]) != 0 ) - { - stamp->hash2 = block->RO.hash2; - stamp->timestamp = block->RO.timestamp; - stamp->height = block->height; - return(0); - } - } - return(-1); -} - -void basilisk_ensure(struct basilisk_sequence *seq,int32_t num) -{ - int32_t oldmax,incr = 1000; - if ( num >= seq->maxstamps ) - { - oldmax = seq->maxstamps; - seq->maxstamps = ((num + 2*incr) / incr) * incr; - seq->stamps = realloc(seq->stamps,sizeof(*seq->stamps) * seq->maxstamps); - memset(&seq->stamps[oldmax],0,sizeof(*seq->stamps) * (seq->maxstamps - oldmax)); - } -} - -int32_t basilisk_hashstampsupdate(struct iguana_info *coin,struct basilisk_sequence *seq,int32_t firstpossible) -{ - while ( (firstpossible + seq->numstamps) < coin->blocks.hwmchain.height ) - { - basilisk_ensure(seq,seq->numstamps); - if ( basilisk_hashstampset(coin,&seq->stamps[seq->numstamps],firstpossible + seq->numstamps) < 0 ) - break; - else seq->numstamps++; - } - seq->longestchain = coin->longestchain; - return(seq->numstamps); -} - -int32_t basilisk_update(char *symbol,uint32_t reftimestamp) -{ - struct basilisk_sequence *seq=0; int32_t max=0,firstpossible=0; struct iguana_info *coin; struct iguana_block *block; - if ( (coin= iguana_coinfind(symbol)) != 0 && (coin->RELAYNODE != 0 || coin->VALIDATENODE != 0) ) - { - if ( strcmp(symbol,"BTCD") == 0 ) - { - seq = &coin->SEQ.BTCD; - firstpossible = BASILISK_FIRSTPOSSIBLEBTCD; - } - else if ( strcmp(symbol,"BTC") == 0 ) - { - seq = &coin->SEQ.BTC; - firstpossible = BASILISK_FIRSTPOSSIBLEBTC; - } else return(-1); - //printf("basilisk update.%s %u lag.%d\n",symbol,reftimestamp,(uint32_t)time(NULL)-seq->lastupdate); - if ( basilisk_hashstampsupdate(coin,seq,firstpossible) > 0 ) - { - if ( (block= iguana_blockfind("SEQupdate",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) - basilisk_hashstampsreverse(coin,seq,firstpossible,max,block,reftimestamp); - return(0); - } - } - return(-1); -} - -int32_t iguana_rwhashstamp(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct hashstamp *stamp) -{ - int32_t len = 0; - len += iguana_rwbignum(rwflag,&serialized[len],sizeof(stamp->hash2),stamp->hash2.bytes); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(stamp->timestamp),&stamp->timestamp); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(stamp->height),&stamp->height); - //len += iguana_rwblockhdr(rwflag,zcash,&serialized[len],(void *)stamp->RO); - return(len); -} - -cJSON *basilisk_sequencejson(uint8_t zcash,struct basilisk_sequence *seq,int32_t startheight,int32_t firstpossible) -{ - int32_t i,n,len=0,datalen,num = 0; cJSON *item; uint8_t *data; char strbuf[8192],*hexstr=0; - if ( startheight < firstpossible ) - startheight = firstpossible; - if ( (i= (startheight - firstpossible) ) < 0 || i >= seq->numstamps ) - return(0); - item = cJSON_CreateObject(); - n = (seq->numstamps - i); - datalen = (int32_t)(n * sizeof(*seq->stamps)); - data = calloc(n,sizeof(*seq->stamps)); - for (; inumstamps && numstamps[i].timestamp == 0 ) - break; - len += iguana_rwhashstamp(1,zcash,&data[len],&seq->stamps[i]); - } - jaddnum(item,"start",startheight); - jaddnum(item,"num",num); - jaddnum(item,"lastupdate",seq->lastupdate); - jaddnum(item,"longest",seq->longestchain); - basilisk_addhexstr(&hexstr,item,strbuf,sizeof(strbuf),data,datalen); - if ( hexstr != 0 ) - free(hexstr); - return(item); -} - -void basilisk_seqresult(struct supernet_info *myinfo,char *retstr) -{ - struct iguana_info *btcd; struct hashstamp stamp; struct basilisk_sequence *seq = 0; cJSON *resultjson; uint8_t *allocptr = 0,space[8192],*data = 0; int32_t ind,startheight,datalen,lastupdate,longestchain,i,num,firstpossible,len = 0; char *hexstr; - if ( (btcd= iguana_coinfind("BTCD")) != 0 && (resultjson= cJSON_Parse(retstr)) != 0 ) - { - if ( jstr(resultjson,"BTCD") != 0 ) - seq = &btcd->SEQ.BTCD, firstpossible = BASILISK_FIRSTPOSSIBLEBTCD; - else if ( jstr(resultjson,"BTC") != 0 ) - seq = &btcd->SEQ.BTC, firstpossible = BASILISK_FIRSTPOSSIBLEBTC; - if ( seq != 0 ) - { - startheight = jint(resultjson,"start"); - if ( (ind= startheight-firstpossible) < 0 ) - { - free_json(resultjson); - return; - } - num = jint(resultjson,"num"); - lastupdate = jint(resultjson,"lastupdate"); - longestchain = jint(resultjson,"longest"); - hexstr = jstr(resultjson,"data"); - printf("got startheight.%d num.%d lastupdate.%d longest.%d (%s)\n",startheight,num,lastupdate,longestchain,hexstr!=0?hexstr:""); - if ( hexstr != 0 && (data= get_dataptr(&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) - { - basilisk_ensure(seq,ind + num); - for (i=0; ichain->zcash,&data[len],&stamp); - // verify blockheader - seq->stamps[ind] = stamp; - } - } - if ( allocptr != 0 ) - free(allocptr); - } - free_json(resultjson); - } -} - -char *basilisk_respond_hashstamps(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) -{ - int32_t startheight; struct iguana_info *btcd; cJSON *retjson = cJSON_CreateObject(); - if ( (btcd= iguana_coinfind("BTCD")) != 0 ) - { - if ( (startheight= juint(valsobj,"BTCD")) != 0 ) - jadd(retjson,"BTCD",basilisk_sequencejson(btcd->chain->zcash,&btcd->SEQ.BTCD,startheight,BASILISK_FIRSTPOSSIBLEBTCD)); - else if ( (startheight= juint(valsobj,"BTC")) != 0 ) - jadd(retjson,"BTC",basilisk_sequencejson(btcd->chain->zcash,&btcd->SEQ.BTC,startheight,BASILISK_FIRSTPOSSIBLEBTC)); - } - return(jprint(retjson,1)); -} - -char *basilisk_coinbase(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,uint8_t *data,int32_t datalen,bits256 coinbasespend,cJSON *origtxjson) -{ - char *rawtx; struct vin_info V; cJSON *txjson; - if ( (txjson= origtxjson) == 0 ) - txjson = bitcoin_txcreate(1,0); - bitcoin_txinput(coin,txjson,coinbasespend,-1,0xffffffff,0,0,data,datalen,0,0); - rawtx = bitcoin_json2hex(myinfo,coin,txidp,txjson,&V); - if ( txjson != origtxjson ) - free_json(txjson); - return(rawtx); -} - -cJSON *basilisk_paymentsobj(cJSON *txjson,cJSON *valsobj) -{ - cJSON *item,*array; char *coinaddr; uint64_t satoshis; uint8_t addrtype,rmd160[20],outputscript[512]; int32_t i,n,scriptlen; - if ( txjson == 0 ) - txjson = bitcoin_txcreate(1,juint(valsobj,"locktime")); - if ( (array= jarray(&n,valsobj,"payments")) != 0 && n > 0 ) - { - for (i=0; i 0 ) - { - bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); - scriptlen = bitcoin_standardspend(outputscript,0,rmd160); - bitcoin_txoutput(txjson,outputscript,scriptlen,satoshis); - } - } - } - return(txjson); -} - -struct iguana_info *basilisk_chain(struct supernet_info *myinfo,char chainname[BASILISK_MAXNAMELEN],cJSON *valsobj) -{ - char *chainstr,*keystr; bits256 keyhash,chainhash; struct private_chain *chain; - if ( (chainstr= jstr(valsobj,"chain")) == 0 ) - return(0); - if ( (keystr= jstr(valsobj,"key")) != 0 ) - vcalc_sha256(0,keyhash.bytes,(uint8_t *)keystr,(int32_t)strlen(keystr)); - else keyhash = GENESIS_PUBKEY; - vcalc_sha256(0,chainhash.bytes,(uint8_t *)chainstr,(int32_t)strlen(chainstr)); - if ( (chain= category_subscribe(myinfo,chainhash,keyhash)) == 0 ) - return(0); - safecopy(chainname,chainstr,30), chainname[30] = 0; - if ( keystr != 0 ) - { - strcat(chainname,"."); - safecopy(chainname+strlen(chainname),keystr,BASILISK_MAXNAMELEN-1-strlen(chainname)); - } - return(chain->info); -} - -int32_t basilisk_privatechainvals(struct supernet_info *myinfo,char *CMD,cJSON *valsobj) -{ - struct iguana_info *virt; bits256 hash,prevhash; struct iguana_block *block; char chainname[BASILISK_MAXNAMELEN]; - if ( strcmp(CMD,"SET") == 0 || strcmp(CMD,"GET") == 0 ) - { - if ( (virt= basilisk_chain(myinfo,chainname,valsobj)) == 0 ) - clonestr("{\"error\":\"cant find private chain\"}"); - if ( strcmp(CMD,"SET") == 0 ) - { - hash = GENESIS_PUBKEY; - if ( jobj(valsobj,"prev") != 0 ) - { - prevhash = jbits256(valsobj,"prev"); - if ( (block= iguana_blockfind("basilisk",virt,prevhash)) == 0 ) - { - char str[65]; printf("warning couldnt find %s in %s\n",bits256_str(str,prevhash),chainname); - prevhash = virt->blocks.hwmchain.RO.hash2; - } - } else prevhash = virt->blocks.hwmchain.RO.hash2; - hash = prevhash; - if ( jobj(valsobj,"prev") != 0 ) - jdelete(valsobj,"prev"); - } - return(0); - } - return(-1); -} - -char *basilisk_block(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_block *block,int32_t version,uint32_t timestamp,uint32_t *noncep,bits256 prevblock,uint32_t nBits,int32_t height,char **txptrs,int32_t txn_count,uint8_t *coinbase,int32_t coinbaselen,bits256 coinbasespend,cJSON *txjson) -{ - struct iguana_info *btcd; uint8_t serialized[sizeof(*block)],space[16384],*txdata,*allocptr = 0; int32_t i,n,totaltxlen=0,txlen,numiters=1000000; char *coinbasestr,*blockstr=0; bits256 *txids=0,txspace[256],threshold; - if ( (btcd= iguana_coinfind("BTCD")) == 0 ) - { - printf("basilisk needs BTCD\n"); - return(0); - } - if ( txn_count+2 < sizeof(space)/sizeof(*space) ) - { - txids = txspace; - memset(txids,0,sizeof(*txids) * (txn_count+2)); - } else txids = calloc(txn_count+2,sizeof(*txids)); - if ( txn_count > 0 ) - { - for (i=0; iRO.version = version; - block->RO.prev_block = prevblock; - block->RO.merkle_root = iguana_merkle(txids,txn_count + 1); - block->RO.timestamp = timestamp; - block->RO.bits = nBits; - block->RO.txn_count = (txn_count + 1); - block->height = height; - threshold = bits256_from_compact(nBits); - if ( (block->RO.nonce= *noncep) == 0 ) - { - for (i=0; iRO.nonce = rand(); - n = iguana_serialize_block(virt->chain,&block->RO.hash2,serialized,block); - //char str[65]; printf("nonce.%08x %s\n",block->RO.nonce,bits256_str(str,block->RO.hash2)); - if ( bits256_cmp(threshold,block->RO.hash2) > 0 ) - break; - } - } - *noncep = block->RO.nonce; - n = iguana_serialize_block(virt->chain,&block->RO.hash2,serialized,block); - if ( bits256_cmp(threshold,block->RO.hash2) > 0 ) - { - blockstr = calloc(1,strlen(coinbasestr) + (totaltxlen+n)*2 + 1); - init_hexbytes_noT(blockstr,serialized,n); - strcat(blockstr,coinbasestr); - for (i=0; isymbol,virt->chain->hashalgo,serialized,datalen); - if ( bits256_cmp(threshold,hash2) > 0 ) - return(0); - else return(0); -} - -char *basilisk_createblock(struct supernet_info *myinfo,struct iguana_block *block,char *symbol,uint32_t nBits,int32_t height,char **txptrs,int32_t txn_count,cJSON *txjson) -{ - bits256 btchash,btcdhash,zero; uint8_t coinbase[512]; int32_t coinbaselen; uint32_t nonce; uint32_t timestamp; struct iguana_info *btcd; - memset(block,0,sizeof(*block)); - if ( (btcd= iguana_coinfind("BTCD")) != 0 ) - { - timestamp = (uint32_t)time(NULL); - btcdhash = basilisk_hashstampscalc(btcd,(bits256 *)coinbase,timestamp); - if ( bits256_cmp(btcdhash,GENESIS_PUBKEY) == 0 || bits256_cmp(*(bits256 *)coinbase,GENESIS_PUBKEY) == 0 ) - { - printf("no hashstamps\n"); - return(0); - } - coinbaselen = (int32_t)strlen(symbol); - memcpy(&coinbase[sizeof(btchash)],symbol,coinbaselen); - memset(zero.bytes,0,sizeof(zero)); - nonce = 0; - return(basilisk_block(myinfo,btcd,block,BASILISK_DEFAULTVERSION,timestamp,&nonce,zero,nBits,height,txptrs,txn_count,coinbase,coinbaselen,btcdhash,txjson)); - } else return(0); -} - -cJSON *basilisk_genesisjson(struct supernet_info *myinfo,struct iguana_info *btcd,char *symbol,char *chainname,cJSON *valsobj) -{ - char str2[64],hashstr[64],argbuf[1024],*nbitstr,*blockstr; uint8_t buf[4]; int32_t i; uint32_t nBits; struct iguana_block genesis; - if ( (nbitstr= jstr(valsobj,"nbits")) == 0 ) - { - nBits = BASILISK_DEFAULTDIFF; - nbitstr = BASILISK_DEFAULTDIFFSTR; - } - else - { - for (i=0; i<4; i++) - decode_hex(&buf[3-i],1,&nbitstr[i*2]); - memcpy(&nBits,buf,sizeof(nBits)); - } - if ( (blockstr= basilisk_createblock(myinfo,&genesis,symbol,nBits,0,0,0,basilisk_paymentsobj(0,jobj(valsobj,"payments")))) != 0 ) - { - bits256_str(hashstr,genesis.RO.hash2); - sprintf(argbuf,"{\"name\":\"%s\",\"unitval\":%02x,\"genesishash\":\"%s\",\"genesis\":{\"version\":1,\"timestamp\":%u,\"nbits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesisblock\":\"%s\"}",chainname,(nBits >> 24) & 0xff,hashstr,genesis.RO.timestamp,nbitstr,genesis.RO.nonce,bits256_str(str2,genesis.RO.merkle_root),blockstr); - free(blockstr); - //printf("argbuf.(%s) hash.%s\n",argbuf,hashstr); - return(cJSON_Parse(argbuf)); - } else return(cJSON_Parse("{\"error\":\"couldnt create block\"}")); -} - -struct iguana_info *basilisk_privatechain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj) -{ - int32_t datalen,maxpeers,initialheight,minconfirms,maxrequests,maxbundles,hdrsize; int64_t maxrecvcache; uint64_t services; struct iguana_info *virt=0; char *hexstr; uint8_t hexbuf[1024],*ptr,*serialized; - if ( (hexstr= jstr(valsobj,"genesisblock")) != 0 && (virt= iguana_coinadd(symbol,valsobj)) == 0 ) - { - safecopy(virt->name,chainname,sizeof(virt->name)); - virt->chain = calloc(1,sizeof(*virt->chain)); - virt->chain->hashalgo = blockhash_sha256; - serialized = get_dataptr(&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr); - iguana_chaininit(virt->chain,1,valsobj); - iguana_coinargs(symbol,&maxrecvcache,&minconfirms,&maxpeers,&initialheight,&services,&maxrequests,&maxbundles,valsobj); - iguana_setcoin(myinfo,symbol,virt,maxpeers,maxrecvcache,services,initialheight,0,minconfirms,maxrequests,maxbundles,valsobj); - hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr); - if ( basilisk_blocknonce_verify(virt,serialized,hdrsize,virt->chain->nBits) == 0 ) - { - virt->chain->genesishash2 = iguana_calcblockhash(symbol,virt->chain->hashalgo,serialized,hdrsize); - memcpy(virt->chain->genesis_hashdata,virt->chain->genesishash2.bytes,sizeof(virt->chain->genesishash2)); - if ( ptr != 0 ) - free(ptr); - virt->chain->genesis_hex = clonestr(hexstr); - virt->MAXPEERS = 0; - iguana_callcoinstart(virt); - printf("nonce verified\n"); - } else printf("error validating nonce\n"); - } - return(virt); -} - -cJSON *basilisk_genesisargs(char *symbol,char *chainname,char *chain,char *keystr,char *genesishash,char *genesisblock,char *magicstr,uint16_t port,uint16_t blocktime,char *nbitstr) -{ - int32_t timespan,targetspacing; cJSON *argvals = cJSON_CreateObject(); - if ( genesishash != 0 && genesishash[0] != 0 ) - jaddstr(argvals,"genesishash",genesishash); - if ( genesisblock != 0 && genesisblock[0] != 0 ) - jaddstr(argvals,"genesisblock",genesisblock); - jaddstr(argvals,"netmagic",magicstr); - jaddstr(argvals,"symbol",symbol); - jaddstr(argvals,"name",chainname); - if ( nbitstr == 0 || nbitstr[0] == 0 ) - nbitstr = BASILISK_DEFAULTDIFFSTR; - jaddstr(argvals,"nbits",nbitstr); - jaddstr(argvals,"chain",chain); - if ( keystr != 0 ) - jaddstr(argvals,"key",keystr); - if ( port == 0 ) - jaddstr(argvals,"privatechain",chainname); - else - { - jaddnum(argvals,"services",129); - jaddnum(argvals,"portp2p",port); - if ( blocktime == 0xffff ) - targetspacing = 24 * 60 * 60; // one day - else targetspacing = 60; // one minute - jaddnum(argvals,"targetspacing",targetspacing); - if ( (timespan= sqrt(604800 / targetspacing)) < 7 ) - timespan = 7; - jaddnum(argvals,"targettimespan",targetspacing * timespan); - } - return(argvals); -} - -char *basilisk_respond_newprivatechain(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) -{ - struct iguana_info *virt,*btcd; char *symbol,*chain,chainname[BASILISK_MAXNAMELEN]; cJSON *retjson; - if ( (virt= basilisk_chain(myinfo,chainname,valsobj)) != 0 ) - { - printf("%s already exists\n",chainname); - return(clonestr("{\"error\":\"cant create duplicate privatechain\"}")); - } - if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(valsobj,"symbol")) != 0 && (chain= jstr(valsobj,"chain")) != 0 ) - { - if ( (virt= basilisk_privatechain(myinfo,symbol,chainname,valsobj)) != 0 ) - { - retjson = basilisk_genesisargs(symbol,chainname,chain,jstr(valsobj,"key"),jstr(valsobj,"genesishash"),jstr(valsobj,"genesisblock"),jstr(valsobj,"netmagic"),juint(valsobj,"port"),juint(valsobj,"blocktime"),jstr(valsobj,"nbits")); - jaddstr(retjson,"result","success"); - return(jprint(retjson,1)); - } - } - return(clonestr("{\"error\":-22}")); -} - -uint32_t basilisk_nBits(struct iguana_info *virt,struct iguana_block *block) -{ - uint32_t nBits = 0; struct iguana_block *prev,*prev2; - if ( block->height >= 0 && (prev= iguana_blockfind("privatetx",virt,block->RO.prev_block)) != 0 && prev->height > 1 ) - { - if ( (prev2= iguana_blockfind("prvatetx2",virt,prev->RO.prev_block)) != 0 && prev2->height >= 0 ) - nBits = iguana_targetbits(virt,block,prev,prev2,1,virt->chain->targetspacing,virt->chain->targettimespan); - else nBits = virt->chain->nBits; - if ( nBits == 0 ) - nBits = BASILISK_DEFAULTDIFF; - } - return(nBits); -} - -char *basilisk_respond_privatetx(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 txid,int32_t from_basilisk) -{ - bits256 checktxid; int32_t blocklen; uint32_t nBits; char *symbol,*blockstr,*txptrs[2],space[4096]; struct iguana_info *virt; cJSON *sendjson; struct iguana_block newblock,*block; uint8_t *blockdata,*allocptr,blockspace[8192]; - if ( data != 0 && datalen != 0 && (symbol= jstr(valsobj,"symbol")) != 0 && (virt= iguana_coinfind(symbol)) != 0 ) - { - checktxid = bits256_doublesha256(0,data,datalen); - block = (struct iguana_block *)&virt->blocks.hwmchain; - if ( bits256_cmp(txid,checktxid) == 0 && (nBits= basilisk_nBits(virt,block)) != 0 ) - { - txptrs[0] = basilisk_addhexstr(&txptrs[1],0,space,sizeof(space),data,datalen); // add mempool - if ( (blockstr= basilisk_createblock(myinfo,&newblock,virt->symbol,nBits,block->height+1,txptrs,1,basilisk_paymentsobj(0,jobj(valsobj,"payments")))) != 0 ) - { - if ( _iguana_chainlink(virt,&newblock) != 0 ) - { - sendjson = cJSON_CreateObject(); - jaddstr(sendjson,"coin",symbol); - jaddnum(sendjson,"ht",newblock.height); - jaddbits256(sendjson,"pubkey",newblock.RO.hash2); - blockdata = basilisk_jsondata(&allocptr,blockspace,sizeof(blockspace),&blocklen,symbol,sendjson,basilisktag); - printf("broadcast %s %s\n",blockstr,jprint(sendjson,0)); - basilisk_sendcmd(myinfo,0,"BLK",&basilisktag,juint(valsobj,"encrypt"),juint(valsobj,"delay"),&blockdata[sizeof(struct iguana_msghdr)+sizeof(basilisktag)],blocklen,-1,nBits); - if ( allocptr != 0 ) - free(allocptr); - } - free(blockstr); - } - if ( txptrs[1] != 0 ) - free(txptrs[1]); - } else return(clonestr("{\"error\":\"privatetx doesnt match txid\"}")); - } - return(clonestr("{\"error\":\"no privatetx data\"}")); -} - -char *basilisk_respond_privateblock(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash2,int32_t from_basilisk) -{ - char *symbol; struct iguana_info *virt; bits256 checkhash2; int32_t hdrsize; uint32_t nBits; struct iguana_msgblock msg; struct iguana_block newblock; - printf("got privateblock len.%d from (%s) %s\n",datalen,remoteaddr!=0?remoteaddr:"",jprint(valsobj,0)); - if ( (symbol= jstr(valsobj,"coin")) != 0 && (virt= iguana_coinfind(symbol)) != 0 ) - { - hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr); - nBits = basilisk_nBits(virt,(struct iguana_block *)&virt->blocks.hwmchain); - if ( basilisk_blocknonce_verify(virt,data,hdrsize,nBits) == 0 ) - { - iguana_rwblock(symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&checkhash2,data,&msg,datalen); - if ( bits256_cmp(hash2,checkhash2) == 0 ) - { - iguana_blockconv(virt->chain->zcash,virt->chain->auxpow,&newblock,&msg,hash2,jint(valsobj,"ht")); - if ( _iguana_chainlink(virt,&newblock) != 0 ) - { - return(clonestr("{\"result\":\"private chain extended\"}")); - } else return(clonestr("{\"result\":\"block not HWM\"}")); - } else return(clonestr("{\"error\":\"block error with checkhash2\"}")); - } else return(clonestr("{\"error\":\"block nonce didnt verify\"}")); - } - return(0); -} - -#include "../includes/iguana_apidefs.h" -#include "../includes/iguana_apideclares.h" - -HASH_ARRAY_STRING(basilisk,sequence,pubkey,vals,hexstr) -{ - return(basilisk_standardservice("SEQ",myinfo,pubkey,vals,hexstr,1)); -} - -HASH_ARRAY_STRING(basilisk,newprivatechain,pubkey,vals,hexstr) -{ - char chainname[BASILISK_MAXNAMELEN],magicstr[9],*retstr,*symbol,*chain; struct iguana_info *virt,*btcd; cJSON *argjson,*argvals,*retjson=0; int32_t i; uint32_t magic; - if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 && (chain= jstr(vals,"chain")) != 0 ) - { - if ( iguana_coinfind(symbol) == 0 && (virt= basilisk_chain(myinfo,chainname,vals)) != 0 ) - { - printf("%s already exists\n",chainname); - return(clonestr("{\"error\":\"cant create duplicate privatechain\"}")); - } - if ( jobj(vals,"netmagic") == 0 ) - { - OS_randombytes((void *)&magic,sizeof(magic)); - for (i=0; iRELAYNODE != 0 || btcd->VALIDATENODE != 0 ) - retstr = basilisk_respond_newprivatechain(myinfo,"NEW",0,0,0,argvals,0,0,GENESIS_PUBKEY,0); - else retstr = basilisk_standardservice("NEW",myinfo,GENESIS_PUBKEY,argvals,0,1); - free_json(argvals); - if ( (argvals= cJSON_Parse(retstr)) != 0 ) - { - if ( jobj(argvals,"result") != 0 && strcmp(jstr(argvals,"result"),"success") == 0 ) - { - if ( basilisk_privatechain(myinfo,symbol,chainname,argvals) != 0 ) - jaddstr(argvals,"status","active"); - //free_json(argvals); - } else jaddstr(argvals,"error","couldnt initialize privatechain"); - free(retstr); - return(jprint(argvals,1)); - } - if ( retjson != 0 ) - free_json(retjson); - free_json(argvals); - return(retstr); - } else return(clonestr("{\"error\":\"couldnt create genesis_block\"}")); - } - return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new private chain\"}")); -} - -HASH_ARRAY_STRING(basilisk,privatetx,pubkey,vals,hexstr) -{ - struct iguana_info *btcd,*virt; char *retstr=0,*symbol; uint8_t *data,*allocptr,space[4096]; int32_t datalen; bits256 txid; - if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 ) - { - if ( (virt= iguana_coinfind(symbol)) != 0 ) - { - if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 ) - { - if ( (data= get_dataptr(&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) - { - txid = bits256_doublesha256(0,data,datalen); - retstr = basilisk_respond_privatetx(myinfo,"VTX",0,0,0,vals,data,datalen,txid,0); - } - if ( allocptr != 0 ) - free(allocptr); - if ( retstr == 0 ) - retstr = clonestr("{\"error\":\"couldnt create privatetx\"}"); - } else retstr = basilisk_standardservice("VTX",myinfo,txid,vals,hexstr,1); - return(retstr); - } else return(clonestr("{\"error\":\"couldnt find privatechain\"}")); - } - return(basilisk_standardservice("VTX",myinfo,pubkey,vals,hexstr,1)); -} - -HASH_ARRAY_STRING(basilisk,privateblock,pubkey,vals,hexstr) -{ - return(clonestr("{\"error\":\"privateblock is an internal function\"}")); - //return(basilisk_standardservice("BLK",myinfo,pubkey,vals,hexstr,1)); -} -#include "../includes/iguana_apiundefs.h" - - diff --git a/crypto777/curve25519.c b/crypto777/curve25519.c index e4dc45375..62ac83bd0 100755 --- a/crypto777/curve25519.c +++ b/crypto777/curve25519.c @@ -1848,4 +1848,25 @@ uint64_t acct777_signtx(struct acct777_sig *sig,bits256 privkey,uint32_t timesta return(acct777_sign(sig,privkey,acct777_msgpubkey(data,datalen),timestamp,data,datalen)); }*/ +int32_t _SuperNET_cipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 destpub,bits256 srcpriv,uint8_t *buf) +{ + memset(cipher,0,len+crypto_box_ZEROBYTES); + memset(buf,0,crypto_box_ZEROBYTES); + memcpy(buf+crypto_box_ZEROBYTES,message,len); + crypto_box(cipher,buf,len+crypto_box_ZEROBYTES,nonce,destpub.bytes,srcpriv.bytes); + return(len + crypto_box_ZEROBYTES); +} + +uint8_t *_SuperNET_decipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 srcpub,bits256 mypriv) +{ + int32_t err; + if ( (err= crypto_box_open(message,cipher,len,nonce,srcpub.bytes,mypriv.bytes)) == 0 ) + { + message += crypto_box_ZEROBYTES; + len -= crypto_box_ZEROBYTES; + return(message); + } + return(0); +} + #undef force_inline diff --git a/InstantDEX/InstantDEX.c b/deprecated/InstantDEX/InstantDEX.c similarity index 100% rename from InstantDEX/InstantDEX.c rename to deprecated/InstantDEX/InstantDEX.c diff --git a/InstantDEX/InstantDEX_quote.h b/deprecated/InstantDEX/InstantDEX_quote.h similarity index 100% rename from InstantDEX/InstantDEX_quote.h rename to deprecated/InstantDEX/InstantDEX_quote.h diff --git a/InstantDEX/exchange_trades.h b/deprecated/InstantDEX/exchange_trades.h similarity index 100% rename from InstantDEX/exchange_trades.h rename to deprecated/InstantDEX/exchange_trades.h diff --git a/InstantDEX/exchangeparse.h b/deprecated/InstantDEX/exchangeparse.h similarity index 100% rename from InstantDEX/exchangeparse.h rename to deprecated/InstantDEX/exchangeparse.h diff --git a/iguana/InstantDEX/prices777.c b/deprecated/InstantDEX/prices777.c similarity index 100% rename from iguana/InstantDEX/prices777.c rename to deprecated/InstantDEX/prices777.c diff --git a/InstantDEX/quotes.h b/deprecated/InstantDEX/quotes.h similarity index 100% rename from InstantDEX/quotes.h rename to deprecated/InstantDEX/quotes.h diff --git a/iguana/InstantDEX/quotes777.c b/deprecated/InstantDEX/quotes777.c similarity index 100% rename from iguana/InstantDEX/quotes777.c rename to deprecated/InstantDEX/quotes777.c diff --git a/InstantDEX/subatomic.h b/deprecated/InstantDEX/subatomic.h similarity index 100% rename from InstantDEX/subatomic.h rename to deprecated/InstantDEX/subatomic.h diff --git a/InstantDEX/tradebots.h b/deprecated/InstantDEX/tradebots.h similarity index 100% rename from InstantDEX/tradebots.h rename to deprecated/InstantDEX/tradebots.h diff --git a/InstantDEX/trades.h b/deprecated/InstantDEX/trades.h similarity index 100% rename from InstantDEX/trades.h rename to deprecated/InstantDEX/trades.h diff --git a/iguana/InstantDEX/InstantDEX.c b/deprecated/InstantDEX2/InstantDEX.c similarity index 100% rename from iguana/InstantDEX/InstantDEX.c rename to deprecated/InstantDEX2/InstantDEX.c diff --git a/iguana/InstantDEX/InstantDEX_quote.h b/deprecated/InstantDEX2/InstantDEX_quote.h similarity index 100% rename from iguana/InstantDEX/InstantDEX_quote.h rename to deprecated/InstantDEX2/InstantDEX_quote.h diff --git a/InstantDEX/Makefile b/deprecated/InstantDEX2/Makefile similarity index 100% rename from InstantDEX/Makefile rename to deprecated/InstantDEX2/Makefile diff --git a/iguana/InstantDEX/exchange_trades.h b/deprecated/InstantDEX2/exchange_trades.h similarity index 100% rename from iguana/InstantDEX/exchange_trades.h rename to deprecated/InstantDEX2/exchange_trades.h diff --git a/iguana/InstantDEX/exchangeparse.h b/deprecated/InstantDEX2/exchangeparse.h similarity index 100% rename from iguana/InstantDEX/exchangeparse.h rename to deprecated/InstantDEX2/exchangeparse.h diff --git a/InstantDEX/exchanges/bitfinex.c b/deprecated/InstantDEX2/exchanges/bitfinex.c similarity index 100% rename from InstantDEX/exchanges/bitfinex.c rename to deprecated/InstantDEX2/exchanges/bitfinex.c diff --git a/InstantDEX/exchanges/bitstamp.c b/deprecated/InstantDEX2/exchanges/bitstamp.c similarity index 100% rename from InstantDEX/exchanges/bitstamp.c rename to deprecated/InstantDEX2/exchanges/bitstamp.c diff --git a/InstantDEX/exchanges/bittrex.c b/deprecated/InstantDEX2/exchanges/bittrex.c similarity index 100% rename from InstantDEX/exchanges/bittrex.c rename to deprecated/InstantDEX2/exchanges/bittrex.c diff --git a/InstantDEX/exchanges/btc38.c b/deprecated/InstantDEX2/exchanges/btc38.c similarity index 100% rename from InstantDEX/exchanges/btc38.c rename to deprecated/InstantDEX2/exchanges/btc38.c diff --git a/InstantDEX/exchanges/btce.c b/deprecated/InstantDEX2/exchanges/btce.c similarity index 100% rename from InstantDEX/exchanges/btce.c rename to deprecated/InstantDEX2/exchanges/btce.c diff --git a/InstantDEX/exchanges/checkbalance.c b/deprecated/InstantDEX2/exchanges/checkbalance.c similarity index 100% rename from InstantDEX/exchanges/checkbalance.c rename to deprecated/InstantDEX2/exchanges/checkbalance.c diff --git a/InstantDEX/exchanges/coinbase.c b/deprecated/InstantDEX2/exchanges/coinbase.c similarity index 100% rename from InstantDEX/exchanges/coinbase.c rename to deprecated/InstantDEX2/exchanges/coinbase.c diff --git a/InstantDEX/exchanges/huobi.c b/deprecated/InstantDEX2/exchanges/huobi.c similarity index 100% rename from InstantDEX/exchanges/huobi.c rename to deprecated/InstantDEX2/exchanges/huobi.c diff --git a/InstantDEX/exchanges/lakebtc.c b/deprecated/InstantDEX2/exchanges/lakebtc.c similarity index 100% rename from InstantDEX/exchanges/lakebtc.c rename to deprecated/InstantDEX2/exchanges/lakebtc.c diff --git a/InstantDEX/exchanges/okcoin.c b/deprecated/InstantDEX2/exchanges/okcoin.c similarity index 100% rename from InstantDEX/exchanges/okcoin.c rename to deprecated/InstantDEX2/exchanges/okcoin.c diff --git a/InstantDEX/exchanges/poloniex.c b/deprecated/InstantDEX2/exchanges/poloniex.c similarity index 100% rename from InstantDEX/exchanges/poloniex.c rename to deprecated/InstantDEX2/exchanges/poloniex.c diff --git a/InstantDEX/exchanges/quadriga.c b/deprecated/InstantDEX2/exchanges/quadriga.c similarity index 100% rename from InstantDEX/exchanges/quadriga.c rename to deprecated/InstantDEX2/exchanges/quadriga.c diff --git a/InstantDEX/index.html b/deprecated/InstantDEX2/index.html similarity index 100% rename from InstantDEX/index.html rename to deprecated/InstantDEX2/index.html diff --git a/InstantDEX/m_clean b/deprecated/InstantDEX2/m_clean similarity index 100% rename from InstantDEX/m_clean rename to deprecated/InstantDEX2/m_clean diff --git a/InstantDEX/m_pnacl b/deprecated/InstantDEX2/m_pnacl similarity index 100% rename from InstantDEX/m_pnacl rename to deprecated/InstantDEX2/m_pnacl diff --git a/InstantDEX/main.c b/deprecated/InstantDEX2/main.c similarity index 100% rename from InstantDEX/main.c rename to deprecated/InstantDEX2/main.c diff --git a/InstantDEX/manifest.json b/deprecated/InstantDEX2/manifest.json similarity index 100% rename from InstantDEX/manifest.json rename to deprecated/InstantDEX2/manifest.json diff --git a/InstantDEX/orderbooks.h b/deprecated/InstantDEX2/orderbooks.h similarity index 100% rename from InstantDEX/orderbooks.h rename to deprecated/InstantDEX2/orderbooks.h diff --git a/iguana/InstantDEX/quotes.h b/deprecated/InstantDEX2/quotes.h similarity index 100% rename from iguana/InstantDEX/quotes.h rename to deprecated/InstantDEX2/quotes.h diff --git a/iguana/InstantDEX/subatomic.h b/deprecated/InstantDEX2/subatomic.h similarity index 100% rename from iguana/InstantDEX/subatomic.h rename to deprecated/InstantDEX2/subatomic.h diff --git a/iguana/InstantDEX/tradebots.h b/deprecated/InstantDEX2/tradebots.h similarity index 100% rename from iguana/InstantDEX/tradebots.h rename to deprecated/InstantDEX2/tradebots.h diff --git a/iguana/InstantDEX/trades.h b/deprecated/InstantDEX2/trades.h similarity index 100% rename from iguana/InstantDEX/trades.h rename to deprecated/InstantDEX2/trades.h diff --git a/deprecated/SuperNET.c b/deprecated/SuperNET.c index ded022edf..138c6679a 100755 --- a/deprecated/SuperNET.c +++ b/deprecated/SuperNET.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2014-2015 The SuperNET Developers. * + * Copyright © 2014-2016 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * @@ -13,495 +13,1542 @@ * * ******************************************************************************/ +#include "iguana777.h" +#include "../includes/tweetnacl.h" #include "../crypto777/OS_portable.h" -#include "SuperNET.h" - -void SuperNET_rpcloop(void *args) -{ - struct supernet_info *myinfo = args; - int32_t recvlen,bindsock,postflag,sock,remains,jsonflag,numsent,len; socklen_t clilen; - char remoteaddr[64],jsonbuf[8192],*buf,*retstr,*space;//,*retbuf; ,n,i,m - struct sockaddr_in cli_addr; uint32_t ipbits,i; uint16_t port; - int32_t size = 1024 * 1024 * 2; - port = SUPERNET_PORT; - bindsock = iguana_socket(1,"127.0.0.1",port); - printf("SuperNET_rpcloop 127.0.0.1:%d bind sock.%d\n",port,bindsock); - space = calloc(1,size); - while ( bindsock >= 0 ) - { - clilen = sizeof(cli_addr); - //printf("ACCEPT (%s:%d) on sock.%d\n","127.0.0.1",port,bindsock); - sock = accept(bindsock,(struct sockaddr *)&cli_addr,&clilen); - if ( sock < 0 ) - { - //printf("iguana_rpcloop ERROR on accept usock.%d\n",sock); - continue; +#include "../includes/libgfshare.h" +#include "../includes/utlist.h" +#include "../includes/uthash.h" +#include "../includes/curve25519.h" +#include "../includes/cJSON.h" + +#ifdef oldway + +cJSON *SuperNET_argjson(cJSON *json) +{ + cJSON *argjson = jduplicate(json); + jdelete(argjson,"agent"); + jdelete(argjson,"method"); + jdelete(argjson,"categoryhash"); + jdelete(argjson,"subhash"); + jdelete(argjson,"mypub"); + jdelete(argjson,"hexmsg"); + jdelete(argjson,"plaintext"); + jdelete(argjson,"broadcast"); + jdelete(argjson,"ov"); + jdelete(argjson,"check"); + jdelete(argjson,"yourip"); + jdelete(argjson,"myip"); + jdelete(argjson,"myipaddr"); + return(argjson); +} + +bits256 SuperNET_sharedseed(bits256 privkey,bits256 otherpub) +{ + bits256 seed2,seed; + seed = curve25519_shared(privkey,otherpub); + vcalc_sha256(0,seed2.bytes,seed.bytes,sizeof(bits256)); + return(seed2); +} + +int32_t SuperNET_delaymillis(struct supernet_info *myinfo,int32_t maxdelay) +{ + maxdelay += myinfo->maxdelay; + if ( maxdelay > SUPERNET_MAXDELAY ) + maxdelay = SUPERNET_MAXDELAY; + if ( maxdelay == 0 ) + return(0); + return(rand() % maxdelay); +} + +void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag) +{ + uint64_t ipbits; struct iguana_peer *addr; + ipbits = calc_ipbits(ipaddr); + printf("got %s remotepeer.(%s) supernet.%d\n",symbol,ipaddr,supernetflag); + if ( supernetflag != 0 && (uint32_t)myinfo->myaddr.selfipbits != (uint32_t)ipbits ) + { + if ( (addr= iguana_peerslot(coin,ipbits,0)) != 0 ) + { + printf("launch startconnection to supernet peer.(%s)\n",ipaddr); + iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); + return; } - memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits)); - expand_ipbits(remoteaddr,ipbits); - memset(jsonbuf,0,sizeof(jsonbuf)); - remains = (int32_t)(sizeof(jsonbuf) - 1); - buf = jsonbuf; - recvlen = 0; - retstr = 0; - while ( remains > 0 ) - { - if ( (len= (int32_t)recv(sock,buf,remains,0)) < 0 ) + } + iguana_possible_peer(coin,ipaddr); +} + +int32_t SuperNET_confirmip(struct supernet_info *myinfo,uint32_t ipbits) +{ + int32_t j,total = 0; uint32_t x; struct iguana_info *coin,*tmp; + //portable_mutex_lock(&Allcoins_mutex); + HASH_ITER(hh,myinfo->allcoins,coin,tmp) + { + for (j=0; jpeers->active[j].myipbits) != 0 ) { - if ( errno == EAGAIN ) - { - printf("EAGAIN for len %d, remains.%d\n",len,remains); - usleep(10000); - } - break; + if ( x == ipbits ) + total++; + else total--; + } + } + } + //portable_mutex_unlock(&Allcoins_mutex); + return(total); +} + +void SuperNET_checkipaddr(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *myipaddr,char *remoteaddr) +{ + uint32_t myipbits = (uint32_t)calc_ipbits(myipaddr); + if ( addr->myipbits == 0 ) + addr->myipbits = myipbits; + else if ( addr->myipbits != myipbits ) + { + printf("%s: myipaddr conflict %x != %x?\n",addr->ipaddr,addr->myipbits,myipbits); + addr->myipbits = 0; + } + if ( addr->myipbits != 0 && myinfo->myaddr.myipbits == 0 ) + myinfo->myaddr.myipbits = addr->myipbits; + if ( addr->myipbits == myinfo->myaddr.myipbits ) + myinfo->myaddr.confirmed++; + else myinfo->myaddr.confirmed--; + if ( (myinfo->myaddr.totalconfirmed= SuperNET_confirmip(myinfo,addr->myipbits)) >= coin->peers->numranked ) + myinfo->myaddr.selfipbits = addr->myipbits; + if ( myinfo->myaddr.selfipbits == myinfo->myaddr.myipbits ) + { + expand_ipbits(myinfo->ipaddr,myinfo->myaddr.selfipbits); + vcalc_sha256(0,myinfo->myaddr.iphash.bytes,(uint8_t *)&myinfo->myaddr.selfipbits,sizeof(myinfo->myaddr.selfipbits)); + } + if ( myinfo->ipaddr[0] == 0 || strcmp(myinfo->ipaddr,"127.0.0.1") == 0 ) + { + strcpy(myinfo->ipaddr,myipaddr); + } + //printf("myipaddr.%s self.%x your.%x\n",myinfo->ipaddr,myinfo->myaddr.selfipbits,myinfo->myaddr.myipbits); +} +#endif + +int32_t _SuperNET_cipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 destpub,bits256 srcpriv,uint8_t *buf) +{ + memset(cipher,0,len+crypto_box_ZEROBYTES); + memset(buf,0,crypto_box_ZEROBYTES); + memcpy(buf+crypto_box_ZEROBYTES,message,len); + crypto_box(cipher,buf,len+crypto_box_ZEROBYTES,nonce,destpub.bytes,srcpriv.bytes); + return(len + crypto_box_ZEROBYTES); +} + +uint8_t *_SuperNET_decipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 srcpub,bits256 mypriv) +{ + int32_t err; + if ( (err= crypto_box_open(message,cipher,len,nonce,srcpub.bytes,mypriv.bytes)) == 0 ) + { + message += crypto_box_ZEROBYTES; + len -= crypto_box_ZEROBYTES; + return(message); + } + return(0); +} + +void *SuperNET_deciphercalc(void **ptrp,int32_t *msglenp,bits256 privkey,bits256 srcpubkey,uint8_t *cipher,int32_t cipherlen,uint8_t *buf,int32_t bufsize) +{ + uint8_t *origptr,*nonce,*message; void *retptr; + if ( bits256_nonz(privkey) == 0 ) + privkey = GENESIS_PRIVKEY; + *ptrp = 0; + if ( cipherlen > bufsize ) + { + message = calloc(1,cipherlen); + *ptrp = (void *)message; + } + else message = buf; + origptr = cipher; + if ( bits256_nonz(srcpubkey) == 0 ) + { + memcpy(srcpubkey.bytes,cipher,sizeof(srcpubkey)); + char str[65]; printf("use attached pubkey.(%s)\n",bits256_str(str,srcpubkey)); + cipher += sizeof(srcpubkey); + cipherlen -= sizeof(srcpubkey); + } + nonce = cipher; + cipher += crypto_box_NONCEBYTES, cipherlen -= crypto_box_NONCEBYTES; + *msglenp = cipherlen - crypto_box_ZEROBYTES; + if ( (retptr= _SuperNET_decipher(nonce,cipher,message,cipherlen,srcpubkey,privkey)) == 0 ) + { + *msglenp = -1; + free(*ptrp); + } + return(retptr); +} + +uint8_t *SuperNET_ciphercalc(void **ptrp,int32_t *cipherlenp,bits256 *privkeyp,bits256 *destpubkeyp,uint8_t *data,int32_t datalen,uint8_t *space2,int32_t space2size) +{ + bits256 mypubkey; uint8_t *buf,*nonce,*cipher,*origptr,space[8192]; int32_t onetimeflag=0,allocsize; + *ptrp = 0; + allocsize = (datalen + crypto_box_NONCEBYTES + crypto_box_ZEROBYTES); + if ( bits256_nonz(*destpubkeyp) == 0 || memcmp(destpubkeyp->bytes,GENESIS_PUBKEY.bytes,sizeof(*destpubkeyp)) == 0 ) + { + *destpubkeyp = GENESIS_PUBKEY; + onetimeflag = 2; // prevent any possible leakage of privkey by encrypting to known destpub + } + if ( bits256_nonz(*privkeyp) == 0 ) + onetimeflag = 1; + if ( onetimeflag != 0 ) + { + crypto_box_keypair(mypubkey.bytes,privkeyp->bytes); + allocsize += sizeof(bits256); + } + if ( allocsize > sizeof(space) ) + buf = calloc(1,allocsize); + else buf = space; + if ( allocsize+sizeof(struct iguana_msghdr) > space2size ) + { + cipher = calloc(1,allocsize + sizeof(struct iguana_msghdr)); + *ptrp = (void *)cipher; + } else cipher = space2; + cipher = &cipher[sizeof(struct iguana_msghdr)]; + origptr = nonce = cipher; + if ( onetimeflag != 0 ) + { + memcpy(cipher,mypubkey.bytes,sizeof(mypubkey)); + nonce = &cipher[sizeof(mypubkey)]; + } + OS_randombytes(nonce,crypto_box_NONCEBYTES); + cipher = &nonce[crypto_box_NONCEBYTES]; + _SuperNET_cipher(nonce,cipher,(void *)data,datalen,*destpubkeyp,*privkeyp,buf); + if ( buf != space ) + free(buf); + *cipherlenp = allocsize; + return(origptr); +} + +#ifdef oldway +int32_t SuperNET_copybits(int32_t reverse,uint8_t *dest,uint8_t *src,int32_t len) +{ + int32_t i; uint8_t *tmp; + if ( reverse != 0 ) + { + tmp = dest; + dest = src; + src = tmp; + } + //printf("src.%p dest.%p len.%d\n",src,dest,len); + //for (i=0; i> 3); +} + +uint16_t SuperNET_checkc(bits256 privkey,bits256 otherpub,void *num,int32_t len) +{ + uint8_t buf[40]; bits256 check,seed,seed2; + seed = curve25519_shared(privkey,otherpub); + vcalc_sha256(0,seed2.bytes,seed.bytes,sizeof(seed)); + memcpy(buf,seed2.bytes,sizeof(seed)); + iguana_rwnum(1,&buf[sizeof(seed)],len,num); + vcalc_sha256(0,check.bytes,buf,(int32_t)sizeof(seed2)+len); + //printf("SuperNET_checkc otherpub.%llx + privkey.%llx -> %x\n",(long long)otherpub.txid,(long long)privkey.txid,check.ushorts[0]); + return(check.ushorts[0]); +} + +int32_t SuperNET_json2bits(uint8_t *serialized,int32_t maxsize,cJSON *json,bits256 mypub,uint16_t checkc,uint32_t myipbits,uint32_t destipbits,int32_t _othervalid) +{ + uint16_t apinum; bits256 categoryhash,subhash; uint32_t tmp,crc,timestamp; char *agent,*method; char *hexmsg; uint8_t broadcastflag; int8_t othervalid; int32_t n,len = sizeof(uint32_t); + if ( _othervalid > 100 ) + othervalid = 100; + else if ( _othervalid < -100 ) + othervalid = -100; + else othervalid = _othervalid; + tmp = juint(json,"broadcast"); + if ( tmp > SUPERNET_MAXHOPS ) + broadcastflag = SUPERNET_MAXHOPS; + else broadcastflag = tmp; + if ( juint(json,"request") != 0 ) + broadcastflag |= 0x10; + categoryhash = jbits256(json,"categoryhash"); + subhash = jbits256(json,"subhash"); + timestamp = juint(json,"timestamp"); + if ( bits256_nonz(categoryhash) > 0 && memcmp(categoryhash.bytes,GENESIS_PUBKEY.bytes,sizeof(categoryhash)) != 0 ) + { + broadcastflag |= 0x40; + if ( bits256_nonz(subhash) > 0 && memcmp(subhash.bytes,GENESIS_PUBKEY.bytes,sizeof(subhash)) != 0 ) + broadcastflag |= 0x20; + else subhash = GENESIS_PUBKEY; + if ( broadcastflag == 0 ) + broadcastflag = 1; + } + else + { + categoryhash = subhash = GENESIS_PUBKEY; + if ( broadcastflag == 0 ) + broadcastflag = 1; + } + if ( juint(json,"plaintext") != 0 ) + broadcastflag |= 0x80; + //if ( (tag= j64bits(json,"tag")) == 0 ) + // OS_randombytes((uint8_t *)&tag,sizeof(tag)); + agent = jstr(json,"agent"), method = jstr(json,"method"); + if ( agent != 0 && method != 0 && strcmp(agent,"SuperNET") == 0 && strcmp(method,"json2bits") == 0 ) + { + agent = jstr(json,"destagent"); + method = jstr(json,"destmethod"); + } + if ( (apinum= SuperNET_API2num(agent,method)) == 0xffff ) + { + printf("agent.(%s) method.(%s) is not found\n",agent,method); + return(-1); + } + len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),×tamp); + len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),&destipbits); + len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),&myipbits); + //printf("myipbits.%x destipbits.%x\n",myipbits,destipbits); + len += iguana_rwnum(1,&serialized[len],sizeof(checkc),&checkc); + len += iguana_rwnum(1,&serialized[len],sizeof(apinum),&apinum); + //len += iguana_rwnum(1,&serialized[len],sizeof(tag),&tag); + len += iguana_rwbignum(1,&serialized[len],sizeof(mypub),mypub.bytes); + len += iguana_rwnum(1,&serialized[len],sizeof(othervalid),&othervalid); + len += iguana_rwnum(1,&serialized[len],sizeof(broadcastflag),&broadcastflag); + if ( (broadcastflag & 0x40) != 0 ) + { + len += iguana_rwbignum(1,&serialized[len],sizeof(bits256),categoryhash.bytes); + if ( (broadcastflag & 0x20) != 0 ) + len += iguana_rwbignum(1,&serialized[len],sizeof(bits256),subhash.bytes); + } + //printf("broadcastflag.%x\n",broadcastflag); + if ( (hexmsg= jstr(json,"hexmsg")) != 0 ) + { + n = (int32_t)strlen(hexmsg); + if ( (n & 1) == 0 && is_hexstr(hexmsg,n) > 0 ) + { + n >>= 1; + decode_hex(&serialized[len],n,hexmsg); + len += n; + } else return(-1); + } + crc = calc_crc32(0,&serialized[sizeof(crc)],len - sizeof(crc)); + iguana_rwnum(1,serialized,sizeof(crc),&crc); + //int32_t i; for (i=0; i SUPERNET_MAXHOPS ) + broadcastflag = SUPERNET_MAXHOPS; + //printf("<<<<<<<<<<<<<<<< crc.%u ipbits.(%x %x) tag.%llx checkc.%x apinum.%d valid.%d other.%d broadcast.%d plaintext.%d\n",crc,destipbits,myipbits,(long long)tag,checkc,apinum,addr->validpub,othervalid,broadcastflag,plaintext); + if ( SuperNET_num2API(agent,method,apinum) >= 0 ) + { + jaddstr(json,"agent",agent); + jaddstr(json,"method",method); + if ( timestamp != 0 ) + jaddnum(json,"timestamp",timestamp); + if ( bits256_nonz(categoryhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,categoryhash.bytes,sizeof(categoryhash)) != 0 ) + jaddbits256(json,"categoryhash",categoryhash); + if ( bits256_nonz(categoryhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,subhash.bytes,sizeof(subhash)) != 0 ) + jaddbits256(json,"subhash",subhash); + expand_ipbits(destip,destipbits), jaddstr(json,"yourip",destip); + expand_ipbits(myipaddr,myipbits), jaddstr(json,"myip",myipaddr); + jaddstr(json,"mypub",bits256_str(str,senderpub)); + categoryhash = subhash = GENESIS_PUBKEY; + if ( (broadcastflag & 0x40) != 0 ) + { + jaddbits256(json,"categoryhash",categoryhash); + if ( (broadcastflag & 0x20) != 0 ) + jaddbits256(json,"subhash",subhash); + } + //jadd64bits(json,"tag",tag); + init_hexbytes_noT(checkstr,(void *)&checkc,sizeof(checkc)); + jaddstr(json,"check",checkstr); + jaddnum(json,"ov",othervalid); + if ( requestflag != 0 ) + jaddnum(json,"request",requestflag); + if ( plaintext != 0 ) + jaddnum(json,"plaintext",plaintext!=0); + if ( broadcastflag != 0 ) + jaddnum(json,"broadcast",broadcastflag%SUPERNET_MAXHOPS); + if ( len < datalen ) + { + //printf("len %d vs %d datalen\n",len,datalen); + hexmsg = malloc(((datalen - len)<<1) + 1); + init_hexbytes_noT(hexmsg,&serialized[len],datalen - len); + //printf("hex.(%s)\n",hexmsg); + jaddstr(json,"hexmsg",hexmsg); + free(hexmsg); + } + //printf("bits2json.(%s)\n",jprint(json,0)); + return(json); + } else printf("cant decode apinum.%d (%d.%d)\n",apinum,apinum>>5,apinum%0x1f); + return(0); +} + +char *SuperNET_hexconv(char *hexmsg) +{ + cJSON *json; char *myip,*yourip,*retstr = hexmsg; uint32_t myipbits=0,destipbits=0; + uint8_t *bits; int32_t n,len = (int32_t)strlen(hexmsg); + //if ( hexmsg == 0 || is_hexstr(hexmsg,len) == 0 ) + return(hexmsg); + len >>= 1; + if ( (bits= calloc(1,len)) != 0 ) + { + decode_hex(bits,len,hexmsg); + if ( (json= cJSON_Parse((char *)bits)) != 0 ) + { + printf("parsed hexmsg.(%s)\n",(char *)bits); + if ( (myip= jstr(json,"myip")) != 0 ) + myipbits = (uint32_t)calc_ipbits(myip); + if ( (yourip= jstr(json,"yourip")) != 0 ) + destipbits = (uint32_t)calc_ipbits(yourip); + n = SuperNET_json2bits(bits,len,json,jbits256(json,"mypub"),juint(json,"checkc"),myipbits,destipbits,(int32_t)jdouble(json,"ov")); + cJSON *json2 = SuperNET_bits2json(bits,n); printf("hexconv.(%s) -> (%s)\n",jprint(json,0),jprint(json2,1)); + if ( (retstr= calloc(1,n*2+1)) != 0 ) + init_hexbytes_noT(retstr,bits,n); + else retstr = hexmsg; + free_json(json); + } //else printf("SuperNET_hexconv cant parse.(%s)\n",hexmsg); + free(bits); + } + return(retstr); +} + +void iguana_setkeys(struct supernet_info *myinfo,struct iguana_peer *addr,bits256 *myprivp,bits256 *mypubp,bits256 *destpubp,bits256 *nextprivp,bits256 *nextpubp,bits256 *nextdestpubp) +{ + *nextprivp = myinfo->privkey; + *nextpubp = myinfo->myaddr.pubkey; + *nextdestpubp = addr->pubkey; + *myprivp = *nextprivp, *mypubp = *nextpubp, *destpubp = *nextdestpubp; + //if ( addr->validpub < 3 ) + *destpubp = GENESIS_PUBKEY; + //if ( addr->othervalid < 3 ) + *myprivp = GENESIS_PRIVKEY, *mypubp = GENESIS_PUBKEY; + //char str[65]; printf("(priv.%llx pub.%llx) -> destpub.%s\n",(long long)myprivp->txid,(long long)mypubp->txid,bits256_str(str,*destpubp)); +} + +bits256 iguana_actualpubkey(int32_t *offsetp,uint8_t *cipher,int32_t cipherlen,bits256 destpubkey) +{ + int32_t i; + *offsetp = 0; + if ( cipherlen < 56+16 ) + return(destpubkey); + for (i=56; i<56+16; i++) + if ( cipher[i] != 0 ) + break; + if ( i == 56+16 ) + { + *offsetp = sizeof(destpubkey); + memcpy(destpubkey.bytes,cipher,sizeof(destpubkey)); + //char str[65]; printf("extracted destpubkey.(%s)\n",bits256_str(str,destpubkey)); + } + return(destpubkey); +} + +int32_t iguana_send_supernet(struct iguana_peer *addr,char *jsonstr,int32_t delaymillis) +{ + int32_t datalen,cipherlen,qlen = -1; uint8_t *serialized,space2[32768],*cipher; cJSON *json; + struct supernet_info *myinfo; uint16_t checkc; + bits256 destpub,privkey,pubkey,nextprivkey,nextpubkey,nextdestpub; void *ptr = 0; + myinfo = SuperNET_MYINFO(0); + if ( (json= cJSON_Parse(jsonstr)) != 0 ) + { + iguana_setkeys(myinfo,addr,&privkey,&pubkey,&destpub,&nextprivkey,&nextpubkey,&nextdestpub); + if ( juint(json,"plaintext") == 0 && juint(json,"broadcast") == 0 && memcmp(destpub.bytes,GENESIS_PUBKEY.bytes,sizeof(pubkey)) == 0 ) + { + printf("warning broadcasting non-plaintext! (%s) (%d %d %d)\n",jsonstr,juint(json,"plaintext"),juint(json,"broadcast"),memcmp(destpub.bytes,GENESIS_PUBKEY.bytes,sizeof(pubkey))); //getchar(); + //free_json(json); + //return(-1); + } + serialized = malloc(sizeof(struct iguana_msghdr) + IGUANA_MAXPACKETSIZE); + checkc = SuperNET_checkc(nextprivkey,nextdestpub,&nextpubkey.txid,sizeof(nextpubkey.txid)); + if ( (datalen= SuperNET_json2bits(&serialized[sizeof(struct iguana_msghdr)],IGUANA_MAXPACKETSIZE,json,nextpubkey,checkc,(uint32_t)calc_ipbits(myinfo->ipaddr),(uint32_t)calc_ipbits(addr->ipaddr),addr->validpub)) > 0 ) + { + if ( 0 && jstr(json,"method") != 0 && strcmp("getpeers",jstr(json,"method")) != 0 ) + printf("SUPERSEND -> (%s) (%s) delaymillis.%d datalen.%d checkc.%x\n",jprint(SuperNET_bits2json(&serialized[sizeof(struct iguana_msghdr)],datalen),1),addr->ipaddr,delaymillis,datalen,checkc); + if ( memcmp(destpub.bytes,GENESIS_PUBKEY.bytes,sizeof(destpub)) == 0 ) + { + qlen = iguana_queue_send(addr,delaymillis,serialized,"SuperNET",datalen+1); + //printf("send broadcast\n"); } else { - if ( len > 0 ) + if ( (cipher= SuperNET_ciphercalc(&ptr,&cipherlen,&privkey,&destpub,&serialized[sizeof(struct iguana_msghdr)],datalen,space2,sizeof(space2))) != 0 ) { - remains -= len; - recvlen += len; - buf = &buf[len]; - retstr = SuperNET_rpcparse(myinfo,space,size,&jsonflag,&postflag,jsonbuf,remoteaddr); - break; - } else usleep(10000); + void *msgbits; int32_t msglen,offset; bits256 testpriv; uint8_t space[65536]; void *ptr2; + destpub = iguana_actualpubkey(&offset,cipher,cipherlen,destpub); + if ( 0 && (msgbits= SuperNET_deciphercalc(&ptr2,&msglen,testpriv,destpub,&cipher[offset],cipherlen-offset,space,sizeof(space))) == 0 ) + { + int32_t i; for (i=0; iipaddr); + qlen = iguana_queue_send(addr,delaymillis,&cipher[-sizeof(struct iguana_msghdr)],"SuperNETb",cipherlen); + if ( ptr != 0 ) + free(ptr); + } } - } - if ( retstr != 0 ) - { - i = 0; - if ( postflag == 0 && jsonflag == 0 ) - retstr = SuperNET_htmlresponse(space,size,&remains,1,retstr,1); - else remains = (int32_t)strlen(retstr); - printf("RETBUF.(%s)\n",retstr); - while ( remains > 0 ) + } else printf("error json2bits\n"); + free(serialized); + } else printf("cant parse.(%s)\n",jsonstr); + return(qlen); +} + +int32_t DHT_dist(bits256 desthash,bits256 hash) +{ + int32_t i,dist = 0; + for (i=0; i<4; i++) + dist += bitweight(desthash.ulongs[i] ^ hash.ulongs[i]); + printf("(dist.%d) ",dist); + return(dist*0); +} + +struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_info **coinp,uint64_t destipbits,bits256 category,bits256 subhash) +{ + int32_t i,j; struct iguana_peer *addr; uint16_t port; + *coinp = 0; + port = (uint16_t)(destipbits >> 32); + for (i=0; ipeers.active[j]; + if ( addr->usock >= 0 ) { - if ( errno != EAGAIN && errno != EWOULDBLOCK ) + if ( destipbits == addr->ipbits || category_peer(myinfo,addr,category,subhash) >= 0 ) { - //printf("%s: %s numsent.%d vs remains.%d len.%d errno.%d (%s) usock.%d\n",retstr,ipaddr,numsent,remains,recvlen,errno,strerror(errno),sock); - break; + if ( port == 0 || addr->A.port == port ) + { + *coinp = Coins[i]; + return(addr); + } } } - else if ( remains > 0 ) + } + } + } + return(0); +} + +char *SuperNET_DHTsend(struct supernet_info *myinfo,uint64_t destipbits,bits256 categoryhash,bits256 subhash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext) +{ + int32_t i,j; char *convstr,*jsonstr=0; struct iguana_peer *addr; cJSON *json; struct iguana_info *coin; + if ( myinfo == 0 ) + return(clonestr("{\"error\":\"no supernet_info\"}")); + json = cJSON_CreateObject(); + jaddstr(json,"agent","SuperNET"); + jaddstr(json,"method","DHT"); + convstr = SuperNET_hexconv(hexmsg); + jaddstr(json,"hexmsg",convstr); + if ( convstr != hexmsg ) + free(convstr); + if ( broadcastflag > 0 ) + jaddnum(json,"broadcast",broadcastflag-1); + if ( plaintext != 0 ) + jaddnum(json,"plaintext",plaintext!=0); + if ( bits256_nonz(categoryhash) > 0 && memcmp(categoryhash.bytes,GENESIS_PUBKEY.bytes,sizeof(bits256)) != 0 ) + jaddbits256(json,"categoryhash",categoryhash); + if ( bits256_nonz(subhash) > 0 && memcmp(subhash.bytes,GENESIS_PUBKEY.bytes,sizeof(bits256)) != 0 ) + jaddbits256(json,"subhash",subhash); + if ( SuperNET_hexmsgfind(myinfo,categoryhash,subhash,hexmsg,1) >= 0 ) + { + //char str[65]; printf("duplicate hex.(%s) for %s\n",hexmsg,bits256_str(str,categoryhash)); + return(clonestr("{\"error\":\"duplicate packet rejected\"}")); + } + else + { + //printf("DHT send\n"); + SuperNET_hexmsgadd(myinfo,categoryhash,subhash,hexmsg,tai_now(),0); + } + jsonstr = jprint(json,1); + if ( broadcastflag != 0 || destipbits == 0 ) + { + for (i=0; i 0 ) - printf("iguana sent.%d remains.%d of len.%d\n",numsent,remains,recvlen); + addr = &Coins[i]->peers.active[j]; + if ( addr->usock >= 0 && addr->supernet != 0 && (broadcastflag != 0 || category_peer(myinfo,addr,categoryhash,subhash) >= 0) ) + { + if ( strcmp("0.0.0.0",addr->ipaddr) != 0 && strcmp("127.0.0.1",addr->ipaddr) != 0 ) + { + //char str[65]; printf("BROADCAST[%d] crc.%x %s SEND.(%d) to %s\n",j,calc_crc32(0,jsonstr,(int32_t)strlen(jsonstr)),bits256_str(str,categoryhash),(int32_t)strlen(jsonstr),addr->ipaddr); + iguana_send_supernet(addr,jsonstr,maxdelay==0?0:(rand()%maxdelay)); + } + } } } - if ( retstr != space ) - free(retstr); } - //printf("done response sock.%d\n",sock); - closesocket(sock); + return(clonestr("{\"result\":\"packet sent to all peers\"}")); } + if ( (addr= iguana_peerfind(myinfo,&coin,destipbits,categoryhash,subhash)) == 0 ) + return(clonestr("{\"error\":\"no route found\"}")); + if ( SuperNET_hexmsgfind(myinfo,categoryhash,subhash,hexmsg,1) >= 0 ) + { + printf("SEND.(%s) to %s\n",jsonstr,addr->ipaddr); + iguana_send_supernet(addr,jsonstr,maxdelay==0?0:(rand()%maxdelay)); + return(clonestr("{\"result\":\"packet sent directly\"}")); + } + return(clonestr("{\"result\":\"no appropriate peers to send to\"}")); +} + +char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 categoryhash,bits256 subhash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext) +{ + uint32_t destipbits; char *retstr; + destipbits = (uint32_t)calc_ipbits(destip); + if ( (retstr = SuperNET_DHTsend(myinfo,destipbits,categoryhash,subhash,hexmsg,maxdelay,broadcastflag,plaintext)) != 0 ) + free(retstr); + return(clonestr("{\"result\":\"DHT sent\"}")); } -/* -struct endpoint find_epbits(struct relay_info *list,uint32_t ipbits,uint16_t port,int32_t type) + +char *SuperNET_forward(struct supernet_info *myinfo,char *hexmsg,uint32_t destipbits,bits256 categoryhash,bits256 subhash,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext) { - int32_t i; struct endpoint epbits; - memset(&epbits,0,sizeof(epbits)); - if ( list != 0 && list->num > 0 ) + return(SuperNET_DHTsend(myinfo,destipbits,categoryhash,subhash,hexmsg,maxdelay,broadcastflag,plaintext)); +} + +int32_t SuperNET_destination(struct supernet_info *myinfo,uint32_t *destipbitsp,bits256 *categoryp,bits256 *subhashp,int32_t *maxdelayp,cJSON *json,char *remoteaddr) +{ + char *destip; int32_t destflag = 0; + if ( (destip= jstr(json,"destip")) != 0 ) + *destipbitsp = (uint32_t)calc_ipbits(destip); + else *destipbitsp = 0; + *maxdelayp = juint(json,"delay"); + *categoryp = jbits256(json,"categoryhash"); + *subhashp = jbits256(json,"subhash"); + if ( *destipbitsp != 0 ) { - if ( type >= 0 ) - type = nn_portoffset(type); - for (i=0; inum&&i<(int32_t)(sizeof(list->connections)/sizeof(*list->connections)); i++) - if ( list->connections[i].ipbits == ipbits && (port == 0 || port == list->connections[i].port) && (type < 0 || type == list->connections[i].nn) ) - return(list->connections[i]); + if ( *destipbitsp == myinfo->myaddr.selfipbits ) + destflag |= SUPERNET_ISMINE; + else destflag |= SUPERNET_FORWARD; } - return(epbits); + else if ( bits256_nonz(*categoryp) > 0 ) + { + if ( category_peer(myinfo,0,*categoryp,*subhashp) > 0 ) + destflag |= SUPERNET_ISMINE; + if ( juint(json,"broadcast") > 0 ) + destflag |= SUPERNET_FORWARD; + } + if ( juint(json,"request") != 0 || remoteaddr == 0 || remoteaddr[0] == 0 || strcmp(remoteaddr,"127.0.0.1") == 0 ) + destflag |= SUPERNET_ISMINE; + return(destflag); } -int32_t add_relay(struct relay_info *list,struct endpoint epbits) +char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr,uint16_t port) { - list->connections[list->num % (sizeof(list->connections)/sizeof(*list->connections))] = epbits, list->num++; - if ( list->num > (sizeof(list->connections)/sizeof(*list->connections)) ) - printf("add_relay warning num.%d > %ld\n",list->num,(long)(sizeof(list->connections)/sizeof(*list->connections))); - return(list->num); + char hexbuf[8192]; bits256 category,subhash; + int32_t autologin = 0,hexlen,destflag,maxdelay,flag=0,newflag=0; uint32_t destipbits,timestamp; //cJSON *retjson; + char *str,*forwardstr=0,*retstr=0,*agent=0,*method=0,*message,*hexmsg=0,*jsonstr=0; uint64_t tag; + //printf("SuperNET_JSON.(%s)\n",jprint(json,0)); + if ( remoteaddr != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 ) + remoteaddr = 0; + if ( (agent = jstr(json,"agent")) == 0 ) + agent = "bitcoinrpc"; + method = jstr(json,"method"); + if ( agent != 0 ) + { + if ( strcmp(agent,"pangea") == 0 && jobj(json,"categoryhash") == 0 ) + { + jaddbits256(json,"categoryhash",calc_categoryhashes(0,"pangea",0)); + if ( jobj(json,"subhash") == 0 ) + jaddbits256(json,"subhash",GENESIS_PUBKEY); + } + else if ( strcmp(agent,"InstantDEX") == 0 ) + { + if ( jobj(json,"passphrase") != 0 ) + { + if ( (str= SuperNET_login(myinfo,0,json,remoteaddr,jstr(json,"handle"),0,0,jstr(json,"passphrase"))) != 0 ) + free(str); + autologin = 1; + } + else if ( jobj(json,"password") != 0 ) + { + if ( (str= SuperNET_login(myinfo,0,json,remoteaddr,jstr(json,"handle"),jstr(json,"password"),jstr(json,"permanentfile"),0)) != 0 ) + free(str); + autologin = 1; + } + } + } + if ( remoteaddr == 0 ) + { + if ( jobj(json,"timestamp") != 0 ) + jdelete(json,"timestamp"); + timestamp = (uint32_t)time(NULL); + jaddnum(json,"timestamp",timestamp); + } + if ( (tag= j64bits(json,"tag")) == 0 ) + { + OS_randombytes((uint8_t *)&tag,sizeof(tag)); + jadd64bits(json,"tag",tag); + } + //printf("SuperNET_JSON.(%s) remote.(%s)\n",jprint(json,0),remoteaddr!=0?remoteaddr:""); + destflag = SuperNET_destination(myinfo,&destipbits,&category,&subhash,&maxdelay,json,remoteaddr); + //printf("destflag.%d\n",destflag); + if ( method != 0 && (hexmsg= jstr(json,"hexmsg")) == 0 && strcmp(agent,"bitcoinrpc") != 0 && (message= jstr(json,"message")) == 0 ) + { + jsonstr = jprint(json,0); + hexlen = (int32_t)strlen(jsonstr); + if ( hexlen*2+1 > sizeof(hexbuf) ) + hexmsg = malloc(hexlen*2+1), flag = 1; + else hexmsg = hexbuf; + init_hexbytes_noT(hexmsg,(uint8_t *)jsonstr,(int32_t)strlen(jsonstr)+1); + } + if ( (destflag & SUPERNET_FORWARD) != 0 ) + { + if ( hexmsg != 0 ) + { + if ( SuperNET_hexmsgfind(myinfo,category,subhash,hexmsg,0) < 0 ) + { + //printf("FORWARD.(%s)\n",hexmsg); + newflag = 1; + SuperNET_hexmsgadd(myinfo,category,subhash,hexmsg,tai_now(),remoteaddr); + forwardstr = SuperNET_forward(myinfo,hexmsg,destipbits,category,subhash,maxdelay,juint(json,"broadcast"),juint(json,"plaintext")!=0); + } + } + } + if ( (destflag & SUPERNET_ISMINE) != 0 && agent != 0 && method != 0 ) + { + if ( strcmp(agent,"bitcoinrpc") != 0 && newflag == 0 && hexmsg != 0 && SuperNET_hexmsgfind(myinfo,category,subhash,hexmsg,0) < 0 ) + { + //printf("SuperNET_JSON hexmsgadd\n"); + SuperNET_hexmsgadd(myinfo,category,subhash,hexmsg,tai_now(),remoteaddr); + } + if ( (retstr= SuperNET_processJSON(myinfo,json,remoteaddr,port)) == 0 ) + printf("null retstr from SuperNET_JSON\n"); + } + if ( flag != 0 && hexmsg != 0 && hexmsg != hexbuf ) + free(hexmsg); + if ( retstr == 0 ) + retstr = forwardstr, forwardstr = 0; + if ( forwardstr != 0 ) + free(forwardstr); + if ( jsonstr != 0 ) + free(jsonstr); + if ( autologin != 0 ) + SuperNET_logout(myinfo,0,json,remoteaddr); + return(retstr); } -int32_t nn_add_lbservers(struct supernet_info *myinfo,uint16_t port,uint16_t globalport,uint16_t relaysport,int32_t priority,int32_t sock,char servers[][MAX_SERVERNAME],int32_t num) +char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen,int32_t compressed) { - int32_t i; char endpoint[512],pubendpoint[512]; struct endpoint epbits; uint32_t ipbits; - if ( num > 0 && servers != 0 && nn_setsockopt(sock,NN_SOL_SOCKET,NN_SNDPRIO,&priority,sizeof(priority)) >= 0 ) + struct supernet_info *myinfo;char *myipaddr,*method,*retstr,*checkstr; void *ptr=0; + bits256 senderpub,privkey,pubkey,nextprivkey,nextpubkey,nextdestpub; + uint16_t checkc,othercheckc; cJSON *json,*retjson; int32_t offset,maxdelay,msglen = datalen; + uint8_t space[8192],*msgbits = 0; + myinfo = SuperNET_MYINFO(0); + retstr = 0; + *delaymillisp = 0; + if ( compressed != 0 ) + { + //int32_t i; for (i=0; iipaddr); + addr->validpub >>= 1; + return(0); + } else { char str[65]; printf("GENESIS recv %s\n",bits256_str(str,senderpub)); } + } else printf("GENESIS recv GENESIS\n"); + } //else printf("decrypted mypriv.%llx senderpub.%llx\n",(long long)privkey.txid,(long long)senderpub.txid); + //for (i=0; iprivkey,senderpub,&senderpub.txid,sizeof(senderpub.txid)); + if ( checkc == othercheckc ) + addr->validpub += 1*0; + else if ( addr->validpub > 0 ) + addr->validpub >>= 1; + else addr->validpub--; + //printf("validpub.%d: %x vs %x priv.%llx senderpub.%llx\n",addr->validpub,checkc,othercheckc,(long long)myinfo->privkey.txid,(long long)senderpub.txid); + } + maxdelay = juint(json,"maxdelay"); + if ( 1 && jstr(json,"method") != 0 && strcmp(jstr(json,"method"),"getpeers") != 0 ) + printf("GOT >>>>>>>> SUPERNET P2P.(%s) from.%s %s valid.%d:%d\n",jprint(json,0),coin->symbol,addr->ipaddr,addr->validpub,addr->othervalid); + if ( (myipaddr= jstr(json,"yourip")) != 0 ) + SuperNET_checkipaddr(SuperNET_MYINFO(0),coin,addr,myipaddr,ipaddr); + jaddstr(json,"fromp2p",coin->symbol); + method = jstr(json,"method"); + if ( method != 0 && strcmp(method,"stop") == 0 ) + { + addr->dead = (uint32_t)time(NULL); + addr->rank = 0; + free_json(json); + if ( ptr != 0 ) + free(ptr); + //return(clonestr("{\"result\":\"peer marked as dead\"}")); + return(0); + } + retstr = SuperNET_JSON(myinfo,json,ipaddr,addr->A.port); + //printf("(%s) -> p2pret.(%s)\n",jprint(json,0),retstr); + *delaymillisp = SuperNET_delaymillis(myinfo,maxdelay); + senderpub = jbits256(json,"mypub"); + addr->othervalid = (int32_t)jdouble(json,"ov"); + addr->pubkey = senderpub; + free_json(json); + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( jstr(retjson,"error") != 0 || (jstr(retjson,"result") != 0 && jstr(retjson,"method") == 0) ) { - printf("null ipbits.(%s)\n",servers[i]); - continue; + //printf("filter.(%s) no need to send back\n",retstr); + free(retstr); + retstr = 0; } - //printf("epbits.%llx ipbits.%x %s\n",*(long long *)&epbits,(uint32_t)ipbits,endpoint); - if ( ismyaddress(servers[i],myinfo) == 0 ) + free_json(retjson); + } + } else printf("error decoding bits2json\n"); + if ( ptr != 0 ) + free(ptr); + return(retstr); +} +#else +char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr,uint16_t port) +{ + int32_t autologin = 0; uint32_t timestamp; char *retstr=0,*agent=0,*method=0,*jsonstr=0; uint64_t tag; + //printf("SuperNET_JSON.(%s)\n",jprint(json,0)); + if ( remoteaddr != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 ) + remoteaddr = 0; + if ( (agent = jstr(json,"agent")) == 0 ) + agent = "bitcoinrpc"; + method = jstr(json,"method"); + if ( remoteaddr == 0 ) + { + if ( jobj(json,"timestamp") != 0 ) + jdelete(json,"timestamp"); + timestamp = (uint32_t)time(NULL); + jaddnum(json,"timestamp",timestamp); + } + if ( (tag= j64bits(json,"tag")) == 0 ) + { + OS_randombytes((uint8_t *)&tag,sizeof(tag)); + jadd64bits(json,"tag",tag); + } + if ( (retstr= SuperNET_processJSON(myinfo,json,remoteaddr,port)) == 0 ) + printf("null retstr from SuperNET_JSON\n"); + if ( jsonstr != 0 ) + free(jsonstr); + if ( autologin != 0 ) + SuperNET_logout(myinfo,0,json,remoteaddr); + return(retstr); +} +#endif + +cJSON *SuperNET_peerarray(struct iguana_info *coin,int32_t max,int32_t supernetflag) +{ + int32_t i,r,j,n = 0; struct iguana_peer *addr; cJSON *array = cJSON_CreateArray(); + r = rand(); + for (j=0; jpeers->active[i]; + if ( addr->usock >= 0 && supernetflag == (addr->supernet != 0) ) + { + jaddistr(array,addr->ipaddr); + if ( ++n >= max ) + break; + } + } + if ( n == 0 ) + { + free_json(array); + return(0); + } + return(array); +} + +int32_t SuperNET_coinpeers(struct iguana_info *coin,cJSON *SNjson,cJSON *rawjson,int32_t max) +{ + cJSON *array,*item; + if ( (array= SuperNET_peerarray(coin,max,1)) != 0 ) + { + max -= cJSON_GetArraySize(array); + item = cJSON_CreateObject(); + jaddstr(item,"coin",coin->symbol); + jadd(item,"peers",array); + jaddi(SNjson,item); + } + if ( max > 0 && (array= SuperNET_peerarray(coin,max,0)) != 0 ) + { + max -= cJSON_GetArraySize(array); + item = cJSON_CreateObject(); + jaddstr(item,"coin",coin->symbol); + jadd(item,"peers",array); + jaddi(rawjson,item); + } + return(max); +} + +void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int32_t supernetflag) +{ + int32_t i,j,m; cJSON *coinarray,*item; char *symbol,*ipaddr; struct iguana_info *ptr; + if ( array != 0 && n > 0 ) + { + for (i=0; i= 0 ) + ptr = iguana_coinfind(symbol); + if ( (coinarray= jarray(&m,item,"peers")) != 0 ) { - printf("+R%s ",endpoint); - add_relay(&myinfo->active,epbits); - } - if ( myinfo->subclient >= 0 ) - { - if ( myinfo->iamrelay != 0 ) + for (j=0; jsubclient,pubendpoint) >= 0 ) - printf("+P%s ",pubendpoint); + if ( (ipaddr= jstr(jitem(coinarray,j),0)) != 0 ) + SuperNET_remotepeer(myinfo,ptr,symbol,ipaddr,supernetflag); + else printf("no ipaddr[%d] of %d\n",j,m); } - epbits = calc_epbits("tcp",ipbits,globalport,NN_PUB); - expand_epbits(pubendpoint,epbits); - if ( nn_connect(myinfo->subclient,pubendpoint) >= 0 ) - printf("+P%s ",pubendpoint); } + printf("parsed.%d %s.peers supernet.%d\n",m,symbol,supernetflag); } } - printf("added priority.%d\n",priority); - priority++; - } else printf("error setting priority.%d (%s)\n",priority,nn_errstr()); - return(priority); -} - -int32_t _lb_socket(struct supernet_info *myinfo,uint16_t port,uint16_t globalport,uint16_t relaysport,int32_t maxmillis,char servers[][MAX_SERVERNAME],int32_t num,char backups[][MAX_SERVERNAME],int32_t numbacks,char failsafes[][MAX_SERVERNAME],int32_t numfailsafes) -{ - int32_t lbsock,timeout,retrymillis,priority = 1; - if ( (lbsock= nn_socket(AF_SP,NN_REQ)) >= 0 ) - { - retrymillis = (maxmillis / 30) + 1; - printf("!!!!!!!!!!!! lbsock.%d !!!!!!!!!!!\n",lbsock); - if ( nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_RECONNECT_IVL,&retrymillis,sizeof(retrymillis)) < 0 ) - printf("error setting NN_REQ NN_RECONNECT_IVL_MAX socket %s\n",nn_errstr()); - else if ( nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_RECONNECT_IVL_MAX,&maxmillis,sizeof(maxmillis)) < 0 ) - fprintf(stderr,"error setting NN_REQ NN_RECONNECT_IVL_MAX socket %s\n",nn_errstr()); - timeout = SUPERNET_NETWORKTIMEOUT; - if ( 1 && nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)) < 0 ) - printf("error setting NN_SOL_SOCKET NN_RCVTIMEO socket %s\n",nn_errstr()); - timeout = 100; - if ( 1 && nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)) < 0 ) - printf("error setting NN_SOL_SOCKET NN_SNDTIMEO socket %s\n",nn_errstr()); - if ( num > 0 ) - priority = nn_add_lbservers(myinfo,port,globalport,relaysport,priority,lbsock,servers,num); - if ( numbacks > 0 ) - priority = nn_add_lbservers(myinfo,port,globalport,relaysport,priority,lbsock,backups,numbacks); - if ( numfailsafes > 0 ) - priority = nn_add_lbservers(myinfo,port,globalport,relaysport,priority,lbsock,failsafes,numfailsafes); - } else printf("error getting req socket %s\n",nn_errstr()); - //printf("myinfo->lb.num %d\n",myinfo->lb.num); - return(lbsock); -} - -int32_t nn_lbsocket(struct supernet_info *myinfo,int32_t maxmillis,int32_t port,uint16_t globalport,uint16_t relaysport) -{ - char Cservers[32][MAX_SERVERNAME],Bservers[32][MAX_SERVERNAME],failsafes[4][MAX_SERVERNAME]; - int32_t n,m,lbsock,numfailsafes = 0; - printf("redo lbsocket()\n"), exit(-1); - //strcpy(failsafes[numfailsafes++],"5.9.56.103"); - //strcpy(failsafes[numfailsafes++],"5.9.102.210"); - // n = crackfoo_servers(Cservers,sizeof(Cservers)/sizeof(*Cservers),port); - // m = badass_servers(Bservers,sizeof(Bservers)/sizeof(*Bservers),port); - lbsock = _lb_socket(myinfo,port,globalport,relaysport,maxmillis,Bservers,m,Cservers,n*0,failsafes,numfailsafes); - return(lbsock); -} - -void add_standard_fields(char *request) -{ - cJSON *json; uint64_t tag; - if ( (json= cJSON_Parse(request)) != 0 ) - { - if ( get_API_nxt64bits(cJSON_GetObjectItem(json,"NXT")) == 0 ) - { - randombytes((void *)&tag,sizeof(tag)); - sprintf(request + strlen(request) - 1,",\"NXT\":\"%s\",\"tag\":\"%llu\"}",myinfo->NXTADDR,(long long)tag); - if ( myinfo->iamrelay != 0 && (myinfo->hostname[0] != 0 || myinfo->ipaddr[0] != 0) ) - sprintf(request + strlen(request) - 1,",\"iamrelay\":\"%s\"}",myinfo->hostname[0]!=0?myinfo->hostname:myinfo->myipaddr); - } - free_json(json); } } -char *nn_loadbalanced(struct supernet_info *myinfo,uint8_t *data,int32_t len) +cJSON *SuperNET_rosettajson(bits256 privkey,int32_t showprivs) { - char *msg,*jsonstr = 0; - int32_t sendlen,i,lbsock,recvlen = 0; - if ( (lbsock= myinfo->lbclient) < 0 ) - return(clonestr("{\"error\":\"invalid load balanced socket\"}")); - for (i=0; i<10; i++) - if ( (nn_socket_status(lbsock,1) & NN_POLLOUT) != 0 ) - break; - if ( myinfo->Debuglevel > 2 ) - printf("sock.%d NN_LBSEND.(%s)\n",lbsock,data); - //fprintf(stderr,"send to network\n"); - if ( (sendlen= nn_send(lbsock,data,len,0)) == len ) + uint8_t rmd160[20],pub[33]; uint64_t nxt64bits; bits256 pubkey; + char str2[41],wifbuf[64],addr[64],str[128]; cJSON *retjson; + pubkey = acct777_pubkey(privkey); + nxt64bits = acct777_nxt64bits(pubkey); + retjson = cJSON_CreateObject(); + jaddbits256(retjson,"pubkey",pubkey); + RS_encode(str,nxt64bits); + jaddstr(retjson,"RS",str); + jadd64bits(retjson,"NXT",nxt64bits); + bitcoin_pubkey33(0,pub,privkey); + init_hexbytes_noT(str,pub,33); + jaddstr(retjson,"btcpubkey",str); + calc_OP_HASH160(str2,rmd160,str); + jaddstr(retjson,"rmd160",str2); + if ( bitcoin_address(addr,0,pub,33) != 0 ) { - for (i=0; i<10; i++) - if ( (nn_socket_status(lbsock,1) & NN_POLLIN) != 0 ) - break; - if ( (recvlen= nn_recv(lbsock,&msg,NN_MSG,0)) > 0 ) + jaddstr(retjson,"BTC",addr); + if ( showprivs != 0 ) { - if ( myinfo->Debuglevel > 2 ) - printf("LBRECV.(%s)\n",msg); - jsonstr = clonestr((char *)msg); - nn_freemsg(msg); + bitcoin_priv2wif(wifbuf,privkey,128); + jaddstr(retjson,"BTCwif",wifbuf); } - else + } + if ( bitcoin_address(addr,60,pub,33) != 0 ) + { + jaddstr(retjson,"BTCD",addr); + if ( showprivs != 0 ) { - printf("nn_loadbalanced got recvlen.%d %s\n",recvlen,nn_errstr()); - jsonstr = clonestr("{\"error\":\"lb recv error, probably timeout\"}"); + bitcoin_priv2wif(wifbuf,privkey,188); + jaddstr(retjson,"BTCDwif",wifbuf); } - } else printf("got sendlen.%d instead of %d %s\n",sendlen,len,nn_errstr()), jsonstr = clonestr("{\"error\":\"lb send error\"}"); - return(jsonstr); + } + if ( showprivs != 0 ) + jaddbits256(retjson,"privkey",privkey); + return(retjson); +} + +#include "../includes/iguana_apidefs.h" + +STRING_ARG(SuperNET,addr2rmd160,address) +{ + uint8_t addrtype,rmd160[20]; char rmdstr[41]; cJSON *retjson; + bitcoin_addr2rmd160(&addrtype,rmd160,address); + init_hexbytes_noT(rmdstr,rmd160,sizeof(rmd160)); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",rmdstr); + jaddnum(retjson,"addrtype",addrtype); + jaddstr(retjson,"address",address); + return(jprint(retjson,1)); } -cJSON *relay_json(struct relay_info *list) +STRING_ARG(SuperNET,rmd160conv,rmd160) { - cJSON *json,*array; char endpoint[512]; int32_t i; - if ( list == 0 || list->num == 0 ) - return(0); - array = cJSON_CreateArray(); - for (i=0; inum&&i<(int32_t)(sizeof(list->connections)/sizeof(*list->connections)); i++) + uint8_t rmdbuf[20]; char coinaddr[64],p2shaddr[64]; cJSON *retjson = cJSON_CreateObject(); + if ( rmd160 != 0 && strlen(rmd160) == 40 ) { - expand_epbits(endpoint,list->connections[i]); - jaddistr(array,endpoint); + decode_hex(rmdbuf,20,rmd160); + bitcoin_address(coinaddr,coin->chain->pubtype,rmdbuf,20); + bitcoin_address(p2shaddr,coin->chain->p2shtype,rmdbuf,20); + jaddstr(retjson,"result","success"); + jaddstr(retjson,"address",coinaddr); + jaddstr(retjson,"p2sh",p2shaddr); } - json = cJSON_CreateObject(); - jadd(json,"endpoints",array); - //cJSON_AddItemToObject(json,"type",cJSON_CreateString(nn_typestr(list->mytype))); - //cJSON_AddItemToObject(json,"dest",cJSON_CreateString(nn_typestr(list->desttype))); - jaddnum(json,"total",list->num); - return(json); + return(jprint(retjson,1)); } -char *relays_jsonstr(struct supernet_info *myinfo,char *jsonstr,cJSON *argjson) +HASH_AND_INT(SuperNET,priv2pub,privkey,addrtype) { - cJSON *json; - if ( myinfo->iamrelay != 0 && myinfo->ipaddr[0] != 0 ) + cJSON *retjson; bits256 pub; uint8_t pubkey[33]; char coinaddr[64],pubkeystr[67]; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + retjson = cJSON_CreateObject(); + crypto_box_priv2pub(pub.bytes,privkey.bytes); + jaddbits256(retjson,"curve25519",pub); + pub = bitcoin_pubkey33(myinfo->ctx,pubkey,privkey); + init_hexbytes_noT(pubkeystr,pubkey,33); + jaddstr(retjson,"secp256k1",pubkeystr); + bitcoin_address(coinaddr,addrtype,pubkey,33); + jaddstr(retjson,"result",coinaddr); + return(jprint(retjson,1)); +} + +ZERO_ARGS(SuperNET,keypair) +{ + cJSON *retjson; bits256 pubkey,privkey; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + retjson = cJSON_CreateObject(); + crypto_box_keypair(pubkey.bytes,privkey.bytes); + jaddstr(retjson,"result","generated keypair"); + jaddbits256(retjson,"privkey",privkey); + jaddbits256(retjson,"pubkey",pubkey); + return(jprint(retjson,1)); +} + +TWOHASHES_AND_STRING(SuperNET,decipher,privkey,srcpubkey,cipherstr) +{ + int32_t cipherlen=0,msglen; char *retstr; cJSON *retjson; void *ptr = 0; uint8_t *cipher,*message,space[8192]; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + if ( cipherstr != 0 ) + cipherlen = (int32_t)strlen(cipherstr) >> 1; + if ( cipherlen < crypto_box_NONCEBYTES ) + return(clonestr("{\"error\":\"cipher is too short\"}")); + cipher = calloc(1,cipherlen); + decode_hex(cipher,cipherlen,cipherstr); + if ( (message= SuperNET_deciphercalc(&ptr,&msglen,privkey,srcpubkey,cipher,cipherlen,space,sizeof(space))) != 0 ) { - json = cJSON_CreateObject(); - jaddstr(json,"relay",myinfo->ipaddr); - if ( myinfo->active.num > 0 ) - jadd(json,"relays",relay_json(&myinfo->active)); - return(jprint(json,1)); - } - else return(clonestr("{\"error\":\"get relay list from relay\"}")); + message[msglen] = 0; + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","deciphered message"); + jaddstr(retjson,"message",(char *)message); + retstr = jprint(retjson,1); + if ( ptr != 0 ) + free(ptr); + } else retstr = clonestr("{\"error\":\"couldnt decipher message\"}"); + return(retstr); } -int32_t init_SUPERNET_pullsock(struct supernet_info *myinfo,int32_t sendtimeout,int32_t recvtimeout) +TWOHASHES_AND_STRING(SuperNET,cipher,privkey,destpubkey,message) { - char bindaddr[64],*transportstr; int32_t iter; - myinfo->pullsock = -1; - if ( (myinfo->pullsock= nn_socket(AF_SP,NN_PULL)) < 0 ) + cJSON *retjson; char *retstr,*hexstr,space[8129]; uint8_t space2[8129]; + uint8_t *cipher; int32_t cipherlen,onetimeflag; bits256 origprivkey; void *ptr = 0; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + if ( (cipher= SuperNET_ciphercalc(&ptr,&cipherlen,&privkey,&destpubkey,(uint8_t *)message,(int32_t)strlen(message)+1,space2,sizeof(space2))) != 0 ) { - printf("error creating pullsock %s\n",nn_strerror(nn_errno())); - return(-1); + if ( cipherlen > sizeof(space)/2 ) + hexstr = calloc(1,(cipherlen<<1)+1); + else hexstr = (void *)space; + init_hexbytes_noT(hexstr,cipher,cipherlen); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",hexstr); + onetimeflag = memcmp(origprivkey.bytes,privkey.bytes,sizeof(privkey)); + if ( onetimeflag != 0 ) + { + //jaddbits256(retjson,"onetime_privkey",privkey); + jaddbits256(retjson,"onetime_pubkey",destpubkey); + if ( onetimeflag == 2 ) + jaddstr(retjson,"warning","onetime keypair was used to broadcast"); + } + retstr = jprint(retjson,1); + if ( hexstr != (void *)space ) + free(hexstr); + if ( ptr != 0 ) + free(ptr); + return(retstr); } - printf("got pullsock.%d\n",myinfo->pullsock); - if ( nn_settimeouts(myinfo->pullsock,sendtimeout,recvtimeout) < 0 ) + printf("error encrypting message.(%s)\n",message); + return(clonestr("{\"error\":\"cant encrypt message\"}")); +} + +bits256 SuperNET_pindecipher(IGUANA_ARGS,char *pin,char *privcipher) +{ + cJSON *testjson; char *mstr,*cstr; bits256 privkey,pinpriv,pinpub; + conv_NXTpassword(pinpriv.bytes,pinpub.bytes,(uint8_t *)pin,(int32_t)strlen(pin)); + privkey = GENESIS_PRIVKEY; + if ( (cstr= SuperNET_decipher(IGUANA_CALLARGS,pinpriv,pinpub,privcipher)) != 0 ) { - printf("error settime pullsock timeouts %s\n",nn_strerror(nn_errno())); - return(-1); - } - printf("PULLsock.%d\n",myinfo->pullsock); - for (iter=0; iter<2; iter++) + if ( (testjson= cJSON_Parse(cstr)) != 0 ) + { + if ( (mstr= jstr(testjson,"message")) != 0 && strlen(mstr) == sizeof(bits256)*2 ) + { + decode_hex(privkey.bytes,sizeof(privkey),mstr); + } else printf("error cant find message privcipher\n"); + free_json(testjson); + } else printf("Error decipher.(%s)\n",cstr); + free(cstr); + } else printf("null return from deciphering privcipher\n"); + return(privkey); +} + +THREE_STRINGS(SuperNET,rosetta,passphrase,pin,showprivkey) +{ + uint8_t flag = 0; uint64_t nxt64bits; bits256 check,privkey,pubkey,pinpriv,pinpub; + char str[128],privcipher[512],*privcipherstr,*cstr; cJSON *retjson; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + nxt64bits = conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); + if ( showprivkey != 0 && strcmp(showprivkey,"yes") == 0 ) + flag = 1; + privcipher[0] = 0; + conv_NXTpassword(pinpriv.bytes,pinpub.bytes,(uint8_t *)pin,(int32_t)strlen(pin)); + if ( (cstr= SuperNET_cipher(IGUANA_CALLARGS,pinpriv,pinpub,bits256_str(str,privkey))) != 0 ) { - transportstr = (iter == 0) ? "ipc" : "inproc"; - sprintf(bindaddr,"%s://SuperNET.agents",transportstr); - if ( nn_bind(myinfo->pullsock,bindaddr) < 0 ) + if ( (retjson= cJSON_Parse(cstr)) != 0 ) { - printf("error binding pullsock to (%s) %s\n",bindaddr,nn_strerror(nn_errno())); - return(-1); - } + if ( (privcipherstr= jstr(retjson,"result")) != 0 ) + strcpy(privcipher,privcipherstr); + free_json(retjson); + } else printf("error parsing cipher retstr.(%s)\n",cstr); + free(cstr); + } else printf("error SuperNET_cipher null return\n"); + retjson = SuperNET_rosettajson(privkey,flag); + jaddstr(retjson,"privcipher",privcipher); + check = SuperNET_pindecipher(IGUANA_CALLARGS,pin,privcipher); + if ( memcmp(check.bytes,privkey.bytes,sizeof(check)) != 0 ) + { + jaddbits256(retjson,"deciphered",check); + jaddstr(retjson,"error","cant recreate privkey from (pin + privcipher)"); } - return(0); + else if ( flag != 0 ) + jaddbits256(retjson,"deciphered",check); + if ( jobj(retjson,"error") == 0 ) + jaddstr(retjson,"result","use pin and privcipher to access wallet"); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,broadcastcipher,message) +{ + bits256 zero; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + memset(zero.bytes,0,sizeof(zero)); + return(SuperNET_cipher(IGUANA_CALLARGS,zero,zero,message)); +} + +STRING_ARG(SuperNET,broadcastdecipher,message) +{ + bits256 zero; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + memset(zero.bytes,0,sizeof(zero)); + return(SuperNET_decipher(IGUANA_CALLARGS,zero,zero,message)); +} + +HASH_AND_STRING(SuperNET,multicastcipher,pubkey,message) +{ + bits256 zero; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + memset(zero.bytes,0,sizeof(zero)); + return(SuperNET_cipher(IGUANA_CALLARGS,zero,pubkey,message)); +} + +HASH_AND_STRING(SuperNET,multicastdecipher,privkey,cipherstr) +{ + bits256 zero; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + memset(zero.bytes,0,sizeof(zero)); + return(SuperNET_decipher(IGUANA_CALLARGS,privkey,zero,cipherstr)); } -void busdata_init(struct supernet_info *myinfo,int32_t sendtimeout,int32_t recvtimeout,int32_t firstiter) +ZERO_ARGS(SuperNET,stop) { - char endpoint[512]; int32_t i; - myinfo->servicesock = myinfo->pubglobal = myinfo->pubrelays = myinfo->lbserver = -1; - endpoint[0] = 0; - if ( (myinfo->subclient= nn_createsocket(myinfo,endpoint,0,"NN_SUB",NN_SUB,0,sendtimeout,recvtimeout)) >= 0 ) + if ( remoteaddr == 0 || strncmp(remoteaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 ) { - myinfo->pfd[myinfo->numservers++].fd = myinfo->subclient, printf("numservers.%d\n",myinfo->numservers); - nn_setsockopt(myinfo->subclient,NN_SUB,NN_SUB_SUBSCRIBE,"",0); - } else printf("error creating subclient\n"); - myinfo->lbclient = nn_lbsocket(myinfo,SUPERNET_NETWORKTIMEOUT,SUPERNET_PORT + LB_OFFSET,myinfo->port + PUBGLOBALS_OFFSET,myinfo->port + PUBRELAYS_OFFSET); - printf("LBclient.%d port.%d\n",myinfo->lbclient,SUPERNET_PORT + LB_OFFSET); - sprintf(endpoint,"%s://%s:%u",myinfo->transport,myinfo->ipaddr,myinfo->serviceport); - if ( (myinfo->servicesock= nn_createsocket(myinfo,endpoint,1,"NN_REP",NN_REP,myinfo->serviceport,sendtimeout,recvtimeout)) >= 0 ) - myinfo->pfd[myinfo->numservers++].fd = myinfo->servicesock, printf("numservers.%d\n",myinfo->numservers); - else printf("error creating servicesock\n"); - for (i=0; inumservers; i++) - myinfo->pfd[i].events = NN_POLLIN | NN_POLLOUT; - printf("myinfo->iamrelay %d, numservers.%d ipaddr.(%s://%s) port.%d serviceport.%d\n",myinfo->iamrelay,myinfo->numservers,myinfo->transport,myinfo->ipaddr,myinfo->port,myinfo->serviceport); + iguana_exit(); + return(clonestr("{\"result\":\"exit started\"}")); + } else return(clonestr("{\"error\":\"cant do a remote stop of this node\"}")); } -void SuperNET_init(struct supernet_info *myinfo,char *jsonstr) +TWO_ARRAYS(SuperNET,mypeers,supernet,rawpeers) { - char *str; - if ( jsonstr != 0 && (str= SuperNET_JSON(myinfo,jsonstr)) != 0 ) - free(str); - busdata_init(myinfo,10,1,0); - init_SUPERNET_pullsock(myinfo,10,10); -}*/ + SuperNET_parsepeers(myinfo,supernet,cJSON_GetArraySize(supernet),1); + SuperNET_parsepeers(myinfo,rawpeers,cJSON_GetArraySize(rawpeers),0); + return(clonestr("{\"result\":\"peers parsed\"}")); +} -int32_t Supernet_lineparse(char *key,int32_t keymax,char *value,int32_t valuemax,char *src) +STRING_ARG(SuperNET,getpeers,activecoin) { - int32_t a,b,c,n = 0; - key[0] = value[0] = 0; - while ( (c= src[n]) == ' ' || c == '\t' || c == '\n' || c == '\t' ) - n++; - while ( (c= src[n]) != ':' && c != 0 ) + int32_t max = 64; struct iguana_info *tmp; cJSON *SNjson,*rawjson,*retjson = cJSON_CreateObject(); + SNjson = cJSON_CreateArray(); + rawjson = cJSON_CreateArray(); + if ( coin != 0 ) + max = SuperNET_coinpeers(coin,SNjson,rawjson,max); + else { - *key++ = c; - if ( ++n >= keymax-1 ) + //portable_mutex_lock(&Allcoins_mutex); + HASH_ITER(hh,myinfo->allcoins,coin,tmp) { - *key = 0; - printf("lineparse overflow key.(%s)\n",src); - return(-1); + max = SuperNET_coinpeers(coin,SNjson,rawjson,max); } + //portable_mutex_unlock(&Allcoins_mutex); } - *key = 0; - if ( src[n] != ':' ) - return(n); - n++; - while ( (c= src[n]) == ' ' || c == '\t' ) - n++; - while ( (c= src[n]) != 0 && c != '\r' && c != '\n' ) - { - if ( c == '%' && (a= src[n+1]) != 0 && (b= src[n+2]) != 0 ) - c = ((unhex(a) << 4) | unhex(b)), n += 2; - *value++ = c; - n++; - if ( n >= valuemax-1 ) - { - *value = 0; - printf("lineparse overflow.(%s)\n",src); - return(-1); - } + if ( max != 64 ) + { + jaddstr(retjson,"agent","SuperNET"); + jaddstr(retjson,"method","mypeers"); + jadd(retjson,"supernet",SNjson); + jadd(retjson,"rawpeers",rawjson); } - *value = 0; - if ( src[n] != 0 ) + else { - n++; - while ( (c= src[n]) == '\r' || c == '\n' ) - n++; + jaddstr(retjson,"error","no peers"); + free_json(SNjson); + free_json(rawjson); } - return(n); + return(jprint(retjson,1)); } -cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr) +/*TWOSTRINGS_AND_TWOHASHES_AND_TWOINTS(SuperNET,DHT,hexmsg,destip,categoryhash,subhash,maxdelay,broadcast) { - int32_t i,n,totallen,datalen,len = 0; cJSON *json,*array; char key[8192],*data; - json = cJSON_CreateObject(); - array = cJSON_CreateArray(); - totallen = (int32_t)strlen(urlstr); - while ( 1 ) + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"cant remote DHT\"}")); + else if ( hexmsg == 0 || is_hexstr(hexmsg,(int32_t)strlen(hexmsg)) <= 0 ) + return(clonestr("{\"error\":\"hexmsg missing or not in hex\"}")); + return(SuperNET_DHTencode(myinfo,destip,categoryhash,subhash,hexmsg,maxdelay,broadcast,juint(json,"plaintext")!=0)); +}*/ + +HASH_AND_STRING(SuperNET,saveconf,wallethash,confjsonstr) +{ + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + return(clonestr("{\"result\":\"saveconf here\"}")); +} + +HASH_ARRAY_STRING(SuperNET,layer,mypriv,otherpubs,str) +{ + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + return(clonestr("{\"result\":\"layer encrypt here\"}")); +} + +TWO_STRINGS(SuperNET,categoryhashes,category,subcategory) +{ + bits256 categoryhash,subhash; cJSON *retjson = cJSON_CreateObject(); + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + jaddstr(retjson,"result","category hashes calculated"); + jaddbits256(retjson,"categoryhash",categoryhash); + jaddbits256(retjson,"subhash",subhash); + return(jprint(retjson,1)); +} + +TWO_STRINGS(SuperNET,subscribe,category,subcategory) +{ + bits256 categoryhash,subhash; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + if ( category_subscribe(myinfo,categoryhash,subhash) != 0 ) + return(clonestr("{\"result\":\"subscribed\"}")); + else return(clonestr("{\"error\":\"couldnt subscribe\"}")); +} + +TWO_STRINGS(SuperNET,gethexmsg,category,subcategory) +{ + bits256 categoryhash,subhash; struct category_msg *m; char *hexstr; cJSON *retjson; struct private_chain *cat; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + if ( (m= category_gethexmsg(myinfo,&cat,categoryhash,subhash)) != 0 ) { - for (i=len; urlstr[i]!=0; i++) - if ( urlstr[i] == '\r' || urlstr[i] == '\n' ) - break; - if ( i == len && (urlstr[len] == '\r' || urlstr[len] == '\n') ) + hexstr = calloc(1,m->len*2+1); + init_hexbytes_noT(hexstr,m->msg,m->len); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",hexstr); + free(hexstr); + return(jprint(retjson,1)); + } else return(clonestr("{\"result\":\"no message\"}")); +} + +THREE_STRINGS(SuperNET,posthexmsg,category,subcategory,hexmsg) +{ + bits256 categoryhash,subhash; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + category_posthexmsg(myinfo,categoryhash,subhash,hexmsg,tai_now(),remoteaddr); + return(clonestr("{\"result\":\"posted message\"}")); +} + +THREE_STRINGS(SuperNET,announce,category,subcategory,message) +{ + bits256 categoryhash,subhash; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + return(SuperNET_categorymulticast(myinfo,0,categoryhash,subhash,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext"),json,remoteaddr)); +} + +THREE_STRINGS(SuperNET,survey,category,subcategory,message) +{ + bits256 categoryhash,subhash; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + return(SuperNET_categorymulticast(myinfo,1,categoryhash,subhash,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext"),json,remoteaddr)); +} + +STRING_ARG(SuperNET,wif2priv,wif) +{ + bits256 privkey; char str[65]; uint8_t privkeytype; cJSON *retjson = cJSON_CreateObject(); + if ( bitcoin_wif2priv(&privkeytype,&privkey,wif) == sizeof(privkey) ) + { + jaddstr(retjson,"result","success"); + jaddstr(retjson,"privkey",bits256_str(str,privkey)); + jaddnum(retjson,"type",privkeytype); + } else jaddstr(retjson,"error","couldnt convert wif"); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,priv2wif,priv) +{ + bits256 privkey; char wifstr[65]; uint8_t wiftype; cJSON *retjson = cJSON_CreateObject(); + if ( is_hexstr(priv,0) == sizeof(bits256)*2 ) + { + wiftype = coin != 0 ? coin->chain->wiftype : 0x80; + decode_hex(privkey.bytes,sizeof(privkey),priv); + if ( bitcoin_priv2wif(wifstr,privkey,wiftype) > 0 ) { - len++; - continue; - } - urlstr[i] = 0; - if ( (n= Supernet_lineparse(key,sizeof(key),value,bufsize,&urlstr[len])) > 0 ) - { - if ( value[0] != 0 ) - jaddstr(json,key,value); - else jaddistr(array,key); - len += (n + 1); - if ( strcmp(key,"Content-Length") == 0 && (datalen= atoi(value)) > 0 ) + jaddstr(retjson,"result","success"); + jaddstr(retjson,"privkey",priv); + jaddnum(retjson,"type",wiftype); + jaddstr(retjson,"wif",wifstr); + } else jaddstr(retjson,"error","couldnt convert privkey"); + } else jaddstr(retjson,"error","non 32 byte hex privkey"); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,myipaddr,ipaddr) +{ + cJSON *retjson = cJSON_CreateObject(); + if ( myinfo->ipaddr[0] == 0 ) + { + if ( is_ipaddr(ipaddr) != 0 ) + strcpy(myinfo->ipaddr,ipaddr); + } + jaddstr(retjson,"result",myinfo->ipaddr); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,setmyipaddr,ipaddr) +{ + cJSON *retjson = cJSON_CreateObject(); + if ( is_ipaddr(ipaddr) != 0 ) + { + strcpy(myinfo->ipaddr,ipaddr); + jaddstr(retjson,"result",myinfo->ipaddr); + } else jaddstr(retjson,"error","illegal ipaddr"); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,utime2utc,utime) +{ + uint32_t utc = 0; cJSON *retjson = cJSON_CreateObject(); + utc = OS_conv_utime(utime); + char str[65]; printf("utime.%s -> %u -> %s\n",utime,utc,utc_str(str,utc)); + jaddnum(retjson,"result",utc); + return(jprint(retjson,1)); +} + +INT_ARG(SuperNET,utc2utime,utc) +{ + char str[65]; cJSON *retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",utc_str(str,utc)); + return(jprint(retjson,1)); +} + +ZERO_ARGS(SuperNET,logout) +{ + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + iguana_walletlock(myinfo,coin); + return(clonestr("{\"result\":\"logged out\"}")); +} + +ZERO_ARGS(SuperNET,activehandle) +{ + cJSON *retjson; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + retjson = SuperNET_rosettajson(myinfo->persistent_priv,0); + jaddstr(retjson,"result","success"); + jaddstr(retjson,"handle",myinfo->handle); + jaddbits256(retjson,"persistent",myinfo->myaddr.persistent); + if ( myinfo->expiration != 0 ) + { + jaddstr(retjson,"status","unlocked"); + jaddnum(retjson,"duration",myinfo->expiration - time(NULL)); + } else jaddstr(retjson,"status","locked"); + SuperNET_MYINFOadd(myinfo); + return(jprint(retjson,1)); +} + +struct supernet_info *SuperNET_accountfind(cJSON *json) +{ + int32_t num; char *decryptstr; struct supernet_info M,*myinfo; struct iguana_info *coin = 0; + char *password,*permanentfile,*passphrase,*remoteaddr,*perspriv; + myinfo = 0; + if ( (password= jstr(json,"password")) == 0 ) + password = ""; + if ( (permanentfile= jstr(json,"permanentfile")) == 0 ) + permanentfile = ""; + if ( (passphrase= jstr(json,"passphrase")) == 0 ) + passphrase = ""; + remoteaddr = jstr(json,"remoteaddr"); + if ( (passphrase == 0 || passphrase[0] == 0) && (decryptstr= SuperNET_decryptjson(IGUANA_CALLARGS,password,permanentfile)) != 0 ) + { + if ( (json= cJSON_Parse(decryptstr)) != 0 ) + { + memset(&M,0,sizeof(M)); + if ( (perspriv= jstr(json,"persistent_priv")) != 0 && strlen(perspriv) == sizeof(bits256)*2 ) { - data = &urlstr[totallen - datalen]; - data[-1] = 0; - //printf("post.(%s) (%c)\n",data,data[0]); - jaddstr(json,"POST",data); + M.persistent_priv = bits256_conv(perspriv); + SuperNET_setkeys(&M,0,0,0); + if ( (myinfo = SuperNET_MYINFOfind(&num,M.myaddr.persistent)) != 0 ) + { + //printf("found account.(%s) %s %llu\n",myinfo!=0?myinfo->handle:"",M.myaddr.NXTADDR,(long long)M.myaddr.nxt64bits); + return(myinfo); + } } - } else break; - } - jadd(json,"lines",array); - return(json); -} - -char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr) -{ - cJSON *tokens,*argjson,*json = 0; char urlmethod[16],*data,url[1024],*retstr,*token = 0; int32_t i,j,n; - //printf("rpcparse.(%s)\n",urlstr); - for (i=0; ihandle:"",M.myaddr.NXTADDR,(long long)M.myaddr.nxt64bits); + return(myinfo); + } + } else printf("no passphrase in (%s)\n",jprint(json,0)); + free_json(json); + } else printf("cant parse.(%s)\n",decryptstr); + free(decryptstr); } - if ( token != 0 ) - jaddistr(tokens,token); - if ( (json= SuperNET_urlconv(retbuf,bufsize,urlstr+n)) != 0 ) + return(SuperNET_MYINFO(0)); +} + +FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase) +{ + char *str,*decryptstr = 0; cJSON *argjson,*item,*walletitem; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + if ( handle != 0 && handle[0] != 0 ) + safecopy(myinfo->handle,handle,sizeof(myinfo->handle)); + else memset(myinfo->handle,0,sizeof(myinfo->handle)); + if ( password == 0 || password[0] == 0 ) + password = passphrase; + /*if ( password != 0 && password[0] != 0 ) + safecopy(myinfo->secret,password,sizeof(myinfo->secret)); + else if ( passphrase != 0 && passphrase[0] != 0 ) + safecopy(myinfo->secret,passphrase,sizeof(myinfo->secret));*/ + if ( permanentfile != 0 ) + safecopy(myinfo->permanentfile,permanentfile,sizeof(myinfo->permanentfile)); + if ( (decryptstr= SuperNET_decryptjson(IGUANA_CALLARGS,password,myinfo->permanentfile)) != 0 ) { - jadd(json,"tokens",tokens); - jaddstr(json,"urlmethod",urlmethod); - if ( (data= jstr(json,"POST")) == 0 || (argjson= cJSON_Parse(data)) == 0 ) + if ( (argjson= cJSON_Parse(decryptstr)) != 0 ) { - argjson = cJSON_CreateObject(); - if ( (n= cJSON_GetArraySize(tokens)) > 0 ) + if ( jobj(argjson,"error") == 0 ) { - jaddstr(argjson,"agent",jstri(tokens,0)); - if ( n > 1 ) - jaddstr(argjson,"method",jstri(tokens,1)); - for (i=2; iexpiration,password); + if ( myinfo->decryptstr != 0 ) + free(myinfo->decryptstr); + myinfo->decryptstr = decryptstr; + if ( (passphrase= jstr(argjson,"passphrase")) != 0 ) { - if ( i == n-1 ) - jaddstr(argjson,"data",jstri(tokens,i)); - else - { - jaddstr(argjson,jstri(tokens,i),jstri(tokens,i+1)); - i++; - } + SuperNET_setkeys(myinfo,passphrase,(int32_t)strlen(passphrase),1); + free_json(argjson); + myinfo->expiration = (uint32_t)(time(NULL) + 3600); + return(SuperNET_activehandle(IGUANA_CALLARGS)); } - } + else + { + free_json(argjson); + return(clonestr("{\"error\":\"cant find passphrase in decrypted json\"}")); + } + } else free_json(argjson); + } + else + { + free(decryptstr); + return(clonestr("{\"error\":\"cant parse decrypted json\"}")); } - retstr = SuperNET_JSON(myinfo,argjson,remoteaddr); - printf("(%s) -> (%s) postflag.%d (%s)\n",urlstr,cJSON_Print(json),*postflagp,jprint(argjson,0)); - return(retstr); } - return(clonestr("{\"error\":\"couldnt process packet\"}")); + if ( passphrase != 0 && passphrase[0] != 0 ) + { + SuperNET_setkeys(myinfo,passphrase,(int32_t)strlen(passphrase),1); + if ( myinfo->decryptstr != 0 && (argjson= cJSON_Parse(myinfo->decryptstr)) != 0 ) + { + if ( jobj(argjson,"passphrase") != 0 ) + jdelete(argjson,"passphrase"); + if ( jobj(argjson,"error") != 0 ) + jdelete(argjson,"error"); + } + else + { + char rmd160str[41],str[65]; uint8_t rmd160[20]; + item = cJSON_CreateObject(); + calc_rmd160_sha256(rmd160,myinfo->persistent_pubkey33,33); + init_hexbytes_noT(rmd160str,rmd160,20); + jaddstr(item,rmd160str,bits256_str(str,myinfo->persistent_priv)); + walletitem = cJSON_CreateObject(); + jadd(walletitem,"default",item); + argjson = cJSON_CreateObject(); + jadd(argjson,"wallet",walletitem); + myinfo->dirty = (uint32_t)time(NULL); + } + jaddstr(argjson,"passphrase",passphrase); + if ( (str= SuperNET_encryptjson(myinfo,coin,argjson,remoteaddr,password,myinfo->permanentfile,"")) != 0 ) + free(str); + myinfo->expiration = (uint32_t)(time(NULL) + 3600); + return(SuperNET_activehandle(IGUANA_CALLARGS)); + } else return(clonestr("{\"error\":\"need passphrase\"}")); + printf("logged into (%s) %s %s\n",myinfo->myaddr.NXTADDR,myinfo->myaddr.BTC,myinfo->myaddr.BTCD); + return(SuperNET_activehandle(IGUANA_CALLARGS)); } +#include "../includes/iguana_apiundefs.h" diff --git a/iguana/SuperNET.h b/deprecated/SuperNET.h similarity index 95% rename from iguana/SuperNET.h rename to deprecated/SuperNET.h index df00031d0..9ae8f48d1 100755 --- a/iguana/SuperNET.h +++ b/deprecated/SuperNET.h @@ -16,6 +16,7 @@ #ifndef INCLUDED_SUPERNET_H #define INCLUDED_SUPERNET_H +deprecated file #define SUPERNET_MAXHOPS 7 #include "../crypto777/OS_portable.h" #include "../includes/cJSON.h" @@ -75,25 +76,26 @@ struct supernet_address struct supernet_info; #include "../basilisk/basilisk.h" +#include "../gecko/gecko.h" struct supernet_info { char ipaddr[64],transport[8]; int32_t APISLEEP; int32_t iamrelay; uint32_t expiration,dirty; int32_t Debuglevel,readyflag,dead,POLLTIMEOUT; char rpcsymbol[16],LBpoint[64],PUBpoint[64]; - //int32_t pullsock,subclient,lbclient,lbserver,servicesock,pubglobal,pubrelays,numservers; bits256 privkey,persistent_priv,BTCmarkerhash,instantdex_category,pangea_category,basilisk_category; - char secret[2048],NXTAPIURL[512],permanentfile[1024]; + char secret[2048],NXTAPIURL[512],permanentfile[1024]; uint8_t persistent_pubkey33[33]; uint8_t *recvbuf[6]; struct supernet_address myaddr; int32_t LBsock,PUBsock,reqsock,subsock,networktimeout,maxdelay; uint16_t LBport,PUBport,reqport,subport,rpcport,publicRPC,argport; - //struct nn_pollfd pfd[SUPERNET_MAXAGENTS]; //struct relay_info active; struct supernet_agent agents[SUPERNET_MAXAGENTS]; queue_t acceptQ; struct basilisk_info basilisks; int32_t numagents,numexchanges,IAMRELAY; struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; struct iguana_waccount *wallet; void *ctx; char handle[1024],*decryptstr; + struct iguana_info *allcoins; int32_t allcoins_being_added,allcoins_numvirts; portable_mutex_t allcoins_mutex; + }; /*struct supernet_endpoint @@ -126,13 +128,6 @@ struct crypto777_msghdr uint8_t serialized[]; } __attribute__((packed)); -struct private_chain -{ - UT_hash_handle hh; queue_t Q; - char *(*processfunc)(struct supernet_info *myinfo,struct private_chain *cat,void *data,int32_t datalen,char *remoteaddr); - bits256 hash; struct private_chain *subchains; struct iguana_info *info; -}; - extern struct private_chain *Categories; struct category_msg { struct queueitem DL; struct tai t; uint64_t remoteipbits; int32_t len; uint8_t msg[]; }; diff --git a/SuperNET/Makefile b/deprecated/SuperNET/Makefile similarity index 100% rename from SuperNET/Makefile rename to deprecated/SuperNET/Makefile diff --git a/SuperNET/SuperNET.c b/deprecated/SuperNET/SuperNET.c similarity index 99% rename from SuperNET/SuperNET.c rename to deprecated/SuperNET/SuperNET.c index 5f807e552..800b04fe5 100755 --- a/SuperNET/SuperNET.c +++ b/deprecated/SuperNET/SuperNET.c @@ -13,7 +13,7 @@ * * ******************************************************************************/ -#include "SuperNET.h" +//#include "SuperNET.h" #define IGUANA_FORMS "[ \ \ {\"disp\":\"simple explorer\",\"agent\":\"ramchain\",\"method\":\"explore\",\"fields\":[{\"skip\":1,\"field\":\"search\",\"cols\":65,\"rows\":1}]}, \ diff --git a/SuperNET/SuperNET.h b/deprecated/SuperNET/SuperNET.h similarity index 100% rename from SuperNET/SuperNET.h rename to deprecated/SuperNET/SuperNET.h diff --git a/SuperNET/busdata777.c b/deprecated/SuperNET/busdata777.c similarity index 100% rename from SuperNET/busdata777.c rename to deprecated/SuperNET/busdata777.c diff --git a/SuperNET/console777.c b/deprecated/SuperNET/console777.c similarity index 100% rename from SuperNET/console777.c rename to deprecated/SuperNET/console777.c diff --git a/SuperNET/hostnet777.c b/deprecated/SuperNET/hostnet777.c similarity index 100% rename from SuperNET/hostnet777.c rename to deprecated/SuperNET/hostnet777.c diff --git a/SuperNET/index.html b/deprecated/SuperNET/index.html similarity index 100% rename from SuperNET/index.html rename to deprecated/SuperNET/index.html diff --git a/SuperNET/m_clean b/deprecated/SuperNET/m_clean similarity index 100% rename from SuperNET/m_clean rename to deprecated/SuperNET/m_clean diff --git a/SuperNET/m_osx b/deprecated/SuperNET/m_osx similarity index 100% rename from SuperNET/m_osx rename to deprecated/SuperNET/m_osx diff --git a/SuperNET/m_pnacl b/deprecated/SuperNET/m_pnacl similarity index 100% rename from SuperNET/m_pnacl rename to deprecated/SuperNET/m_pnacl diff --git a/SuperNET/m_unix b/deprecated/SuperNET/m_unix similarity index 100% rename from SuperNET/m_unix rename to deprecated/SuperNET/m_unix diff --git a/SuperNET/main.c b/deprecated/SuperNET/main.c similarity index 99% rename from SuperNET/main.c rename to deprecated/SuperNET/main.c index b429a8eab..57669e1eb 100755 --- a/SuperNET/main.c +++ b/deprecated/SuperNET/main.c @@ -21,7 +21,7 @@ #define CHROMEAPP_HANDLER Handler_SuperNET #include "../pnacl_main.h" -#include "SuperNET.h" +//#include "SuperNET.h" #ifndef MSG_NOSIGNAL #define MSG_NOSIGNAL 0x4000 // Do not generate SIGPIPE diff --git a/SuperNET/manifest.json b/deprecated/SuperNET/manifest.json similarity index 100% rename from SuperNET/manifest.json rename to deprecated/SuperNET/manifest.json diff --git a/SuperNET/relays777.c b/deprecated/SuperNET/relays777.c similarity index 100% rename from SuperNET/relays777.c rename to deprecated/SuperNET/relays777.c diff --git a/SuperNET/system777.c b/deprecated/SuperNET/system777.c similarity index 100% rename from SuperNET/system777.c rename to deprecated/SuperNET/system777.c diff --git a/SuperNET/teleport777.c b/deprecated/SuperNET/teleport777.c similarity index 100% rename from SuperNET/teleport777.c rename to deprecated/SuperNET/teleport777.c diff --git a/SuperNET/tools/common.mk b/deprecated/SuperNET/tools/common.mk similarity index 100% rename from SuperNET/tools/common.mk rename to deprecated/SuperNET/tools/common.mk diff --git a/SuperNET/tools/httpd.py b/deprecated/SuperNET/tools/httpd.py similarity index 100% rename from SuperNET/tools/httpd.py rename to deprecated/SuperNET/tools/httpd.py diff --git a/deprecated/SuperNET3.c b/deprecated/SuperNET3.c new file mode 100755 index 000000000..ded022edf --- /dev/null +++ b/deprecated/SuperNET3.c @@ -0,0 +1,507 @@ +/****************************************************************************** + * Copyright © 2014-2015 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include "../crypto777/OS_portable.h" +#include "SuperNET.h" + +void SuperNET_rpcloop(void *args) +{ + struct supernet_info *myinfo = args; + int32_t recvlen,bindsock,postflag,sock,remains,jsonflag,numsent,len; socklen_t clilen; + char remoteaddr[64],jsonbuf[8192],*buf,*retstr,*space;//,*retbuf; ,n,i,m + struct sockaddr_in cli_addr; uint32_t ipbits,i; uint16_t port; + int32_t size = 1024 * 1024 * 2; + port = SUPERNET_PORT; + bindsock = iguana_socket(1,"127.0.0.1",port); + printf("SuperNET_rpcloop 127.0.0.1:%d bind sock.%d\n",port,bindsock); + space = calloc(1,size); + while ( bindsock >= 0 ) + { + clilen = sizeof(cli_addr); + //printf("ACCEPT (%s:%d) on sock.%d\n","127.0.0.1",port,bindsock); + sock = accept(bindsock,(struct sockaddr *)&cli_addr,&clilen); + if ( sock < 0 ) + { + //printf("iguana_rpcloop ERROR on accept usock.%d\n",sock); + continue; + } + memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits)); + expand_ipbits(remoteaddr,ipbits); + memset(jsonbuf,0,sizeof(jsonbuf)); + remains = (int32_t)(sizeof(jsonbuf) - 1); + buf = jsonbuf; + recvlen = 0; + retstr = 0; + while ( remains > 0 ) + { + if ( (len= (int32_t)recv(sock,buf,remains,0)) < 0 ) + { + if ( errno == EAGAIN ) + { + printf("EAGAIN for len %d, remains.%d\n",len,remains); + usleep(10000); + } + break; + } + else + { + if ( len > 0 ) + { + remains -= len; + recvlen += len; + buf = &buf[len]; + retstr = SuperNET_rpcparse(myinfo,space,size,&jsonflag,&postflag,jsonbuf,remoteaddr); + break; + } else usleep(10000); + } + } + if ( retstr != 0 ) + { + i = 0; + if ( postflag == 0 && jsonflag == 0 ) + retstr = SuperNET_htmlresponse(space,size,&remains,1,retstr,1); + else remains = (int32_t)strlen(retstr); + printf("RETBUF.(%s)\n",retstr); + while ( remains > 0 ) + { + if ( (numsent= (int32_t)send(sock,&retstr[i],remains,MSG_NOSIGNAL)) < 0 ) + { + if ( errno != EAGAIN && errno != EWOULDBLOCK ) + { + //printf("%s: %s numsent.%d vs remains.%d len.%d errno.%d (%s) usock.%d\n",retstr,ipaddr,numsent,remains,recvlen,errno,strerror(errno),sock); + break; + } + } + else if ( remains > 0 ) + { + remains -= numsent; + i += numsent; + if ( remains > 0 ) + printf("iguana sent.%d remains.%d of len.%d\n",numsent,remains,recvlen); + } + } + if ( retstr != space ) + free(retstr); + } + //printf("done response sock.%d\n",sock); + closesocket(sock); + } +} +/* +struct endpoint find_epbits(struct relay_info *list,uint32_t ipbits,uint16_t port,int32_t type) +{ + int32_t i; struct endpoint epbits; + memset(&epbits,0,sizeof(epbits)); + if ( list != 0 && list->num > 0 ) + { + if ( type >= 0 ) + type = nn_portoffset(type); + for (i=0; inum&&i<(int32_t)(sizeof(list->connections)/sizeof(*list->connections)); i++) + if ( list->connections[i].ipbits == ipbits && (port == 0 || port == list->connections[i].port) && (type < 0 || type == list->connections[i].nn) ) + return(list->connections[i]); + } + return(epbits); +} + +int32_t add_relay(struct relay_info *list,struct endpoint epbits) +{ + list->connections[list->num % (sizeof(list->connections)/sizeof(*list->connections))] = epbits, list->num++; + if ( list->num > (sizeof(list->connections)/sizeof(*list->connections)) ) + printf("add_relay warning num.%d > %ld\n",list->num,(long)(sizeof(list->connections)/sizeof(*list->connections))); + return(list->num); +} + +int32_t nn_add_lbservers(struct supernet_info *myinfo,uint16_t port,uint16_t globalport,uint16_t relaysport,int32_t priority,int32_t sock,char servers[][MAX_SERVERNAME],int32_t num) +{ + int32_t i; char endpoint[512],pubendpoint[512]; struct endpoint epbits; uint32_t ipbits; + if ( num > 0 && servers != 0 && nn_setsockopt(sock,NN_SOL_SOCKET,NN_SNDPRIO,&priority,sizeof(priority)) >= 0 ) + { + for (i=0; i= 0 ) + { + printf("+R%s ",endpoint); + add_relay(&myinfo->active,epbits); + } + if ( myinfo->subclient >= 0 ) + { + if ( myinfo->iamrelay != 0 ) + { + epbits = calc_epbits("tcp",ipbits,relaysport,NN_PUB); + expand_epbits(pubendpoint,epbits); + if ( nn_connect(myinfo->subclient,pubendpoint) >= 0 ) + printf("+P%s ",pubendpoint); + } + epbits = calc_epbits("tcp",ipbits,globalport,NN_PUB); + expand_epbits(pubendpoint,epbits); + if ( nn_connect(myinfo->subclient,pubendpoint) >= 0 ) + printf("+P%s ",pubendpoint); + } + } + } + printf("added priority.%d\n",priority); + priority++; + } else printf("error setting priority.%d (%s)\n",priority,nn_errstr()); + return(priority); +} + +int32_t _lb_socket(struct supernet_info *myinfo,uint16_t port,uint16_t globalport,uint16_t relaysport,int32_t maxmillis,char servers[][MAX_SERVERNAME],int32_t num,char backups[][MAX_SERVERNAME],int32_t numbacks,char failsafes[][MAX_SERVERNAME],int32_t numfailsafes) +{ + int32_t lbsock,timeout,retrymillis,priority = 1; + if ( (lbsock= nn_socket(AF_SP,NN_REQ)) >= 0 ) + { + retrymillis = (maxmillis / 30) + 1; + printf("!!!!!!!!!!!! lbsock.%d !!!!!!!!!!!\n",lbsock); + if ( nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_RECONNECT_IVL,&retrymillis,sizeof(retrymillis)) < 0 ) + printf("error setting NN_REQ NN_RECONNECT_IVL_MAX socket %s\n",nn_errstr()); + else if ( nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_RECONNECT_IVL_MAX,&maxmillis,sizeof(maxmillis)) < 0 ) + fprintf(stderr,"error setting NN_REQ NN_RECONNECT_IVL_MAX socket %s\n",nn_errstr()); + timeout = SUPERNET_NETWORKTIMEOUT; + if ( 1 && nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)) < 0 ) + printf("error setting NN_SOL_SOCKET NN_RCVTIMEO socket %s\n",nn_errstr()); + timeout = 100; + if ( 1 && nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)) < 0 ) + printf("error setting NN_SOL_SOCKET NN_SNDTIMEO socket %s\n",nn_errstr()); + if ( num > 0 ) + priority = nn_add_lbservers(myinfo,port,globalport,relaysport,priority,lbsock,servers,num); + if ( numbacks > 0 ) + priority = nn_add_lbservers(myinfo,port,globalport,relaysport,priority,lbsock,backups,numbacks); + if ( numfailsafes > 0 ) + priority = nn_add_lbservers(myinfo,port,globalport,relaysport,priority,lbsock,failsafes,numfailsafes); + } else printf("error getting req socket %s\n",nn_errstr()); + //printf("myinfo->lb.num %d\n",myinfo->lb.num); + return(lbsock); +} + +int32_t nn_lbsocket(struct supernet_info *myinfo,int32_t maxmillis,int32_t port,uint16_t globalport,uint16_t relaysport) +{ + char Cservers[32][MAX_SERVERNAME],Bservers[32][MAX_SERVERNAME],failsafes[4][MAX_SERVERNAME]; + int32_t n,m,lbsock,numfailsafes = 0; + printf("redo lbsocket()\n"), exit(-1); + //strcpy(failsafes[numfailsafes++],"5.9.56.103"); + //strcpy(failsafes[numfailsafes++],"5.9.102.210"); + // n = crackfoo_servers(Cservers,sizeof(Cservers)/sizeof(*Cservers),port); + // m = badass_servers(Bservers,sizeof(Bservers)/sizeof(*Bservers),port); + lbsock = _lb_socket(myinfo,port,globalport,relaysport,maxmillis,Bservers,m,Cservers,n*0,failsafes,numfailsafes); + return(lbsock); +} + +void add_standard_fields(char *request) +{ + cJSON *json; uint64_t tag; + if ( (json= cJSON_Parse(request)) != 0 ) + { + if ( get_API_nxt64bits(cJSON_GetObjectItem(json,"NXT")) == 0 ) + { + randombytes((void *)&tag,sizeof(tag)); + sprintf(request + strlen(request) - 1,",\"NXT\":\"%s\",\"tag\":\"%llu\"}",myinfo->NXTADDR,(long long)tag); + if ( myinfo->iamrelay != 0 && (myinfo->hostname[0] != 0 || myinfo->ipaddr[0] != 0) ) + sprintf(request + strlen(request) - 1,",\"iamrelay\":\"%s\"}",myinfo->hostname[0]!=0?myinfo->hostname:myinfo->myipaddr); + } + free_json(json); + } +} + +char *nn_loadbalanced(struct supernet_info *myinfo,uint8_t *data,int32_t len) +{ + char *msg,*jsonstr = 0; + int32_t sendlen,i,lbsock,recvlen = 0; + if ( (lbsock= myinfo->lbclient) < 0 ) + return(clonestr("{\"error\":\"invalid load balanced socket\"}")); + for (i=0; i<10; i++) + if ( (nn_socket_status(lbsock,1) & NN_POLLOUT) != 0 ) + break; + if ( myinfo->Debuglevel > 2 ) + printf("sock.%d NN_LBSEND.(%s)\n",lbsock,data); + //fprintf(stderr,"send to network\n"); + if ( (sendlen= nn_send(lbsock,data,len,0)) == len ) + { + for (i=0; i<10; i++) + if ( (nn_socket_status(lbsock,1) & NN_POLLIN) != 0 ) + break; + if ( (recvlen= nn_recv(lbsock,&msg,NN_MSG,0)) > 0 ) + { + if ( myinfo->Debuglevel > 2 ) + printf("LBRECV.(%s)\n",msg); + jsonstr = clonestr((char *)msg); + nn_freemsg(msg); + } + else + { + printf("nn_loadbalanced got recvlen.%d %s\n",recvlen,nn_errstr()); + jsonstr = clonestr("{\"error\":\"lb recv error, probably timeout\"}"); + } + } else printf("got sendlen.%d instead of %d %s\n",sendlen,len,nn_errstr()), jsonstr = clonestr("{\"error\":\"lb send error\"}"); + return(jsonstr); +} + +cJSON *relay_json(struct relay_info *list) +{ + cJSON *json,*array; char endpoint[512]; int32_t i; + if ( list == 0 || list->num == 0 ) + return(0); + array = cJSON_CreateArray(); + for (i=0; inum&&i<(int32_t)(sizeof(list->connections)/sizeof(*list->connections)); i++) + { + expand_epbits(endpoint,list->connections[i]); + jaddistr(array,endpoint); + } + json = cJSON_CreateObject(); + jadd(json,"endpoints",array); + //cJSON_AddItemToObject(json,"type",cJSON_CreateString(nn_typestr(list->mytype))); + //cJSON_AddItemToObject(json,"dest",cJSON_CreateString(nn_typestr(list->desttype))); + jaddnum(json,"total",list->num); + return(json); +} + +char *relays_jsonstr(struct supernet_info *myinfo,char *jsonstr,cJSON *argjson) +{ + cJSON *json; + if ( myinfo->iamrelay != 0 && myinfo->ipaddr[0] != 0 ) + { + json = cJSON_CreateObject(); + jaddstr(json,"relay",myinfo->ipaddr); + if ( myinfo->active.num > 0 ) + jadd(json,"relays",relay_json(&myinfo->active)); + return(jprint(json,1)); + } + else return(clonestr("{\"error\":\"get relay list from relay\"}")); +} + +int32_t init_SUPERNET_pullsock(struct supernet_info *myinfo,int32_t sendtimeout,int32_t recvtimeout) +{ + char bindaddr[64],*transportstr; int32_t iter; + myinfo->pullsock = -1; + if ( (myinfo->pullsock= nn_socket(AF_SP,NN_PULL)) < 0 ) + { + printf("error creating pullsock %s\n",nn_strerror(nn_errno())); + return(-1); + } + printf("got pullsock.%d\n",myinfo->pullsock); + if ( nn_settimeouts(myinfo->pullsock,sendtimeout,recvtimeout) < 0 ) + { + printf("error settime pullsock timeouts %s\n",nn_strerror(nn_errno())); + return(-1); + } + printf("PULLsock.%d\n",myinfo->pullsock); + for (iter=0; iter<2; iter++) + { + transportstr = (iter == 0) ? "ipc" : "inproc"; + sprintf(bindaddr,"%s://SuperNET.agents",transportstr); + if ( nn_bind(myinfo->pullsock,bindaddr) < 0 ) + { + printf("error binding pullsock to (%s) %s\n",bindaddr,nn_strerror(nn_errno())); + return(-1); + } + } + return(0); +} + +void busdata_init(struct supernet_info *myinfo,int32_t sendtimeout,int32_t recvtimeout,int32_t firstiter) +{ + char endpoint[512]; int32_t i; + myinfo->servicesock = myinfo->pubglobal = myinfo->pubrelays = myinfo->lbserver = -1; + endpoint[0] = 0; + if ( (myinfo->subclient= nn_createsocket(myinfo,endpoint,0,"NN_SUB",NN_SUB,0,sendtimeout,recvtimeout)) >= 0 ) + { + myinfo->pfd[myinfo->numservers++].fd = myinfo->subclient, printf("numservers.%d\n",myinfo->numservers); + nn_setsockopt(myinfo->subclient,NN_SUB,NN_SUB_SUBSCRIBE,"",0); + } else printf("error creating subclient\n"); + myinfo->lbclient = nn_lbsocket(myinfo,SUPERNET_NETWORKTIMEOUT,SUPERNET_PORT + LB_OFFSET,myinfo->port + PUBGLOBALS_OFFSET,myinfo->port + PUBRELAYS_OFFSET); + printf("LBclient.%d port.%d\n",myinfo->lbclient,SUPERNET_PORT + LB_OFFSET); + sprintf(endpoint,"%s://%s:%u",myinfo->transport,myinfo->ipaddr,myinfo->serviceport); + if ( (myinfo->servicesock= nn_createsocket(myinfo,endpoint,1,"NN_REP",NN_REP,myinfo->serviceport,sendtimeout,recvtimeout)) >= 0 ) + myinfo->pfd[myinfo->numservers++].fd = myinfo->servicesock, printf("numservers.%d\n",myinfo->numservers); + else printf("error creating servicesock\n"); + for (i=0; inumservers; i++) + myinfo->pfd[i].events = NN_POLLIN | NN_POLLOUT; + printf("myinfo->iamrelay %d, numservers.%d ipaddr.(%s://%s) port.%d serviceport.%d\n",myinfo->iamrelay,myinfo->numservers,myinfo->transport,myinfo->ipaddr,myinfo->port,myinfo->serviceport); +} + +void SuperNET_init(struct supernet_info *myinfo,char *jsonstr) +{ + char *str; + if ( jsonstr != 0 && (str= SuperNET_JSON(myinfo,jsonstr)) != 0 ) + free(str); + busdata_init(myinfo,10,1,0); + init_SUPERNET_pullsock(myinfo,10,10); +}*/ + +int32_t Supernet_lineparse(char *key,int32_t keymax,char *value,int32_t valuemax,char *src) +{ + int32_t a,b,c,n = 0; + key[0] = value[0] = 0; + while ( (c= src[n]) == ' ' || c == '\t' || c == '\n' || c == '\t' ) + n++; + while ( (c= src[n]) != ':' && c != 0 ) + { + *key++ = c; + if ( ++n >= keymax-1 ) + { + *key = 0; + printf("lineparse overflow key.(%s)\n",src); + return(-1); + } + } + *key = 0; + if ( src[n] != ':' ) + return(n); + n++; + while ( (c= src[n]) == ' ' || c == '\t' ) + n++; + while ( (c= src[n]) != 0 && c != '\r' && c != '\n' ) + { + if ( c == '%' && (a= src[n+1]) != 0 && (b= src[n+2]) != 0 ) + c = ((unhex(a) << 4) | unhex(b)), n += 2; + *value++ = c; + n++; + if ( n >= valuemax-1 ) + { + *value = 0; + printf("lineparse overflow.(%s)\n",src); + return(-1); + } + } + *value = 0; + if ( src[n] != 0 ) + { + n++; + while ( (c= src[n]) == '\r' || c == '\n' ) + n++; + } + return(n); +} + +cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr) +{ + int32_t i,n,totallen,datalen,len = 0; cJSON *json,*array; char key[8192],*data; + json = cJSON_CreateObject(); + array = cJSON_CreateArray(); + totallen = (int32_t)strlen(urlstr); + while ( 1 ) + { + for (i=len; urlstr[i]!=0; i++) + if ( urlstr[i] == '\r' || urlstr[i] == '\n' ) + break; + if ( i == len && (urlstr[len] == '\r' || urlstr[len] == '\n') ) + { + len++; + continue; + } + urlstr[i] = 0; + if ( (n= Supernet_lineparse(key,sizeof(key),value,bufsize,&urlstr[len])) > 0 ) + { + if ( value[0] != 0 ) + jaddstr(json,key,value); + else jaddistr(array,key); + len += (n + 1); + if ( strcmp(key,"Content-Length") == 0 && (datalen= atoi(value)) > 0 ) + { + data = &urlstr[totallen - datalen]; + data[-1] = 0; + //printf("post.(%s) (%c)\n",data,data[0]); + jaddstr(json,"POST",data); + } + } else break; + } + jadd(json,"lines",array); + return(json); +} + +char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr) +{ + cJSON *tokens,*argjson,*json = 0; char urlmethod[16],*data,url[1024],*retstr,*token = 0; int32_t i,j,n; + //printf("rpcparse.(%s)\n",urlstr); + for (i=0; i 0 ) + { + jaddstr(argjson,"agent",jstri(tokens,0)); + if ( n > 1 ) + jaddstr(argjson,"method",jstri(tokens,1)); + for (i=2; i (%s) postflag.%d (%s)\n",urlstr,cJSON_Print(json),*postflagp,jprint(argjson,0)); + return(retstr); + } + return(clonestr("{\"error\":\"couldnt process packet\"}")); +} + diff --git a/iguana/SuperNET_category.c b/deprecated/SuperNET_category.c similarity index 90% rename from iguana/SuperNET_category.c rename to deprecated/SuperNET_category.c index 05293a94a..6ba767ef9 100755 --- a/iguana/SuperNET_category.c +++ b/deprecated/SuperNET_category.c @@ -38,9 +38,9 @@ bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory) return(categoryhash); } -struct private_chain *category_find(bits256 categoryhash,bits256 subhash) +struct gecko_chain *category_find(bits256 categoryhash,bits256 subhash) { - struct private_chain *cat=0,*sub = 0; bits256 hash; + struct gecko_chain *cat=0,*sub = 0; bits256 hash; HASH_FIND(hh,Categories,categoryhash.bytes,sizeof(categoryhash),cat); if ( cat != 0 ) { @@ -56,9 +56,9 @@ struct private_chain *category_find(bits256 categoryhash,bits256 subhash) return(0); } -queue_t *category_Q(struct private_chain **catptrp,bits256 categoryhash,bits256 subhash) +queue_t *category_Q(struct gecko_chain **catptrp,bits256 categoryhash,bits256 subhash) { - struct private_chain *cat; + struct gecko_chain *cat; *catptrp = 0; if ( (cat= category_find(categoryhash,subhash)) != 0 ) { @@ -68,17 +68,17 @@ queue_t *category_Q(struct private_chain **catptrp,bits256 categoryhash,bits256 else return(0); } -void *private_chain(bits256 categoryhash,bits256 subhash) +/*void *gecko_chain(bits256 categoryhash,bits256 subhash) { - struct private_chain *cat; + struct gecko_chain *cat; if ( (cat= category_find(categoryhash,subhash)) != 0 ) return(cat->info); else return(0); -} +}*/ -void *private_chainset(bits256 categoryhash,bits256 subhash,void *info) +void *gecko_chainset(bits256 categoryhash,bits256 subhash,void *info) { - struct private_chain *cat; + struct gecko_chain *cat; if ( (cat= category_find(categoryhash,subhash)) != 0 ) { cat->info = info; @@ -87,9 +87,10 @@ void *private_chainset(bits256 categoryhash,bits256 subhash,void *info) return(0); } -struct private_chain *category_processfunc(bits256 categoryhash,bits256 subhash,char *(*process_func)(struct supernet_info *myinfo,struct private_chain *cat,void *data,int32_t datalen,char *remoteaddr)) +#ifdef later +struct gecko_chain *category_processfunc(bits256 categoryhash,bits256 subhash,char *(*process_func)(struct supernet_info *myinfo,struct gecko_chain *cat,void *data,int32_t datalen,char *remoteaddr)) { - struct private_chain *cat; + struct gecko_chain *cat; if ( (cat= category_find(categoryhash,subhash)) != 0 ) { cat->processfunc = process_func; @@ -98,7 +99,7 @@ struct private_chain *category_processfunc(bits256 categoryhash,bits256 subhash, return(0); } -struct category_msg *category_gethexmsg(struct supernet_info *myinfo,struct private_chain **catptrp,bits256 categoryhash,bits256 subhash) +struct category_msg *category_gethexmsg(struct supernet_info *myinfo,struct gecko_chain **catptrp,bits256 categoryhash,bits256 subhash) { queue_t *Q; //char str[65]; printf("getmsg.(%s) %llx\n",bits256_str(str,categoryhash),(long long)subhash.txid); @@ -109,7 +110,7 @@ struct category_msg *category_gethexmsg(struct supernet_info *myinfo,struct priv void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr) { - int32_t len; struct category_msg *m; queue_t *Q = 0; struct private_chain *cat; + int32_t len; struct category_msg *m; queue_t *Q = 0; struct gecko_chain *cat; if ( (Q= category_Q(&cat,categoryhash,subhash)) != 0 ) { len = (int32_t)strlen(hexmsg) >> 1; @@ -127,7 +128,7 @@ void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits2 void *category_subscribe(struct supernet_info *myinfo,bits256 chainhash,bits256 keyhash) { - struct private_chain *chain,*subchain; bits256 hash; + struct gecko_chain *chain,*subchain; bits256 hash; HASH_FIND(hh,Categories,chainhash.bytes,sizeof(chainhash),chain); if ( chain == 0 ) { @@ -220,5 +221,6 @@ void category_init(struct supernet_info *myinfo) myinfo->basilisk_category = baseliskhash; category_subscribe(myinfo,baseliskhash,GENESIS_PUBKEY); - basilisks_init(myinfo); -} \ No newline at end of file +} + +#endif diff --git a/iguana/SuperNET_hexmsg.c b/deprecated/SuperNET_hexmsg.c similarity index 99% rename from iguana/SuperNET_hexmsg.c rename to deprecated/SuperNET_hexmsg.c index 0fcdb7867..5d3dc7bd9 100755 --- a/iguana/SuperNET_hexmsg.c +++ b/deprecated/SuperNET_hexmsg.c @@ -15,6 +15,7 @@ #include "iguana777.h" +#ifdef oldway int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,int32_t addflag) { static int lastpurge; static uint64_t Packetcache[1024]; @@ -116,7 +117,6 @@ void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *j } } -#ifdef later int32_t category_default_blockhash(struct category_chain *catchain,void *blockhashp,void *data,int32_t datalen) { bits256 hash; @@ -276,7 +276,6 @@ struct category_chain *category_chain_functions(struct supernet_info *myinfo,bit } return(0); } -#endif struct crypto777_msghdr *crypto777_msgcreate(struct supernet_info *myinfo,struct crypto777_msghdr *msg,int32_t datalen) { @@ -369,6 +368,7 @@ char *crypto777_hexmsg(struct supernet_info *myinfo,void *ptr,int32_t len,char * } return(clonestr("{\"result\":\"test packet\"}")); } +#endif /* Consensus rules: diff --git a/_API.md b/deprecated/_API.md similarity index 100% rename from _API.md rename to deprecated/_API.md diff --git a/field.html b/deprecated/field.html similarity index 100% rename from field.html rename to deprecated/field.html diff --git a/footer.html b/deprecated/footer.html similarity index 100% rename from footer.html rename to deprecated/footer.html diff --git a/formfooter.html b/deprecated/formfooter.html similarity index 100% rename from formfooter.html rename to deprecated/formfooter.html diff --git a/formheader.html b/deprecated/formheader.html similarity index 100% rename from formheader.html rename to deprecated/formheader.html diff --git a/header.html b/deprecated/header.html similarity index 100% rename from header.html rename to deprecated/header.html diff --git a/index.html b/deprecated/index.html similarity index 100% rename from index.html rename to deprecated/index.html diff --git a/index7778.html b/deprecated/index7778.html similarity index 100% rename from index7778.html rename to deprecated/index7778.html diff --git a/js/api.js b/deprecated/js/api.js similarity index 100% rename from js/api.js rename to deprecated/js/api.js diff --git a/js/background.js b/deprecated/js/background.js similarity index 100% rename from js/background.js rename to deprecated/js/background.js diff --git a/js/bootstrap.js b/deprecated/js/bootstrap.js similarity index 100% rename from js/bootstrap.js rename to deprecated/js/bootstrap.js diff --git a/js/common.js b/deprecated/js/common.js similarity index 100% rename from js/common.js rename to deprecated/js/common.js diff --git a/js/example.js b/deprecated/js/example.js similarity index 100% rename from js/example.js rename to deprecated/js/example.js diff --git a/js/form.js b/deprecated/js/form.js similarity index 100% rename from js/form.js rename to deprecated/js/form.js diff --git a/js/jquery-2.1.4.min.js b/deprecated/js/jquery-2.1.4.min.js similarity index 100% rename from js/jquery-2.1.4.min.js rename to deprecated/js/jquery-2.1.4.min.js diff --git a/js/methods.js b/deprecated/js/methods.js similarity index 100% rename from js/methods.js rename to deprecated/js/methods.js diff --git a/js/old_js/test.js b/deprecated/js/old_js/test.js similarity index 100% rename from js/old_js/test.js rename to deprecated/js/old_js/test.js diff --git a/js/settings.js b/deprecated/js/settings.js similarity index 100% rename from js/settings.js rename to deprecated/js/settings.js diff --git a/js/sites.js b/deprecated/js/sites.js similarity index 100% rename from js/sites.js rename to deprecated/js/sites.js diff --git a/js/util.js b/deprecated/js/util.js similarity index 100% rename from js/util.js rename to deprecated/js/util.js diff --git a/deprecated/obsolete.h b/deprecated/obsolete.h index 76c60b2d6..e261d6016 100755 --- a/deprecated/obsolete.h +++ b/deprecated/obsolete.h @@ -16036,7 +16036,7 @@ len = 0; decode_hex(hash2.bytes,sizeof(hash2),txidstr); if ( (tx= iguana_txidfind(coin,&height,&T,hash2)) != 0 ) { - if ( (len= iguana_txbytes(coin,coin->blockspace,sizeof(coin->blockspace),&checktxid,tx,height,0,0)) > 0 ) + if ( (len= iguana_txbytes(coin,coin->blockspace,coin->blockspacesize,&checktxid,tx,height,0,0)) > 0 ) { txbytes = mycalloc('x',1,len*2+1); init_hexbytes_noT(txbytes,coin->blockspace,len*2+1); @@ -16554,7 +16554,7 @@ len = 0; jaddstr(array,waddr->coinaddr); total = 0; n = 0; - iguana_pkhasharray(myinfo,coin,0,coin->minconfirms,coin->longestchain,&total,0,coin->bundlescount,waddr->rmd160,waddr->coinaddr,waddr->pubkey,coin->blocks.hwmchain.height - coin->minconfirms,(uint64_t *)coin->blockspace,&n,(int32_t)(sizeof(coin->blockspace)/sizeof(*waddr->unspents))-1000); + iguana_pkhasharray(myinfo,coin,0,coin->minconfirms,coin->longestchain,&total,0,coin->bundlescount,waddr->rmd160,waddr->coinaddr,waddr->pubkey,coin->blocks.hwmchain.height - coin->minconfirms,(uint64_t *)coin->blockspace,&n,(int32_t)(coin->blockspacesize/sizeof(*waddr->unspents))-1000); if ( n > 0 ) { if ( waddr->unspents == 0 || waddr->maxunspents < n ) @@ -17389,6 +17389,80 @@ len = 0; retjson = cJSON_CreateObject(); return(jprint(retjson,1)); } + /*int32_t basilisk_sendPUB(struct supernet_info *myinfo,uint32_t basilisktag,uint8_t *data,int32_t datalen) // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag) + { + int32_t i,j,r,r2,s,k,val,l,n=0; uint32_t *alreadysent; struct iguana_info *coin; struct iguana_peer *addr; + alreadysent = calloc(IGUANA_MAXPEERS * IGUANA_MAXCOINS,sizeof(*alreadysent)); + r = rand(), r2 = rand(); + for (k=0; kpeers.active[i]) != 0 && addr->ipbits != 0 && addr->usock >= 0 && addr->basilisk != 0 ) + { + for (s=0; sipbits ) + break; + if ( s == n ) + { + printf("pub (%s) addr->supernet.%u to (%s).%d\n",(char *)&data[4],addr->supernet,addr->ipaddr,addr->A.port); + if ( (val= iguana_queue_send(addr,0,&data[-sizeof(struct iguana_msghdr)],"SuperNETpub",datalen)) >= datalen ) + { + alreadysent[n++] = (uint32_t)addr->ipbits; + if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS ) + break; + } + } + } + } + if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS ) + break; + } + free(alreadysent); + return(n); + }*/ + + struct iguana_info *_iguana_coinadd(char *symbol,cJSON *argjson) + { + struct iguana_info *coin; char *privatechain; int32_t pval,i = 0; + if ( symbol == 0 ) + { + printf("_iguana_coinadd deprecated null symbol\n"); + exit(-1); + } + else + { + for (i=0; i= sizeof(Hardcoded_coins)/sizeof(*Hardcoded_coins) ) + break; + //printf("Hardcoded_coins[i][0] %s vs.(%s)\n",Hardcoded_coins[i][0],symbol); + //if ( symbol[0] == 0 ) + // getchar(); + if ( strcmp("endmarker",Hardcoded_coins[i][0]) == 0 || strcmp(symbol,Hardcoded_coins[i][0]) == 0 ) + { + if ( coin->chain == 0 ) + { + if ( i < sizeof(Hardcoded_coins)/sizeof(*Hardcoded_coins) ) + strcpy(coin->name,Hardcoded_coins[i][1]); + else if (argjson != 0 ) + { + if ( jstr(argjson,"name") != 0 ) + safecopy(coin->name,jstr(argjson,"name"),sizeof(coin->name)); + else strcpy(coin->name,symbol); + } + } + return(coin); + } + } + } + return(0); + } + #endif #endif diff --git a/pangea/Makefile b/deprecated/pangea/Makefile similarity index 100% rename from pangea/Makefile rename to deprecated/pangea/Makefile diff --git a/pangea/cards777.c b/deprecated/pangea/cards777.c similarity index 100% rename from pangea/cards777.c rename to deprecated/pangea/cards777.c diff --git a/pangea/hostnet777.c b/deprecated/pangea/hostnet777.c similarity index 100% rename from pangea/hostnet777.c rename to deprecated/pangea/hostnet777.c diff --git a/pangea/index.html b/deprecated/pangea/index.html similarity index 100% rename from pangea/index.html rename to deprecated/pangea/index.html diff --git a/pangea/m_clean b/deprecated/pangea/m_clean similarity index 100% rename from pangea/m_clean rename to deprecated/pangea/m_clean diff --git a/pangea/m_pnacl b/deprecated/pangea/m_pnacl similarity index 100% rename from pangea/m_pnacl rename to deprecated/pangea/m_pnacl diff --git a/pangea/main.c b/deprecated/pangea/main.c similarity index 100% rename from pangea/main.c rename to deprecated/pangea/main.c diff --git a/pangea/manifest.json b/deprecated/pangea/manifest.json similarity index 100% rename from pangea/manifest.json rename to deprecated/pangea/manifest.json diff --git a/pangea/pangea777.c b/deprecated/pangea/pangea777.c similarity index 100% rename from pangea/pangea777.c rename to deprecated/pangea/pangea777.c diff --git a/pangea/pangeafunds.c b/deprecated/pangea/pangeafunds.c similarity index 100% rename from pangea/pangeafunds.c rename to deprecated/pangea/pangeafunds.c diff --git a/pangea/poker.c b/deprecated/pangea/poker.c similarity index 100% rename from pangea/poker.c rename to deprecated/pangea/poker.c diff --git a/pangea/tourney777.c b/deprecated/pangea/tourney777.c similarity index 100% rename from pangea/tourney777.c rename to deprecated/pangea/tourney777.c diff --git a/peggy/Makefile b/deprecated/peggy/Makefile similarity index 100% rename from peggy/Makefile rename to deprecated/peggy/Makefile diff --git a/peggy/accts777.h b/deprecated/peggy/accts777.h similarity index 100% rename from peggy/accts777.h rename to deprecated/peggy/accts777.h diff --git a/peggy/index.html b/deprecated/peggy/index.html similarity index 100% rename from peggy/index.html rename to deprecated/peggy/index.html diff --git a/peggy/m_clean b/deprecated/peggy/m_clean similarity index 100% rename from peggy/m_clean rename to deprecated/peggy/m_clean diff --git a/peggy/m_pnacl b/deprecated/peggy/m_pnacl similarity index 100% rename from peggy/m_pnacl rename to deprecated/peggy/m_pnacl diff --git a/peggy/main.c b/deprecated/peggy/main.c similarity index 100% rename from peggy/main.c rename to deprecated/peggy/main.c diff --git a/peggy/manifest.json b/deprecated/peggy/manifest.json similarity index 100% rename from peggy/manifest.json rename to deprecated/peggy/manifest.json diff --git a/peggy/opreturn777.h b/deprecated/peggy/opreturn777.h similarity index 100% rename from peggy/opreturn777.h rename to deprecated/peggy/opreturn777.h diff --git a/peggy/peggy777.c b/deprecated/peggy/peggy777.c similarity index 100% rename from peggy/peggy777.c rename to deprecated/peggy/peggy777.c diff --git a/peggy/peggytx.h b/deprecated/peggy/peggytx.h similarity index 100% rename from peggy/peggytx.h rename to deprecated/peggy/peggytx.h diff --git a/peggy/serdes777.h b/deprecated/peggy/serdes777.h similarity index 100% rename from peggy/serdes777.h rename to deprecated/peggy/serdes777.h diff --git a/peggy/txind777.h b/deprecated/peggy/txind777.h similarity index 100% rename from peggy/txind777.h rename to deprecated/peggy/txind777.h diff --git a/prices/Makefile b/deprecated/prices/Makefile similarity index 100% rename from prices/Makefile rename to deprecated/prices/Makefile diff --git a/prices/index.html b/deprecated/prices/index.html similarity index 100% rename from prices/index.html rename to deprecated/prices/index.html diff --git a/prices/m_clean b/deprecated/prices/m_clean similarity index 100% rename from prices/m_clean rename to deprecated/prices/m_clean diff --git a/prices/m_pnacl b/deprecated/prices/m_pnacl similarity index 100% rename from prices/m_pnacl rename to deprecated/prices/m_pnacl diff --git a/prices/main.c b/deprecated/prices/main.c similarity index 100% rename from prices/main.c rename to deprecated/prices/main.c diff --git a/prices/manifest.json b/deprecated/prices/manifest.json similarity index 100% rename from prices/manifest.json rename to deprecated/prices/manifest.json diff --git a/prices/prices777.c b/deprecated/prices/prices777.c similarity index 100% rename from prices/prices777.c rename to deprecated/prices/prices777.c diff --git a/prices/quotes777.c b/deprecated/prices/quotes777.c similarity index 100% rename from prices/quotes777.c rename to deprecated/prices/quotes777.c diff --git a/tradebots/Makefile b/deprecated/tradebots/Makefile similarity index 100% rename from tradebots/Makefile rename to deprecated/tradebots/Makefile diff --git a/tradebots/index.html b/deprecated/tradebots/index.html similarity index 100% rename from tradebots/index.html rename to deprecated/tradebots/index.html diff --git a/tradebots/m_clean b/deprecated/tradebots/m_clean similarity index 100% rename from tradebots/m_clean rename to deprecated/tradebots/m_clean diff --git a/tradebots/m_pnacl b/deprecated/tradebots/m_pnacl similarity index 100% rename from tradebots/m_pnacl rename to deprecated/tradebots/m_pnacl diff --git a/tradebots/main.c b/deprecated/tradebots/main.c similarity index 100% rename from tradebots/main.c rename to deprecated/tradebots/main.c diff --git a/tradebots/manifest.json b/deprecated/tradebots/manifest.json similarity index 100% rename from tradebots/manifest.json rename to deprecated/tradebots/manifest.json diff --git a/tradebots/tradebots.h b/deprecated/tradebots/tradebots.h similarity index 100% rename from tradebots/tradebots.h rename to deprecated/tradebots/tradebots.h diff --git a/widget/ReadMe.MD b/deprecated/widget/ReadMe.MD similarity index 100% rename from widget/ReadMe.MD rename to deprecated/widget/ReadMe.MD diff --git a/widget/index.html b/deprecated/widget/index.html similarity index 100% rename from widget/index.html rename to deprecated/widget/index.html diff --git a/widget/pasted-widget.html b/deprecated/widget/pasted-widget.html similarity index 100% rename from widget/pasted-widget.html rename to deprecated/widget/pasted-widget.html diff --git a/widget/widguana-snippet.html b/deprecated/widget/widguana-snippet.html similarity index 100% rename from widget/widguana-snippet.html rename to deprecated/widget/widguana-snippet.html diff --git a/widget/widguana.js b/deprecated/widget/widguana.js similarity index 100% rename from widget/widguana.js rename to deprecated/widget/widguana.js diff --git a/gecko/gecko.c b/gecko/gecko.c new file mode 100755 index 000000000..381fbeac4 --- /dev/null +++ b/gecko/gecko.c @@ -0,0 +1,565 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include "../iguana/iguana777.h" +#include "gecko_delayedPoW.c" +#include "gecko_miner.c" + +bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory) +{ + bits256 categoryhash; + if ( category == 0 || category[0] == 0 || strcmp(category,"broadcast") == 0 ) + categoryhash = GENESIS_PUBKEY; + else vcalc_sha256(0,categoryhash.bytes,(uint8_t *)category,(int32_t)strlen(category)); + if ( subhashp != 0 ) + { + if ( subcategory == 0 || subcategory[0] == 0 || strcmp(subcategory,"broadcast") == 0 ) + *subhashp = GENESIS_PUBKEY; + else vcalc_sha256(0,subhashp->bytes,(uint8_t *)subcategory,(int32_t)strlen(subcategory)); + } + return(categoryhash); +} + +struct gecko_chain *category_find(bits256 categoryhash,bits256 subhash) +{ + struct gecko_chain *cat=0,*sub = 0; bits256 hash; + HASH_FIND(hh,Categories,categoryhash.bytes,sizeof(categoryhash),cat); + if ( cat != 0 ) + { + if ( bits256_nonz(subhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,subhash.bytes,sizeof(subhash)) != 0 ) + { + hash = subhash; + HASH_FIND(hh,cat->subchains,hash.bytes,sizeof(hash),sub); + if ( sub != 0 ) + return(sub); + } + return(cat); + } //else printf("category_find.(%s) not found\n",bits256_str(str,categoryhash));//, getchar(); + return(0); +} + +queue_t *category_Q(struct gecko_chain **catptrp,bits256 categoryhash,bits256 subhash) +{ + struct gecko_chain *cat; + *catptrp = 0; + if ( (cat= category_find(categoryhash,subhash)) != 0 ) + { + *catptrp = cat; + return(&cat->Q); + } + else return(0); +} + +void *category_subscribe(struct supernet_info *myinfo,bits256 chainhash,bits256 keyhash) +{ + struct gecko_chain *chain,*subchain; bits256 hash; + HASH_FIND(hh,Categories,chainhash.bytes,sizeof(chainhash),chain); + if ( chain == 0 ) + { + chain = mycalloc('c',1,sizeof(*chain)); + chain->hash = hash = chainhash; + char str[65]; printf("ADD cat.(%s)\n",bits256_str(str,chainhash)); + HASH_ADD(hh,Categories,hash,sizeof(hash),chain); + } + if ( bits256_nonz(keyhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,keyhash.bytes,sizeof(keyhash)) != 0 && chain != 0 ) + { + HASH_FIND(hh,chain->subchains,keyhash.bytes,sizeof(keyhash),subchain); + if ( subchain == 0 ) + { + subchain = mycalloc('c',1,sizeof(*subchain)); + subchain->hash = hash = keyhash; + char str[65],str2[65]; printf("subadd.(%s) -> (%s)\n",bits256_str(str,keyhash),bits256_str(str2,chainhash)); + HASH_ADD(hh,chain->subchains,hash,sizeof(hash),subchain); + } + } + return(chain); +} + +struct gecko_chain *gecko_chain(struct supernet_info *myinfo,char chainname[GECKO_MAXNAMELEN],cJSON *valsobj) +{ + char *chainstr,*keystr; bits256 keyhash,chainhash; struct gecko_chain *chain; + if ( (chainstr= jstr(valsobj,"chain")) == 0 ) + return(0); + if ( (keystr= jstr(valsobj,"key")) != 0 ) + vcalc_sha256(0,keyhash.bytes,(uint8_t *)keystr,(int32_t)strlen(keystr)); + else keyhash = GENESIS_PUBKEY; + vcalc_sha256(0,chainhash.bytes,(uint8_t *)chainstr,(int32_t)strlen(chainstr)); + if ( (chain= category_subscribe(myinfo,chainhash,keyhash)) == 0 ) + return(0); + safecopy(chainname,chainstr,30), chainname[30] = 0; + if ( keystr != 0 ) + { + strcat(chainname,"."); + safecopy(chainname+strlen(chainname),keystr,GECKO_MAXNAMELEN-1-strlen(chainname)); + } + return(chain); +} + +int32_t gecko_chainvals(struct supernet_info *myinfo,char *CMD,cJSON *valsobj) +{ + struct iguana_info *virt; struct gecko_chain *chain; bits256 hash,prevhash; struct iguana_block *block; char chainname[GECKO_MAXNAMELEN]; + if ( strcmp(CMD,"SET") == 0 || strcmp(CMD,"GET") == 0 ) + { + if ( (chain= gecko_chain(myinfo,chainname,valsobj)) == 0 || (virt= chain->info) == 0 ) + clonestr("{\"error\":\"cant find gecko chain\"}"); + if ( strcmp(CMD,"SET") == 0 ) + { + hash = GENESIS_PUBKEY; + if ( jobj(valsobj,"prev") != 0 ) + { + prevhash = jbits256(valsobj,"prev"); + if ( (block= iguana_blockfind("basilisk",virt,prevhash)) == 0 ) + { + char str[65]; printf("warning couldnt find %s in %s\n",bits256_str(str,prevhash),chainname); + prevhash = virt->blocks.hwmchain.RO.hash2; + } + } else prevhash = virt->blocks.hwmchain.RO.hash2; + hash = prevhash; + if ( jobj(valsobj,"prev") != 0 ) + jdelete(valsobj,"prev"); + } + return(0); + } + return(-1); +} + +cJSON *gecko_genesisargs(char *symbol,char *chainname,char *chain,char *keystr,char *genesishash,char *genesisblock,char *magicstr,uint16_t port,uint16_t blocktime,char *nbitstr,char *pubval,char *p2shval,char *wifval,uint32_t isPoS) +{ + int32_t timespan,targetspacing; cJSON *argvals = cJSON_CreateObject(); + if ( genesishash != 0 && genesishash[0] != 0 ) + jaddstr(argvals,"genesishash",genesishash); + if ( genesisblock != 0 && genesisblock[0] != 0 ) + jaddstr(argvals,"genesisblock",genesisblock); + jaddstr(argvals,"netmagic",magicstr); + jaddstr(argvals,"symbol",symbol); + jaddstr(argvals,"name",chainname); + if ( pubval == 0 || is_hexstr(pubval,0) != 2 ) + pubval = "00"; + jaddstr(argvals,"pubval",pubval); + if ( p2shval == 0 || is_hexstr(p2shval,0) != 2 ) + p2shval = "05"; + jaddstr(argvals,"p2shval",p2shval); + if ( wifval == 0 || is_hexstr(wifval,0) != 2 ) + wifval = "80"; + jaddstr(argvals,"wifval",wifval); + if ( nbitstr == 0 || nbitstr[0] == 0 ) + nbitstr = GECKO_DEFAULTDIFFSTR; + jaddstr(argvals,"nbits",nbitstr); + jaddstr(argvals,"chain",chain); + if ( keystr != 0 ) + jaddstr(argvals,"key",keystr); + jaddnum(argvals,"isPoS",isPoS); + //printf("argvals isPoS.%d\n",isPoS); + if ( port == 0 ) + { + jaddstr(argvals,"geckochain",chainname); + jaddnum(argvals,"services",128); + } + else + { + jaddnum(argvals,"services",129); + jaddnum(argvals,"portp2p",port); + jaddnum(argvals,"blocktime",blocktime); + if ( blocktime == 0xffff ) + targetspacing = 24 * 60 * 60; // one day + else targetspacing = 60; // one minute + jaddnum(argvals,"targetspacing",targetspacing); + if ( (timespan= sqrt(604800 / targetspacing)) < 7 ) + timespan = 7; + jaddnum(argvals,"targettimespan",targetspacing * timespan); + } + return(argvals); +} + +cJSON *gecko_genesisjson(struct supernet_info *myinfo,struct iguana_info *btcd,int32_t isPoS,char *symbol,char *chainname,cJSON *valsobj,char *magicstr) +{ + char str2[64],hashstr[65],argbuf[1024],*pubstr,*p2shstr,*wifvalstr,*nbitstr,*blockstr; uint8_t buf[4]; int32_t i; uint32_t nBits; struct iguana_block genesis; uint16_t blocktime; + if ( (nbitstr= jstr(valsobj,"nbits")) == 0 ) + { + nBits = GECKO_DEFAULTDIFF; + nbitstr = GECKO_DEFAULTDIFFSTR; + } + else + { + for (i=0; i<4; i++) + decode_hex(&buf[3-i],1,&nbitstr[i*2]); + memcpy(&nBits,buf,sizeof(nBits)); + } + if ( (blocktime= juint(valsobj,"blocktime")) == 0 ) + blocktime = 60; + if ( (pubstr= jstr(valsobj,"pubval")) == 0 ) + pubstr = "00"; + if ( (p2shstr= jstr(valsobj,"p2shval")) == 0 ) + p2shstr = "05"; + if ( (wifvalstr= jstr(valsobj,"wifval")) == 0 ) + wifvalstr = "80"; + printf("json netmagic.%s\n",magicstr); + memset(&genesis,0,sizeof(genesis)); + genesis.RO.version = GECKO_DEFAULTVERSION; + genesis.RO.bits = nBits; + if ( (blockstr= gecko_createblock(myinfo,btcd,isPoS,&genesis,symbol,0,0,0,10000)) != 0 ) + { + bits256_str(hashstr,genesis.RO.hash2); + sprintf(argbuf,"{\"isPoS\":%d,\"name\":\"%s\",\"symbol\":\"%s\",\"netmagic\":\"%s\",\"port\":%u,\"blocktime\":%u,\"pubval\":\"%s\",\"p2shval\":\"%s\",\"wifval\":\"%s\",\"isPoS\":%u,\"unitval\":\"%02x\",\"genesishash\":\"%s\",\"genesis\":{\"version\":1,\"timestamp\":%u,\"nbits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesisblock\":\"%s\"}",isPoS,chainname,symbol,magicstr,juint(valsobj,"port"),blocktime,pubstr,p2shstr,wifvalstr,juint(valsobj,"isPoS"),(nBits >> 24) & 0xff,hashstr,genesis.RO.timestamp,nbitstr,genesis.RO.nonce,bits256_str(str2,genesis.RO.merkle_root),blockstr); + free(blockstr); + //printf("argbuf.(%s) hash.%s\n",argbuf,hashstr); + return(cJSON_Parse(argbuf)); + } else return(cJSON_Parse("{\"error\":\"couldnt create block\"}")); +} + +cJSON *gecko_genesisissue(char *symbol,char *chainname,char *chainstr,cJSON *valsobj) +{ + //printf("issue isPoS.%d\n",juint(valsobj,"isPoS")); + return(gecko_genesisargs(symbol,chainname,chainstr,jstr(valsobj,"key"),jstr(valsobj,"genesishash"),jstr(valsobj,"genesisblock"),jstr(valsobj,"netmagic"),juint(valsobj,"port"),juint(valsobj,"blocktime"),jstr(valsobj,"nbits"),jstr(valsobj,"pubval"),jstr(valsobj,"p2shval"),jstr(valsobj,"wifval"),juint(valsobj,"isPoS"))); +} + +struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj) +{ + int32_t datalen,hdrsize; struct iguana_info *virt=0; char *hexstr; uint8_t hexbuf[1024],*ptr,*serialized; struct iguana_peer *addr; + if ( iguana_coinfind(symbol) == 0 && (hexstr= jstr(valsobj,"genesisblock")) != 0 && (virt= iguana_coinadd(symbol,chainname,valsobj)) != 0 ) + { + safecopy(virt->name,chainname,sizeof(virt->name)); + virt->chain = calloc(1,sizeof(*virt->chain)); + virt->enableCACHE = 1; + serialized = get_dataptr(&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr); + iguana_chaininit(virt->chain,1,valsobj); + hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr); + if ( gecko_blocknonce_verify(virt,serialized,hdrsize,virt->chain->nBits) == 0 ) + { + virt->chain->genesishash2 = iguana_calcblockhash(symbol,virt->chain->hashalgo,serialized,hdrsize); + memcpy(virt->chain->genesis_hashdata,virt->chain->genesishash2.bytes,sizeof(virt->chain->genesishash2)); + if ( ptr != 0 ) + free(ptr); + virt->chain->genesis_hex = clonestr(hexstr); + virt->MAXPEERS = 0; + addr = &virt->internaladdr; + iguana_initpeer(virt,addr,calc_ipbits("127.0.0.1")); + if ( addr->RAWMEM.ptr == 0 ) + iguana_meminit(&addr->RAWMEM,virt->symbol,0,IGUANA_MAXPACKETSIZE * 2,0); + if ( addr->TXDATA.ptr == 0 ) + iguana_meminit(&addr->TXDATA,"txdata",0,IGUANA_MAXPACKETSIZE * 2,0); + if ( addr->HASHMEM.ptr == 0 ) + iguana_meminit(&addr->HASHMEM,"HASHPTRS",0,256,0);//IGUANA_MAXPACKETSIZE*16,0); + iguana_callcoinstart(virt); + } else printf("error validating nonce\n"); + } + return(virt); +} + +char *basilisk_respond_newgeckochain(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) +{ + struct iguana_info *virt,*btcd; struct gecko_chain *chain; char fname[512],*symbol,*retstr,*chainstr,chainname[GECKO_MAXNAMELEN],*genesises; cJSON *chainjson,*retjson,*genesisjson; long filesize; FILE *fp; + if ( (chain= gecko_chain(myinfo,chainname,valsobj)) != 0 && (virt= chain->info) != 0 ) + { + printf("%s already exists\n",chainname); + return(clonestr("{\"error\":\"cant create duplicate geckochain\"}")); + } + if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(valsobj,"symbol")) != 0 && (chainstr= jstr(valsobj,"chain")) != 0 ) + { + if ( (virt= basilisk_geckochain(myinfo,symbol,chainname,valsobj)) != 0 ) + { + chain->info = virt; + if ( (retjson= gecko_genesisissue(symbol,chainname,chainstr,valsobj)) != 0 ) + { + jaddstr(retjson,"result","success"); + retstr = jprint(retjson,0); + sprintf(fname,"genesis/%s",symbol); + genesisjson = 0; + filesize = 0; + if ( (fp= fopen(fname,"wb")) != 0 ) + { + if ( fwrite(retstr,1,strlen(retstr),fp) == strlen(retstr) ) + { + if ( (genesises= OS_filestr(&filesize,"genesis/list")) != 0 ) + { + genesisjson = cJSON_Parse(genesises); + free(genesises); + } else genesisjson = cJSON_CreateArray(); + chainjson = cJSON_CreateObject(); + jaddstr(chainjson,"chain",chainname); + jaddstr(chainjson,"symbol",symbol); + jaddstr(chainjson,"agent","basilisk"); + jaddstr(chainjson,"method","newgeckochain"); + jadd(chainjson,"vals",retjson); + jaddi(genesisjson,chainjson); + } + fclose(fp); + } + if ( genesisjson != 0 ) + { + genesises = jprint(genesisjson,1); + if ( strlen(genesises) > filesize ) + { + if ( (fp= fopen("genesis/list","wb")) != 0 ) + { + fwrite(genesises,1,strlen(genesises),fp); + fclose(fp); + } + } + } else free_json(retjson); + return(retstr); + } else return(clonestr("{\"error\":\"couldnt create gecko genesis\"}")); + } + } + return(clonestr("{\"error\":-22}")); +} + +int32_t gecko_genesises(struct supernet_info *myinfo,cJSON *array) +{ + char *chainstr,chainname[GECKO_MAXNAMELEN],*symbol; int32_t i,n,num=0; cJSON *item,*valsobj; struct iguana_info *btcd,*virt; struct gecko_chain *chain; + if ( (btcd= iguana_coinfind("BTCD")) == 0 ) + return(0); + if ( array != 0 && (n= cJSON_GetArraySize(array)) != 0 ) + { + for (i=0; iinfo) != 0 ) + { + printf("%s %s already exists\n",chainname,symbol); + continue; + } + if ( (virt= basilisk_geckochain(myinfo,symbol,chainname,valsobj)) != 0 ) + { + chain->info = virt; + num++; + } + } + } + } + return(num); +} + +char *basilisk_respond_geckogenesis(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 txid,int32_t from_basilisk) +{ + long filesize; + return(OS_filestr(&filesize,"genesis/list")); +} + +char *basilisk_respond_geckotx(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 txid,int32_t from_basilisk) +{ + bits256 checktxid; int32_t blocklen; uint32_t nBits; char *symbol,*blockstr,*txptrs[2],space[4096]; struct iguana_info *virt; cJSON *sendjson; struct iguana_block newblock; uint8_t *blockdata,*allocptr,blockspace[8192]; + if ( data != 0 && datalen != 0 && (symbol= jstr(valsobj,"symbol")) != 0 && (virt= iguana_coinfind(symbol)) != 0 ) + { + checktxid = bits256_doublesha256(0,data,datalen); + memset(&newblock,0,sizeof(newblock)); + newblock.height = virt->blocks.hwmchain.height + 1; + newblock.RO.prev_block = virt->blocks.hwmchain.RO.prev_block; + newblock.RO.version = GECKO_DEFAULTVERSION; + if ( bits256_cmp(txid,checktxid) == 0 && (nBits= gecko_nBits(virt,&newblock)) != 0 ) + { + newblock.RO.bits = nBits; + txptrs[0] = basilisk_addhexstr(&txptrs[1],0,space,sizeof(space),data,datalen); // add mempool + if ( (blockstr= gecko_createblock(myinfo,iguana_coinfind("BTCD"),juint(valsobj,"isPoS"),&newblock,virt->symbol,txptrs,1,gecko_paymentsobj(myinfo,0,jobj(valsobj,"payments"),0),1000)) != 0 ) + { + if ( _iguana_chainlink(virt,&newblock) != 0 ) + { + sendjson = cJSON_CreateObject(); + jaddstr(sendjson,"coin",symbol); + jaddnum(sendjson,"ht",newblock.height); + jaddbits256(sendjson,"pubkey",newblock.RO.hash2); + blockdata = basilisk_jsondata(&allocptr,blockspace,sizeof(blockspace),&blocklen,symbol,sendjson,basilisktag); + printf("broadcast %s %s\n",blockstr,jprint(sendjson,0)); + basilisk_sendcmd(myinfo,0,"BLK",&basilisktag,juint(valsobj,"encrypt"),juint(valsobj,"delay"),&blockdata[sizeof(struct iguana_msghdr)+sizeof(basilisktag)],blocklen,-1,nBits); + if ( allocptr != 0 ) + free(allocptr); + } + free(blockstr); + } + if ( txptrs[1] != 0 ) + free(txptrs[1]); + } else return(clonestr("{\"error\":\"geckotx doesnt match txid\"}")); + } + return(clonestr("{\"error\":\"no geckotx data\"}")); +} + +char *basilisk_respond_geckoblock(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash2,int32_t from_basilisk) +{ + char *symbol; struct iguana_info *virt; bits256 checkhash2; int32_t hdrsize; uint32_t nBits; struct iguana_msgblock msg; struct iguana_block newblock; + printf("got geckoblock len.%d from (%s) %s\n",datalen,remoteaddr!=0?remoteaddr:"",jprint(valsobj,0)); + if ( (symbol= jstr(valsobj,"coin")) != 0 && (virt= iguana_coinfind(symbol)) != 0 ) + { + hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr); + nBits = gecko_nBits(virt,(struct iguana_block *)&virt->blocks.hwmchain); + if ( gecko_blocknonce_verify(virt,data,hdrsize,nBits) == 0 ) + { + iguana_rwblock(symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&checkhash2,data,&msg,datalen); + if ( bits256_cmp(hash2,checkhash2) == 0 ) + { + iguana_blockconv(virt->chain->zcash,virt->chain->auxpow,&newblock,&msg,hash2,jint(valsobj,"ht")); + if ( _iguana_chainlink(virt,&newblock) != 0 ) + { + return(clonestr("{\"result\":\"gecko chain extended\"}")); + } else return(clonestr("{\"result\":\"block not HWM\"}")); + } else return(clonestr("{\"error\":\"block error with checkhash2\"}")); + } else return(clonestr("{\"error\":\"block nonce didnt verify\"}")); + } + return(0); +} + +#include "../includes/iguana_apidefs.h" +#include "../includes/iguana_apideclares.h" + +HASH_ARRAY_STRING(basilisk,sequence,pubkey,vals,hexstr) +{ + return(basilisk_standardservice("SEQ",myinfo,pubkey,vals,hexstr,1)); +} + +HASH_ARRAY_STRING(basilisk,newgeckochain,pubkey,vals,hexstr) +{ + char chainname[GECKO_MAXNAMELEN],magicstr[9],*retstr,*symbol,*chainstr; struct iguana_info *btcd; cJSON *argjson,*argvals,*retjson=0; int32_t i,isPoS; uint32_t magic; struct gecko_chain *chain; + if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 && (chainstr= jstr(vals,"chain")) != 0 ) + { + if ( iguana_coinfind(symbol) == 0 && (chain= gecko_chain(myinfo,chainname,vals)) != 0 && chain->info != 0 ) + { + printf("%s already exists\n",chainname); + return(clonestr("{\"error\":\"cant create duplicate geckochain\"}")); + } + if ( jobj(vals,"netmagic") == 0 ) + { + OS_randombytes((void *)&magic,sizeof(magic)); + for (i=0; iRELAYNODE != 0 || btcd->VALIDATENODE != 0 ) + retstr = basilisk_respond_newgeckochain(myinfo,"NEW",0,0,0,argvals,0,0,GENESIS_PUBKEY,0); + else retstr = basilisk_standardservice("NEW",myinfo,GENESIS_PUBKEY,argvals,0,1); + free_json(argvals); + if ( (argvals= cJSON_Parse(retstr)) != 0 ) + { + if ( jobj(argvals,"result") != 0 && strcmp(jstr(argvals,"result"),"success") == 0 ) + { + if ( basilisk_geckochain(myinfo,symbol,chainname,argvals) != 0 ) + jaddstr(argvals,"status","active"); + //free_json(argvals); + } else jaddstr(argvals,"error","couldnt initialize geckochain"); + free(retstr); + return(jprint(argvals,1)); + } + if ( retjson != 0 ) + free_json(retjson); + free_json(argvals); + return(retstr); + } else return(clonestr("{\"error\":\"couldnt create genesis_block\"}")); + } + return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new gecko chain\"}")); +} + +HASH_ARRAY_STRING(basilisk,geckotx,pubkey,vals,hexstr) +{ + struct iguana_info *btcd,*virt; char *retstr=0,*symbol; uint8_t *data,*allocptr,space[4096]; int32_t datalen; bits256 txid; + if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 ) + { + if ( (virt= iguana_coinfind(symbol)) != 0 ) + { + if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 ) + { + if ( (data= get_dataptr(&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) + { + txid = bits256_doublesha256(0,data,datalen); + retstr = basilisk_respond_geckotx(myinfo,"VTX",0,0,0,vals,data,datalen,txid,0); + } + if ( allocptr != 0 ) + free(allocptr); + if ( retstr == 0 ) + retstr = clonestr("{\"error\":\"couldnt create geckotx\"}"); + } else retstr = basilisk_standardservice("VTX",myinfo,txid,vals,hexstr,1); + return(retstr); + } else return(clonestr("{\"error\":\"couldnt find geckochain\"}")); + } + return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new gecko tx\"}")); +} + +HASH_ARRAY_STRING(basilisk,geckoblock,pubkey,vals,hexstr) +{ + return(clonestr("{\"error\":\"geckoblock is an internal function\"}")); + //return(basilisk_standardservice("BLK",myinfo,pubkey,vals,hexstr,1)); +} + +HASH_ARRAY_STRING(basilisk,geckogenesis,pubkey,vals,hexstr) +{ + long filesize; int32_t i,j,n,m; struct iguana_info *btcd; char *ref,*symbol,*retstr=0; cJSON *item,*array = 0,*arrayB = 0; FILE *fp; + if ( (btcd= iguana_coinfind("BTCD")) != 0 ) + { + if ( (retstr= basilisk_standardservice("GEN",myinfo,pubkey,vals,hexstr,1)) != 0 ) + { + arrayB = cJSON_Parse(retstr); + free(retstr); + } + if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 ) + { + if ( (retstr= OS_filestr(&filesize,"genesis/list")) != 0 ) + { + array = cJSON_Parse(retstr); + free(retstr); + } + if ( array == 0 ) + array = arrayB; + else if ( arrayB != 0 ) + { + if ( (n= cJSON_GetArraySize(arrayB)) > 0 ) + { + if ( (m= cJSON_GetArraySize(array)) <= 0 ) + array = arrayB; + else + { + for (i=0; istamps == 0 ) + return(-1); + if ( seq->stamps[seq->lasti].timestamp < reftimestamp && seq->lasti >= 3 ) + i = seq->lasti - 3; + for (; inumstamps; i++) + { + if ( (timestamp= seq->stamps[i].timestamp) == 0 || timestamp > reftimestamp ) + { + memset(stamps,0,sizeof(*stamps) * max); + for (j=0; j=0; j++) + stamps[j] = seq->stamps[i - j]; + return(gap); + } + if ( foundflag < 0 && bits256_cmp(hash,seq->stamps[i].hash2) == 0 ) + { + seq->lasti = i; + foundflag = i; + gap = 0; + } + else if ( foundflag >= 0 ) + gap++; + } + return(-1); +} + +bits256 gecko_hashstampscalc(struct iguana_info *btcd,bits256 *btchashp,uint32_t reftimestamp) +{ + struct hashstamp BTCDstamps[GECKO_MAXBTCDGAP],BTCstamps[GECKO_MAXBTCGAP]; bits256 btcdhash; + btcdhash = *btchashp = GENESIS_PUBKEY; + if ( gecko_hashstampsfind(BTCDstamps,GECKO_MAXBTCDGAP,&btcd->SEQ.BTCD,btcdhash,reftimestamp) < 0 ) + { + btcdhash = BTCDstamps[GECKO_MAXBTCDGAP >> 1].hash2; + if ( gecko_hashstampsfind(BTCstamps,GECKO_MAXBTCGAP,&btcd->SEQ.BTC,*btchashp,reftimestamp) < 0 ) + *btchashp = BTCstamps[GECKO_MAXBTCGAP >> 1].hash2; + } + return(btcdhash); +} + +// have local coin +int32_t gecko_hashstampsreverse(struct iguana_info *coin,struct gecko_sequence *seq,int32_t firstpossible,int32_t max,struct iguana_block *block,uint32_t reftimestamp) +{ + uint32_t timestamp; int32_t j,offset; + while ( block != 0 && (timestamp= block->RO.timestamp) > reftimestamp ) + block = iguana_blockfind("hashstamps",coin,block->RO.prev_block); + if ( block == 0 ) + return(-1); + offset = (block->height - firstpossible); + for (j=0; jstamps[offset].hash2 = block->RO.hash2; + seq->stamps[offset].timestamp = block->RO.timestamp; + seq->stamps[offset].height = block->height; + if ( offset-- < 0 || (block= iguana_blockfind("revstamp",coin,block->RO.prev_block)) == 0 ) + return(block == 0 ? -1 : j); + } + return(j); +} + +int32_t gecko_hashstampset(struct iguana_info *coin,struct hashstamp *stamp,int32_t height) +{ + struct iguana_block *block; struct iguana_bundle *bp; + if ( height >= 0 && height < coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 ) + { + if ( (block= bp->blocks[height % coin->chain->bundlesize]) != 0 ) + { + stamp->hash2 = block->RO.hash2; + stamp->timestamp = block->RO.timestamp; + stamp->height = block->height; + return(0); + } + } + return(-1); +} + +void gecko_ensure(struct gecko_sequence *seq,int32_t num) +{ + int32_t oldmax,incr = 1000; + if ( num >= seq->maxstamps ) + { + oldmax = seq->maxstamps; + seq->maxstamps = ((num + 2*incr) / incr) * incr; + seq->stamps = realloc(seq->stamps,sizeof(*seq->stamps) * seq->maxstamps); + memset(&seq->stamps[oldmax],0,sizeof(*seq->stamps) * (seq->maxstamps - oldmax)); + } +} + +int32_t gecko_hashstampsupdate(struct iguana_info *coin,struct gecko_sequence *seq,int32_t firstpossible) +{ + while ( (firstpossible + seq->numstamps) < coin->blocks.hwmchain.height ) + { + gecko_ensure(seq,seq->numstamps); + if ( gecko_hashstampset(coin,&seq->stamps[seq->numstamps],firstpossible + seq->numstamps) < 0 ) + break; + else seq->numstamps++; + } + seq->longestchain = coin->longestchain; + return(seq->numstamps); +} + +int32_t gecko_sequpdate(char *symbol,uint32_t reftimestamp) +{ + struct gecko_sequence *seq=0; int32_t max=0,firstpossible=0; struct iguana_info *coin; struct iguana_block *block; + if ( (coin= iguana_coinfind(symbol)) != 0 && (coin->RELAYNODE != 0 || coin->VALIDATENODE != 0) ) + { + if ( strcmp(symbol,"BTCD") == 0 ) + { + seq = &coin->SEQ.BTCD; + firstpossible = GECKO_FIRSTPOSSIBLEBTCD; + } + else if ( strcmp(symbol,"BTC") == 0 ) + { + seq = &coin->SEQ.BTC; + firstpossible = GECKO_FIRSTPOSSIBLEBTC; + } else return(-1); + //printf("basilisk update.%s %u lag.%d\n",symbol,reftimestamp,(uint32_t)time(NULL)-seq->lastupdate); + if ( gecko_hashstampsupdate(coin,seq,firstpossible) > 0 ) + { + if ( (block= iguana_blockfind("SEQupdate",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) + gecko_hashstampsreverse(coin,seq,firstpossible,max,block,reftimestamp); + return(0); + } + } + return(-1); +} + +int32_t iguana_rwhashstamp(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct hashstamp *stamp) +{ + int32_t len = 0; + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(stamp->hash2),stamp->hash2.bytes); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(stamp->timestamp),&stamp->timestamp); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(stamp->height),&stamp->height); + //len += iguana_rwblockhdr(rwflag,zcash,&serialized[len],(void *)stamp->RO); + return(len); +} + +cJSON *gecko_sequencejson(uint8_t zcash,struct gecko_sequence *seq,int32_t startheight,int32_t firstpossible) +{ + int32_t i,n,len=0,datalen,num = 0; cJSON *item; uint8_t *data; char strbuf[8192],*hexstr=0; + if ( startheight < firstpossible ) + startheight = firstpossible; + if ( (i= (startheight - firstpossible) ) < 0 || i >= seq->numstamps ) + return(0); + item = cJSON_CreateObject(); + n = (seq->numstamps - i); + datalen = (int32_t)(n * sizeof(*seq->stamps)); + data = calloc(n,sizeof(*seq->stamps)); + for (; inumstamps && numstamps[i].timestamp == 0 ) + break; + len += iguana_rwhashstamp(1,zcash,&data[len],&seq->stamps[i]); + } + jaddnum(item,"start",startheight); + jaddnum(item,"num",num); + jaddnum(item,"lastupdate",seq->lastupdate); + jaddnum(item,"longest",seq->longestchain); + basilisk_addhexstr(&hexstr,item,strbuf,sizeof(strbuf),data,datalen); + if ( hexstr != 0 ) + free(hexstr); + return(item); +} + +void gecko_seqresult(struct supernet_info *myinfo,char *retstr) +{ + struct iguana_info *btcd; struct hashstamp stamp; struct gecko_sequence *seq = 0; cJSON *resultjson; uint8_t *allocptr = 0,space[8192],*data = 0; int32_t ind,startheight,datalen,lastupdate,longestchain,i,num,firstpossible,len = 0; char *hexstr; + if ( (btcd= iguana_coinfind("BTCD")) != 0 && (resultjson= cJSON_Parse(retstr)) != 0 ) + { + if ( jstr(resultjson,"BTCD") != 0 ) + seq = &btcd->SEQ.BTCD, firstpossible = GECKO_FIRSTPOSSIBLEBTCD; + else if ( jstr(resultjson,"BTC") != 0 ) + seq = &btcd->SEQ.BTC, firstpossible = GECKO_FIRSTPOSSIBLEBTC; + if ( seq != 0 ) + { + startheight = jint(resultjson,"start"); + if ( (ind= startheight-firstpossible) < 0 ) + { + free_json(resultjson); + return; + } + num = jint(resultjson,"num"); + lastupdate = jint(resultjson,"lastupdate"); + longestchain = jint(resultjson,"longest"); + hexstr = jstr(resultjson,"data"); + printf("got startheight.%d num.%d lastupdate.%d longest.%d (%s)\n",startheight,num,lastupdate,longestchain,hexstr!=0?hexstr:""); + if ( hexstr != 0 && (data= get_dataptr(&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) + { + gecko_ensure(seq,ind + num); + for (i=0; ichain->zcash,&data[len],&stamp); + // verify blockheader + seq->stamps[ind] = stamp; + } + } + if ( allocptr != 0 ) + free(allocptr); + } + free_json(resultjson); + } +} + +char *basilisk_respond_hashstamps(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) +{ + int32_t startheight; struct iguana_info *btcd; cJSON *retjson = cJSON_CreateObject(); + if ( (btcd= iguana_coinfind("BTCD")) != 0 ) + { + if ( (startheight= juint(valsobj,"BTCD")) != 0 ) + jadd(retjson,"BTCD",gecko_sequencejson(btcd->chain->zcash,&btcd->SEQ.BTCD,startheight,GECKO_FIRSTPOSSIBLEBTCD)); + else if ( (startheight= juint(valsobj,"BTC")) != 0 ) + jadd(retjson,"BTC",gecko_sequencejson(btcd->chain->zcash,&btcd->SEQ.BTC,startheight,GECKO_FIRSTPOSSIBLEBTC)); + } + return(jprint(retjson,1)); +} diff --git a/gecko/gecko_miner.c b/gecko/gecko_miner.c new file mode 100755 index 000000000..3352cb148 --- /dev/null +++ b/gecko/gecko_miner.c @@ -0,0 +1,270 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +// included from gecko_chains.c + +int32_t gecko_blocknonce_verify(struct iguana_info *virt,uint8_t *serialized,int32_t datalen,uint32_t nBits) +{ + bits256 threshold,hash2; + threshold = bits256_from_compact(nBits); + hash2 = iguana_calcblockhash(virt->symbol,virt->chain->hashalgo,serialized,datalen); + if ( bits256_cmp(threshold,hash2) > 0 ) + return(0); + else return(0); +} + +uint32_t gecko_nBits(struct iguana_info *virt,struct iguana_block *newblock) +{ + uint32_t nBits = GECKO_DEFAULTDIFF; struct iguana_block *prev=0,*prev2=0; + if ( newblock->height >= 0 && (prev= iguana_blockfind("geckotx",virt,newblock->RO.prev_block)) != 0 && prev->height > 1 ) + { + if ( (prev2= iguana_blockfind("prvatetx2",virt,prev->RO.prev_block)) != 0 && prev2->height >= 0 ) + { + nBits = iguana_targetbits(virt,newblock,prev,prev2,1,virt->chain->targetspacing,virt->chain->targettimespan); + if ( nBits > virt->chain->nBits ) + nBits = virt->chain->nBits; + } + else nBits = virt->chain->nBits; + } else printf("ht.%d prev.%p prevht.%d prev2.%p\n",newblock->height,prev,prev!=0?prev->height:-1,prev2); + return(nBits); +} + +int32_t gecko_delayedPoW(struct supernet_info *myinfo,struct iguana_info *btcd,int32_t isPoS,uint8_t *coinbase,bits256 *btcdhashp,uint32_t timestamp,int32_t height) +{ + bits256 btchash; int32_t len = 0; + len += iguana_rwnum(1,&coinbase[len],sizeof(height),(void *)&height); + if ( (isPoS & 7) != 0 ) + { + *btcdhashp = gecko_hashstampscalc(btcd,&btchash,timestamp); + if ( (isPoS & 2) != 0 && (bits256_cmp(*btcdhashp,GENESIS_PUBKEY) == 0 || bits256_nonz(*btcdhashp) == 0) ) + return(-1); + if ( (isPoS & 4) != 0 && (bits256_cmp(btchash,GENESIS_PUBKEY) == 0 || bits256_nonz(btchash) == 0) ) + return(-1); + //len += iguana_rwbignum(1,&coinbase[len],sizeof(*btcdhashp),btcdhashp->bytes); + len += iguana_rwbignum(1,&coinbase[len],sizeof(btchash),btchash.bytes); + } else *btcdhashp = GENESIS_PUBKEY; + return(len); +} + +char *gecko_coinbasestr(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,uint8_t *data,int32_t datalen,bits256 coinbasespend,cJSON *coinbasetx) +{ + char *rawtx; cJSON *txjson; + if ( (txjson= coinbasetx) == 0 ) + txjson = bitcoin_txcreate(1,0,coin->chain->normal_txversion); + bitcoin_txinput(coin,txjson,coinbasespend,-1,0xffffffff,0,0,data,datalen,0,0); + //printf("TX.(%s)\n",jprint(txjson,0)); + rawtx = bitcoin_json2hex(myinfo,coin,txidp,txjson,0); + if ( txjson != coinbasetx ) + free_json(txjson); + return(rawtx); +} + +char *gecko_block(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_block *newblock,uint32_t *noncep,char **txptrs,int32_t txn_count,uint8_t *coinbase,int32_t coinbaselen,bits256 coinbasespend,cJSON *coinbasetx,double expiration) +{ + struct iguana_info *btcd; uint8_t serialized[sizeof(*newblock)],space[16384],*txdata,*allocptr = 0; int32_t i,n,totaltxlen=0,txlen; char *coinbasestr,*blockstr=0; bits256 *txids=0,txspace[256],threshold; + //char str[65]; printf("prevblock.%s\n",bits256_str(str,newblock->RO.prev_block)); + if ( (btcd= iguana_coinfind("BTCD")) == 0 ) + { + printf("basilisk needs BTCD\n"); + return(0); + } + if ( txn_count+2 < sizeof(space)/sizeof(*space) ) + { + txids = txspace; + memset(txids,0,sizeof(*txids) * (txn_count+2)); + } else txids = calloc(txn_count+2,sizeof(*txids)); + if ( txn_count > 0 ) + { + for (i=0; iRO.merkle_root = iguana_merkle(txids,txn_count + 1); + newblock->RO.txn_count = (txn_count + 1); + threshold = bits256_from_compact(newblock->RO.bits); + if ( (newblock->RO.nonce= *noncep) == 0 ) + { + for (i=0; iRO.nonce = rand(); + n = iguana_serialize_block(virt->chain,&newblock->RO.hash2,serialized,newblock); + //char str[65]; printf("nonce.%08x %s\n",block->RO.nonce,bits256_str(str,block->RO.hash2)); + if ( bits256_cmp(threshold,newblock->RO.hash2) > 0 ) + break; + if ( (i & 0xff) == 0xff && OS_milliseconds() > expiration ) + break; + } + } + *noncep = newblock->RO.nonce; + n = iguana_serialize_block(virt->chain,&newblock->RO.hash2,serialized,newblock); + if ( bits256_cmp(threshold,newblock->RO.hash2) > 0 ) + { + blockstr = calloc(1,strlen(coinbasestr) + (totaltxlen+n)*2 + 1); + init_hexbytes_noT(blockstr,serialized,n); + //printf("block.(%s) coinbase.(%s) lens.%ld\n",blockstr,coinbasestr,(strlen(blockstr)+strlen(coinbasestr))/2); + strcat(blockstr,coinbasestr); + for (i=0; iRO.prev_block),&newblock->RO.prev_block); + if ( btcd != 0 ) + { + newblock->RO.timestamp = (uint32_t)time(NULL); + if ( (coinbaselen= gecko_delayedPoW(myinfo,btcd,isPoS,coinbase,&btcdhash,newblock->RO.timestamp,newblock->height)) < 0 ) + { + printf("error generating coinbase for height.%d\n",newblock->height); + return(0); + } + nonce = 0; + return(gecko_block(myinfo,btcd,newblock,&nonce,txptrs,txn_count,coinbase,coinbaselen,btcdhash,coinbasetx,expiration)); + } else return(0); +} + +/*int32_t basilist_validateblock(cJSON *valsobj) + { + uint32_t now,timestamp; + now = (uint32_t)time(NULL); + if ( (timestamp= juint(valsobj,"timestamp")) < now-BASILISK_MAXBLOCKLAG || timestamp > now+BASILISK_MAXFUTUREBLOCK ) + return(-1); + if ( bits256_nonz(prevhash) == 0 ) + prevhash = coin->blocks.hwmchain.RO.hash2; + if ( (prevblock= iguana_blockfind("setfield",coin,prevhash)) == 0 ) + return(clonestr("{\"error\":\"couldnt find prevhash\"}")); + if ( (prev2= iguana_blockfind("setfield",coin,prevblock->RO.prev_block)) == 0 ) + return(clonestr("{\"error\":\"couldnt find prevhash2\"}")); + nonce = juint(valsobj,"nonce"); + nBits = iguana_targetbits(coin,&coin->blocks.hwmchain,prevblock,prev2,1,coin->chain->targetspacing,coin->chain->targettimespan); + blocktx = basilisk_block(myinfo,coin,&block,1,timestamp,&nonce,prevhash,nBits,prevblock->height+1,0,0,data,datalen,btcdhash,jobj(valsobj,"coinbase")); + + return(0); + }*/ + +cJSON *gecko_paymentsobj(struct supernet_info *myinfo,cJSON *txjson,cJSON *valsobj,int32_t reusedaddrs) +{ + cJSON *item,*array; char *coinaddr; uint64_t satoshis; uint8_t addrtype,pubkey33[33],rmd160[20],outputscript[512]; int32_t i,n,scriptlen; uint32_t locktime,txversion; struct iguana_waddress *waddr; struct iguana_waccount *wacct; + locktime = juint(valsobj,"locktime"); + if ( (txversion= juint(valsobj,"txversion")) == 0 ) + txversion = (locktime == 0) ? IGUANA_NORMAL_TXVERSION : IGUANA_LOCKTIME_TXVERSION; + if ( txjson == 0 ) + txjson = bitcoin_txcreate(1,locktime,txversion); + if ( (array= jarray(&n,valsobj,"payments")) != 0 && n > 0 ) + { + for (i=0; i 0 ) + { + printf("payment.%s <- %.8f\n",coinaddr,dstr(satoshis)); + bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); + scriptlen = 0; + if ( reusedaddrs == 0 ) + { + if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) + { + if ( bitcoin_pubkeylen(waddr->pubkey) > 0 ) + scriptlen = bitcoin_pubkeyspend(outputscript,0,pubkey33); + } + } + if ( scriptlen == 0 ) + scriptlen = bitcoin_standardspend(outputscript,0,rmd160); + bitcoin_txoutput(txjson,outputscript,scriptlen,satoshis); + } + } + } + return(txjson); +} + +char **gecko_mempool(struct supernet_info *myinfo,struct iguana_info *virt,int64_t *rewardp,int32_t *txn_countp,char **ptrp,void *space,int32_t max) +{ + *ptrp = 0; + *txn_countp = 0; + return(0); +} + +void gecko_blocksubmit(struct supernet_info *myinfo,struct iguana_info *virt,char *blockstr) +{ + +} + +void gecko_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis,char *mineraddr) +{ + struct iguana_zblock newblock; uint32_t nBits,locktime=0; int64_t reward = 0; int32_t bundlei,txn_count; cJSON *item,*array,*coinbasetx=0; char *blockstr,**txptrs,*ptr,*space[256]; struct iguana_bundle *bp; + if ( virt->virtualchain == 0 || virt->bundles[virt->blocks.hwmchain.height / virt->chain->bundlesize] == 0 ) + return; + memset(&newblock,0,sizeof(newblock)); + newblock.height = virt->blocks.hwmchain.height + 1; + newblock.RO.prev_block = virt->blocks.hwmchain.RO.hash2; + newblock.RO.version = GECKO_DEFAULTVERSION; + if ( (nBits= gecko_nBits(virt,(void *)&newblock)) != 0 ) + { + newblock.RO.bits = nBits; + //printf("mine.%s %s nBits.%x\n",virt->symbol,mineraddr,nBits); + txptrs = gecko_mempool(myinfo,virt,&reward,&txn_count,&ptr,space,(int32_t)(sizeof(space)/sizeof(*space))); + if ( reward > 0 ) + { + array = cJSON_CreateArray(); + item = cJSON_CreateObject(); + jaddnum(item,mineraddr,dstr(reward)); + jaddi(array,item); + coinbasetx = bitcoin_txcreate(1,locktime,virt->chain->normal_txversion); + jadd(coinbasetx,"payments",array); + } + //char str[65]; printf("HWM.%s %p\n",bits256_str(str,newblock.RO.prev_block),&newblock.RO.prev_block); + if ( (blockstr= gecko_createblock(myinfo,btcd,virt->chain->isPoS,(void *)&newblock,virt->symbol,txptrs,txn_count,coinbasetx,maxmillis)) != 0 ) + { + if ( (bundlei= (newblock.height % virt->chain->bundlesize)) == 0 ) + iguana_bundlecreate(virt,&bundlei,newblock.height,newblock.RO.hash2,newblock.RO.prev_block,1); + newblock.RO.allocsize = virt->chain->zcash != 0 ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block); + if ( (bp= virt->bundles[newblock.height / virt->chain->bundlesize]) != 0 ) + { + char str[65]; + iguana_hash2set(virt,"miner",bp,bundlei,newblock.RO.hash2); + if ( iguana_bundlefind(virt,&bp,&bundlei,newblock.RO.hash2) == 0 ) + printf("cant find ht.%d %s\n",newblock.height,bits256_str(str,newblock.RO.hash2)); + else printf("found bp.%p bundlei.%d\n",bp,bundlei); + } + virt->blocks.hwmchain = newblock; + char str[65]; printf("%s mined.%x %s isPoS.%d numtx.%d ht.%d\n",virt->symbol,newblock.RO.bits,bits256_str(str,newblock.RO.hash2),virt->chain->isPoS,newblock.RO.txn_count,newblock.height); + gecko_blocksubmit(myinfo,virt,blockstr); + free(blockstr); + } + if ( txptrs != space ) + free(txptrs); + } +} + diff --git a/help/.tmpmarker b/help/.tmpmarker deleted file mode 100755 index e69de29bb..000000000 diff --git a/iguana/SuperNET.c b/iguana/SuperNET.c deleted file mode 100755 index c68379471..000000000 --- a/iguana/SuperNET.c +++ /dev/null @@ -1,1557 +0,0 @@ -/****************************************************************************** - * Copyright © 2014-2016 The SuperNET Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * SuperNET software, including this file may be copied, modified, propagated * - * or distributed except according to the terms contained in the LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -#include "iguana777.h" -#include "../includes/tweetnacl.h" -#include "../crypto777/OS_portable.h" -#include "../includes/libgfshare.h" -#include "../includes/utlist.h" -#include "../includes/uthash.h" -#include "../includes/curve25519.h" -#include "../includes/cJSON.h" - - -cJSON *SuperNET_argjson(cJSON *json) -{ - cJSON *argjson = jduplicate(json); - jdelete(argjson,"agent"); - jdelete(argjson,"method"); - jdelete(argjson,"categoryhash"); - jdelete(argjson,"subhash"); - jdelete(argjson,"mypub"); - jdelete(argjson,"hexmsg"); - jdelete(argjson,"plaintext"); - jdelete(argjson,"broadcast"); - jdelete(argjson,"ov"); - jdelete(argjson,"check"); - jdelete(argjson,"yourip"); - jdelete(argjson,"myip"); - jdelete(argjson,"myipaddr"); - return(argjson); -} - -bits256 SuperNET_sharedseed(bits256 privkey,bits256 otherpub) -{ - bits256 seed2,seed; - seed = curve25519_shared(privkey,otherpub); - vcalc_sha256(0,seed2.bytes,seed.bytes,sizeof(bits256)); - return(seed2); -} - -int32_t SuperNET_delaymillis(struct supernet_info *myinfo,int32_t maxdelay) -{ - maxdelay += myinfo->maxdelay; - if ( maxdelay > SUPERNET_MAXDELAY ) - maxdelay = SUPERNET_MAXDELAY; - if ( maxdelay == 0 ) - return(0); - return(rand() % maxdelay); -} - -void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag) -{ - uint64_t ipbits; struct iguana_peer *addr; - ipbits = calc_ipbits(ipaddr); - printf("got %s remotepeer.(%s) supernet.%d\n",symbol,ipaddr,supernetflag); - if ( supernetflag != 0 && (uint32_t)myinfo->myaddr.selfipbits != (uint32_t)ipbits ) - { - if ( (addr= iguana_peerslot(coin,ipbits,0)) != 0 ) - { - printf("launch startconnection to supernet peer.(%s)\n",ipaddr); - iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); - return; - } - } - iguana_possible_peer(coin,ipaddr); -} - -int32_t SuperNET_confirmip(struct supernet_info *myinfo,uint32_t ipbits) -{ - int32_t i,j,total = 0; uint32_t x; - for (i=0; ipeers->active[j].myipbits) != 0 ) - { - if ( x == ipbits ) - total++; - else total--; - } - } - } - } - return(total); -} - -void SuperNET_checkipaddr(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *myipaddr,char *remoteaddr) -{ - uint32_t myipbits = (uint32_t)calc_ipbits(myipaddr); - if ( addr->myipbits == 0 ) - addr->myipbits = myipbits; - else if ( addr->myipbits != myipbits ) - { - printf("%s: myipaddr conflict %x != %x?\n",addr->ipaddr,addr->myipbits,myipbits); - addr->myipbits = 0; - } - if ( addr->myipbits != 0 && myinfo->myaddr.myipbits == 0 ) - myinfo->myaddr.myipbits = addr->myipbits; - if ( addr->myipbits == myinfo->myaddr.myipbits ) - myinfo->myaddr.confirmed++; - else myinfo->myaddr.confirmed--; - if ( (myinfo->myaddr.totalconfirmed= SuperNET_confirmip(myinfo,addr->myipbits)) >= coin->peers->numranked ) - myinfo->myaddr.selfipbits = addr->myipbits; - if ( myinfo->myaddr.selfipbits == myinfo->myaddr.myipbits ) - { - expand_ipbits(myinfo->ipaddr,myinfo->myaddr.selfipbits); - vcalc_sha256(0,myinfo->myaddr.iphash.bytes,(uint8_t *)&myinfo->myaddr.selfipbits,sizeof(myinfo->myaddr.selfipbits)); - } - if ( myinfo->ipaddr[0] == 0 || strcmp(myinfo->ipaddr,"127.0.0.1") == 0 ) - { - strcpy(myinfo->ipaddr,myipaddr); - } - //printf("myipaddr.%s self.%x your.%x\n",myinfo->ipaddr,myinfo->myaddr.selfipbits,myinfo->myaddr.myipbits); -} - -int32_t _SuperNET_cipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 destpub,bits256 srcpriv,uint8_t *buf) -{ - memset(cipher,0,len+crypto_box_ZEROBYTES); - memset(buf,0,crypto_box_ZEROBYTES); - memcpy(buf+crypto_box_ZEROBYTES,message,len); - crypto_box(cipher,buf,len+crypto_box_ZEROBYTES,nonce,destpub.bytes,srcpriv.bytes); - return(len + crypto_box_ZEROBYTES); -} - -uint8_t *_SuperNET_decipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 srcpub,bits256 mypriv) -{ - int32_t err; - if ( (err= crypto_box_open(message,cipher,len,nonce,srcpub.bytes,mypriv.bytes)) == 0 ) - { - message += crypto_box_ZEROBYTES; - len -= crypto_box_ZEROBYTES; - return(message); - } - return(0); -} - -void *SuperNET_deciphercalc(void **ptrp,int32_t *msglenp,bits256 privkey,bits256 srcpubkey,uint8_t *cipher,int32_t cipherlen,uint8_t *buf,int32_t bufsize) -{ - uint8_t *origptr,*nonce,*message; void *retptr; - if ( bits256_nonz(privkey) == 0 ) - privkey = GENESIS_PRIVKEY; - *ptrp = 0; - if ( cipherlen > bufsize ) - { - message = calloc(1,cipherlen); - *ptrp = (void *)message; - } - else message = buf; - origptr = cipher; - if ( bits256_nonz(srcpubkey) == 0 ) - { - memcpy(srcpubkey.bytes,cipher,sizeof(srcpubkey)); - char str[65]; printf("use attached pubkey.(%s)\n",bits256_str(str,srcpubkey)); - cipher += sizeof(srcpubkey); - cipherlen -= sizeof(srcpubkey); - } - nonce = cipher; - cipher += crypto_box_NONCEBYTES, cipherlen -= crypto_box_NONCEBYTES; - *msglenp = cipherlen - crypto_box_ZEROBYTES; - if ( (retptr= _SuperNET_decipher(nonce,cipher,message,cipherlen,srcpubkey,privkey)) == 0 ) - { - *msglenp = -1; - free(*ptrp); - } - return(retptr); -} - -uint8_t *SuperNET_ciphercalc(void **ptrp,int32_t *cipherlenp,bits256 *privkeyp,bits256 *destpubkeyp,uint8_t *data,int32_t datalen,uint8_t *space2,int32_t space2size) -{ - bits256 mypubkey; uint8_t *buf,*nonce,*cipher,*origptr,space[8192]; int32_t onetimeflag=0,allocsize; - *ptrp = 0; - allocsize = (datalen + crypto_box_NONCEBYTES + crypto_box_ZEROBYTES); - if ( bits256_nonz(*destpubkeyp) == 0 || memcmp(destpubkeyp->bytes,GENESIS_PUBKEY.bytes,sizeof(*destpubkeyp)) == 0 ) - { - *destpubkeyp = GENESIS_PUBKEY; - onetimeflag = 2; // prevent any possible leakage of privkey by encrypting to known destpub - } - if ( bits256_nonz(*privkeyp) == 0 ) - onetimeflag = 1; - if ( onetimeflag != 0 ) - { - crypto_box_keypair(mypubkey.bytes,privkeyp->bytes); - allocsize += sizeof(bits256); - } - if ( allocsize > sizeof(space) ) - buf = calloc(1,allocsize); - else buf = space; - if ( allocsize+sizeof(struct iguana_msghdr) > space2size ) - { - cipher = calloc(1,allocsize + sizeof(struct iguana_msghdr)); - *ptrp = (void *)cipher; - } else cipher = space2; - cipher = &cipher[sizeof(struct iguana_msghdr)]; - origptr = nonce = cipher; - if ( onetimeflag != 0 ) - { - memcpy(cipher,mypubkey.bytes,sizeof(mypubkey)); - nonce = &cipher[sizeof(mypubkey)]; - } - OS_randombytes(nonce,crypto_box_NONCEBYTES); - cipher = &nonce[crypto_box_NONCEBYTES]; - _SuperNET_cipher(nonce,cipher,(void *)data,datalen,*destpubkeyp,*privkeyp,buf); - if ( buf != space ) - free(buf); - *cipherlenp = allocsize; - return(origptr); -} - -#ifdef oldway -int32_t SuperNET_copybits(int32_t reverse,uint8_t *dest,uint8_t *src,int32_t len) -{ - int32_t i; uint8_t *tmp; - if ( reverse != 0 ) - { - tmp = dest; - dest = src; - src = tmp; - } - //printf("src.%p dest.%p len.%d\n",src,dest,len); - //for (i=0; i> 3); -} - -uint16_t SuperNET_checkc(bits256 privkey,bits256 otherpub,void *num,int32_t len) -{ - uint8_t buf[40]; bits256 check,seed,seed2; - seed = curve25519_shared(privkey,otherpub); - vcalc_sha256(0,seed2.bytes,seed.bytes,sizeof(seed)); - memcpy(buf,seed2.bytes,sizeof(seed)); - iguana_rwnum(1,&buf[sizeof(seed)],len,num); - vcalc_sha256(0,check.bytes,buf,(int32_t)sizeof(seed2)+len); - //printf("SuperNET_checkc otherpub.%llx + privkey.%llx -> %x\n",(long long)otherpub.txid,(long long)privkey.txid,check.ushorts[0]); - return(check.ushorts[0]); -} - -int32_t SuperNET_json2bits(uint8_t *serialized,int32_t maxsize,cJSON *json,bits256 mypub,uint16_t checkc,uint32_t myipbits,uint32_t destipbits,int32_t _othervalid) -{ - uint16_t apinum; bits256 categoryhash,subhash; uint32_t tmp,crc,timestamp; char *agent,*method; char *hexmsg; uint8_t broadcastflag; int8_t othervalid; int32_t n,len = sizeof(uint32_t); - if ( _othervalid > 100 ) - othervalid = 100; - else if ( _othervalid < -100 ) - othervalid = -100; - else othervalid = _othervalid; - tmp = juint(json,"broadcast"); - if ( tmp > SUPERNET_MAXHOPS ) - broadcastflag = SUPERNET_MAXHOPS; - else broadcastflag = tmp; - if ( juint(json,"request") != 0 ) - broadcastflag |= 0x10; - categoryhash = jbits256(json,"categoryhash"); - subhash = jbits256(json,"subhash"); - timestamp = juint(json,"timestamp"); - if ( bits256_nonz(categoryhash) > 0 && memcmp(categoryhash.bytes,GENESIS_PUBKEY.bytes,sizeof(categoryhash)) != 0 ) - { - broadcastflag |= 0x40; - if ( bits256_nonz(subhash) > 0 && memcmp(subhash.bytes,GENESIS_PUBKEY.bytes,sizeof(subhash)) != 0 ) - broadcastflag |= 0x20; - else subhash = GENESIS_PUBKEY; - if ( broadcastflag == 0 ) - broadcastflag = 1; - } - else - { - categoryhash = subhash = GENESIS_PUBKEY; - if ( broadcastflag == 0 ) - broadcastflag = 1; - } - if ( juint(json,"plaintext") != 0 ) - broadcastflag |= 0x80; - //if ( (tag= j64bits(json,"tag")) == 0 ) - // OS_randombytes((uint8_t *)&tag,sizeof(tag)); - agent = jstr(json,"agent"), method = jstr(json,"method"); - if ( agent != 0 && method != 0 && strcmp(agent,"SuperNET") == 0 && strcmp(method,"json2bits") == 0 ) - { - agent = jstr(json,"destagent"); - method = jstr(json,"destmethod"); - } - if ( (apinum= SuperNET_API2num(agent,method)) == 0xffff ) - { - printf("agent.(%s) method.(%s) is not found\n",agent,method); - return(-1); - } - len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),×tamp); - len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),&destipbits); - len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),&myipbits); - //printf("myipbits.%x destipbits.%x\n",myipbits,destipbits); - len += iguana_rwnum(1,&serialized[len],sizeof(checkc),&checkc); - len += iguana_rwnum(1,&serialized[len],sizeof(apinum),&apinum); - //len += iguana_rwnum(1,&serialized[len],sizeof(tag),&tag); - len += iguana_rwbignum(1,&serialized[len],sizeof(mypub),mypub.bytes); - len += iguana_rwnum(1,&serialized[len],sizeof(othervalid),&othervalid); - len += iguana_rwnum(1,&serialized[len],sizeof(broadcastflag),&broadcastflag); - if ( (broadcastflag & 0x40) != 0 ) - { - len += iguana_rwbignum(1,&serialized[len],sizeof(bits256),categoryhash.bytes); - if ( (broadcastflag & 0x20) != 0 ) - len += iguana_rwbignum(1,&serialized[len],sizeof(bits256),subhash.bytes); - } - //printf("broadcastflag.%x\n",broadcastflag); - if ( (hexmsg= jstr(json,"hexmsg")) != 0 ) - { - n = (int32_t)strlen(hexmsg); - if ( (n & 1) == 0 && is_hexstr(hexmsg,n) > 0 ) - { - n >>= 1; - decode_hex(&serialized[len],n,hexmsg); - len += n; - } else return(-1); - } - crc = calc_crc32(0,&serialized[sizeof(crc)],len - sizeof(crc)); - iguana_rwnum(1,serialized,sizeof(crc),&crc); - //int32_t i; for (i=0; i SUPERNET_MAXHOPS ) - broadcastflag = SUPERNET_MAXHOPS; - //printf("<<<<<<<<<<<<<<<< crc.%u ipbits.(%x %x) tag.%llx checkc.%x apinum.%d valid.%d other.%d broadcast.%d plaintext.%d\n",crc,destipbits,myipbits,(long long)tag,checkc,apinum,addr->validpub,othervalid,broadcastflag,plaintext); - if ( SuperNET_num2API(agent,method,apinum) >= 0 ) - { - jaddstr(json,"agent",agent); - jaddstr(json,"method",method); - if ( timestamp != 0 ) - jaddnum(json,"timestamp",timestamp); - if ( bits256_nonz(categoryhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,categoryhash.bytes,sizeof(categoryhash)) != 0 ) - jaddbits256(json,"categoryhash",categoryhash); - if ( bits256_nonz(categoryhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,subhash.bytes,sizeof(subhash)) != 0 ) - jaddbits256(json,"subhash",subhash); - expand_ipbits(destip,destipbits), jaddstr(json,"yourip",destip); - expand_ipbits(myipaddr,myipbits), jaddstr(json,"myip",myipaddr); - jaddstr(json,"mypub",bits256_str(str,senderpub)); - categoryhash = subhash = GENESIS_PUBKEY; - if ( (broadcastflag & 0x40) != 0 ) - { - jaddbits256(json,"categoryhash",categoryhash); - if ( (broadcastflag & 0x20) != 0 ) - jaddbits256(json,"subhash",subhash); - } - //jadd64bits(json,"tag",tag); - init_hexbytes_noT(checkstr,(void *)&checkc,sizeof(checkc)); - jaddstr(json,"check",checkstr); - jaddnum(json,"ov",othervalid); - if ( requestflag != 0 ) - jaddnum(json,"request",requestflag); - if ( plaintext != 0 ) - jaddnum(json,"plaintext",plaintext!=0); - if ( broadcastflag != 0 ) - jaddnum(json,"broadcast",broadcastflag%SUPERNET_MAXHOPS); - if ( len < datalen ) - { - //printf("len %d vs %d datalen\n",len,datalen); - hexmsg = malloc(((datalen - len)<<1) + 1); - init_hexbytes_noT(hexmsg,&serialized[len],datalen - len); - //printf("hex.(%s)\n",hexmsg); - jaddstr(json,"hexmsg",hexmsg); - free(hexmsg); - } - //printf("bits2json.(%s)\n",jprint(json,0)); - return(json); - } else printf("cant decode apinum.%d (%d.%d)\n",apinum,apinum>>5,apinum%0x1f); - return(0); -} - -char *SuperNET_hexconv(char *hexmsg) -{ - cJSON *json; char *myip,*yourip,*retstr = hexmsg; uint32_t myipbits=0,destipbits=0; - uint8_t *bits; int32_t n,len = (int32_t)strlen(hexmsg); - //if ( hexmsg == 0 || is_hexstr(hexmsg,len) == 0 ) - return(hexmsg); - len >>= 1; - if ( (bits= calloc(1,len)) != 0 ) - { - decode_hex(bits,len,hexmsg); - if ( (json= cJSON_Parse((char *)bits)) != 0 ) - { - printf("parsed hexmsg.(%s)\n",(char *)bits); - if ( (myip= jstr(json,"myip")) != 0 ) - myipbits = (uint32_t)calc_ipbits(myip); - if ( (yourip= jstr(json,"yourip")) != 0 ) - destipbits = (uint32_t)calc_ipbits(yourip); - n = SuperNET_json2bits(bits,len,json,jbits256(json,"mypub"),juint(json,"checkc"),myipbits,destipbits,(int32_t)jdouble(json,"ov")); - cJSON *json2 = SuperNET_bits2json(bits,n); printf("hexconv.(%s) -> (%s)\n",jprint(json,0),jprint(json2,1)); - if ( (retstr= calloc(1,n*2+1)) != 0 ) - init_hexbytes_noT(retstr,bits,n); - else retstr = hexmsg; - free_json(json); - } //else printf("SuperNET_hexconv cant parse.(%s)\n",hexmsg); - free(bits); - } - return(retstr); -} - -void iguana_setkeys(struct supernet_info *myinfo,struct iguana_peer *addr,bits256 *myprivp,bits256 *mypubp,bits256 *destpubp,bits256 *nextprivp,bits256 *nextpubp,bits256 *nextdestpubp) -{ - *nextprivp = myinfo->privkey; - *nextpubp = myinfo->myaddr.pubkey; - *nextdestpubp = addr->pubkey; - *myprivp = *nextprivp, *mypubp = *nextpubp, *destpubp = *nextdestpubp; - //if ( addr->validpub < 3 ) - *destpubp = GENESIS_PUBKEY; - //if ( addr->othervalid < 3 ) - *myprivp = GENESIS_PRIVKEY, *mypubp = GENESIS_PUBKEY; - //char str[65]; printf("(priv.%llx pub.%llx) -> destpub.%s\n",(long long)myprivp->txid,(long long)mypubp->txid,bits256_str(str,*destpubp)); -} - -bits256 iguana_actualpubkey(int32_t *offsetp,uint8_t *cipher,int32_t cipherlen,bits256 destpubkey) -{ - int32_t i; - *offsetp = 0; - if ( cipherlen < 56+16 ) - return(destpubkey); - for (i=56; i<56+16; i++) - if ( cipher[i] != 0 ) - break; - if ( i == 56+16 ) - { - *offsetp = sizeof(destpubkey); - memcpy(destpubkey.bytes,cipher,sizeof(destpubkey)); - //char str[65]; printf("extracted destpubkey.(%s)\n",bits256_str(str,destpubkey)); - } - return(destpubkey); -} - -int32_t iguana_send_supernet(struct iguana_peer *addr,char *jsonstr,int32_t delaymillis) -{ - int32_t datalen,cipherlen,qlen = -1; uint8_t *serialized,space2[32768],*cipher; cJSON *json; - struct supernet_info *myinfo; uint16_t checkc; - bits256 destpub,privkey,pubkey,nextprivkey,nextpubkey,nextdestpub; void *ptr = 0; - myinfo = SuperNET_MYINFO(0); - if ( (json= cJSON_Parse(jsonstr)) != 0 ) - { - iguana_setkeys(myinfo,addr,&privkey,&pubkey,&destpub,&nextprivkey,&nextpubkey,&nextdestpub); - if ( juint(json,"plaintext") == 0 && juint(json,"broadcast") == 0 && memcmp(destpub.bytes,GENESIS_PUBKEY.bytes,sizeof(pubkey)) == 0 ) - { - printf("warning broadcasting non-plaintext! (%s) (%d %d %d)\n",jsonstr,juint(json,"plaintext"),juint(json,"broadcast"),memcmp(destpub.bytes,GENESIS_PUBKEY.bytes,sizeof(pubkey))); //getchar(); - //free_json(json); - //return(-1); - } - serialized = malloc(sizeof(struct iguana_msghdr) + IGUANA_MAXPACKETSIZE); - checkc = SuperNET_checkc(nextprivkey,nextdestpub,&nextpubkey.txid,sizeof(nextpubkey.txid)); - if ( (datalen= SuperNET_json2bits(&serialized[sizeof(struct iguana_msghdr)],IGUANA_MAXPACKETSIZE,json,nextpubkey,checkc,(uint32_t)calc_ipbits(myinfo->ipaddr),(uint32_t)calc_ipbits(addr->ipaddr),addr->validpub)) > 0 ) - { - if ( 0 && jstr(json,"method") != 0 && strcmp("getpeers",jstr(json,"method")) != 0 ) - printf("SUPERSEND -> (%s) (%s) delaymillis.%d datalen.%d checkc.%x\n",jprint(SuperNET_bits2json(&serialized[sizeof(struct iguana_msghdr)],datalen),1),addr->ipaddr,delaymillis,datalen,checkc); - if ( memcmp(destpub.bytes,GENESIS_PUBKEY.bytes,sizeof(destpub)) == 0 ) - { - qlen = iguana_queue_send(addr,delaymillis,serialized,"SuperNET",datalen+1); - //printf("send broadcast\n"); - } - else - { - if ( (cipher= SuperNET_ciphercalc(&ptr,&cipherlen,&privkey,&destpub,&serialized[sizeof(struct iguana_msghdr)],datalen,space2,sizeof(space2))) != 0 ) - { - void *msgbits; int32_t msglen,offset; bits256 testpriv; uint8_t space[65536]; void *ptr2; - destpub = iguana_actualpubkey(&offset,cipher,cipherlen,destpub); - if ( 0 && (msgbits= SuperNET_deciphercalc(&ptr2,&msglen,testpriv,destpub,&cipher[offset],cipherlen-offset,space,sizeof(space))) == 0 ) - { - int32_t i; for (i=0; iipaddr); - qlen = iguana_queue_send(addr,delaymillis,&cipher[-sizeof(struct iguana_msghdr)],"SuperNETb",cipherlen); - if ( ptr != 0 ) - free(ptr); - } - } - } else printf("error json2bits\n"); - free(serialized); - } else printf("cant parse.(%s)\n",jsonstr); - return(qlen); -} - -int32_t DHT_dist(bits256 desthash,bits256 hash) -{ - int32_t i,dist = 0; - for (i=0; i<4; i++) - dist += bitweight(desthash.ulongs[i] ^ hash.ulongs[i]); - printf("(dist.%d) ",dist); - return(dist*0); -} - -struct iguana_peer *iguana_peerfind(struct supernet_info *myinfo,struct iguana_info **coinp,uint64_t destipbits,bits256 category,bits256 subhash) -{ - int32_t i,j; struct iguana_peer *addr; uint16_t port; - *coinp = 0; - port = (uint16_t)(destipbits >> 32); - for (i=0; ipeers.active[j]; - if ( addr->usock >= 0 ) - { - if ( destipbits == addr->ipbits || category_peer(myinfo,addr,category,subhash) >= 0 ) - { - if ( port == 0 || addr->A.port == port ) - { - *coinp = Coins[i]; - return(addr); - } - } - } - } - } - } - return(0); -} - -char *SuperNET_DHTsend(struct supernet_info *myinfo,uint64_t destipbits,bits256 categoryhash,bits256 subhash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext) -{ - int32_t i,j; char *convstr,*jsonstr=0; struct iguana_peer *addr; cJSON *json; struct iguana_info *coin; - if ( myinfo == 0 ) - return(clonestr("{\"error\":\"no supernet_info\"}")); - json = cJSON_CreateObject(); - jaddstr(json,"agent","SuperNET"); - jaddstr(json,"method","DHT"); - convstr = SuperNET_hexconv(hexmsg); - jaddstr(json,"hexmsg",convstr); - if ( convstr != hexmsg ) - free(convstr); - if ( broadcastflag > 0 ) - jaddnum(json,"broadcast",broadcastflag-1); - if ( plaintext != 0 ) - jaddnum(json,"plaintext",plaintext!=0); - if ( bits256_nonz(categoryhash) > 0 && memcmp(categoryhash.bytes,GENESIS_PUBKEY.bytes,sizeof(bits256)) != 0 ) - jaddbits256(json,"categoryhash",categoryhash); - if ( bits256_nonz(subhash) > 0 && memcmp(subhash.bytes,GENESIS_PUBKEY.bytes,sizeof(bits256)) != 0 ) - jaddbits256(json,"subhash",subhash); - if ( SuperNET_hexmsgfind(myinfo,categoryhash,subhash,hexmsg,1) >= 0 ) - { - //char str[65]; printf("duplicate hex.(%s) for %s\n",hexmsg,bits256_str(str,categoryhash)); - return(clonestr("{\"error\":\"duplicate packet rejected\"}")); - } - else - { - //printf("DHT send\n"); - SuperNET_hexmsgadd(myinfo,categoryhash,subhash,hexmsg,tai_now(),0); - } - jsonstr = jprint(json,1); - if ( broadcastflag != 0 || destipbits == 0 ) - { - for (i=0; ipeers.active[j]; - if ( addr->usock >= 0 && addr->supernet != 0 && (broadcastflag != 0 || category_peer(myinfo,addr,categoryhash,subhash) >= 0) ) - { - if ( strcmp("0.0.0.0",addr->ipaddr) != 0 && strcmp("127.0.0.1",addr->ipaddr) != 0 ) - { - //char str[65]; printf("BROADCAST[%d] crc.%x %s SEND.(%d) to %s\n",j,calc_crc32(0,jsonstr,(int32_t)strlen(jsonstr)),bits256_str(str,categoryhash),(int32_t)strlen(jsonstr),addr->ipaddr); - iguana_send_supernet(addr,jsonstr,maxdelay==0?0:(rand()%maxdelay)); - } - } - } - } - } - return(clonestr("{\"result\":\"packet sent to all peers\"}")); - } - if ( (addr= iguana_peerfind(myinfo,&coin,destipbits,categoryhash,subhash)) == 0 ) - return(clonestr("{\"error\":\"no route found\"}")); - if ( SuperNET_hexmsgfind(myinfo,categoryhash,subhash,hexmsg,1) >= 0 ) - { - printf("SEND.(%s) to %s\n",jsonstr,addr->ipaddr); - iguana_send_supernet(addr,jsonstr,maxdelay==0?0:(rand()%maxdelay)); - return(clonestr("{\"result\":\"packet sent directly\"}")); - } - return(clonestr("{\"result\":\"no appropriate peers to send to\"}")); -} - -char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 categoryhash,bits256 subhash,char *hexmsg,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext) -{ - uint32_t destipbits; char *retstr; - destipbits = (uint32_t)calc_ipbits(destip); - if ( (retstr = SuperNET_DHTsend(myinfo,destipbits,categoryhash,subhash,hexmsg,maxdelay,broadcastflag,plaintext)) != 0 ) - free(retstr); - return(clonestr("{\"result\":\"DHT sent\"}")); -} - -char *SuperNET_forward(struct supernet_info *myinfo,char *hexmsg,uint32_t destipbits,bits256 categoryhash,bits256 subhash,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext) -{ - return(SuperNET_DHTsend(myinfo,destipbits,categoryhash,subhash,hexmsg,maxdelay,broadcastflag,plaintext)); -} - -int32_t SuperNET_destination(struct supernet_info *myinfo,uint32_t *destipbitsp,bits256 *categoryp,bits256 *subhashp,int32_t *maxdelayp,cJSON *json,char *remoteaddr) -{ - char *destip; int32_t destflag = 0; - if ( (destip= jstr(json,"destip")) != 0 ) - *destipbitsp = (uint32_t)calc_ipbits(destip); - else *destipbitsp = 0; - *maxdelayp = juint(json,"delay"); - *categoryp = jbits256(json,"categoryhash"); - *subhashp = jbits256(json,"subhash"); - if ( *destipbitsp != 0 ) - { - if ( *destipbitsp == myinfo->myaddr.selfipbits ) - destflag |= SUPERNET_ISMINE; - else destflag |= SUPERNET_FORWARD; - } - else if ( bits256_nonz(*categoryp) > 0 ) - { - if ( category_peer(myinfo,0,*categoryp,*subhashp) > 0 ) - destflag |= SUPERNET_ISMINE; - if ( juint(json,"broadcast") > 0 ) - destflag |= SUPERNET_FORWARD; - } - if ( juint(json,"request") != 0 || remoteaddr == 0 || remoteaddr[0] == 0 || strcmp(remoteaddr,"127.0.0.1") == 0 ) - destflag |= SUPERNET_ISMINE; - return(destflag); -} - -char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr,uint16_t port) -{ - char hexbuf[8192]; bits256 category,subhash; - int32_t autologin = 0,hexlen,destflag,maxdelay,flag=0,newflag=0; uint32_t destipbits,timestamp; //cJSON *retjson; - char *str,*forwardstr=0,*retstr=0,*agent=0,*method=0,*message,*hexmsg=0,*jsonstr=0; uint64_t tag; - //printf("SuperNET_JSON.(%s)\n",jprint(json,0)); - if ( remoteaddr != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 ) - remoteaddr = 0; - if ( (agent = jstr(json,"agent")) == 0 ) - agent = "bitcoinrpc"; - method = jstr(json,"method"); - if ( agent != 0 ) - { - if ( strcmp(agent,"pangea") == 0 && jobj(json,"categoryhash") == 0 ) - { - jaddbits256(json,"categoryhash",calc_categoryhashes(0,"pangea",0)); - if ( jobj(json,"subhash") == 0 ) - jaddbits256(json,"subhash",GENESIS_PUBKEY); - } - else if ( strcmp(agent,"InstantDEX") == 0 ) - { - if ( jobj(json,"passphrase") != 0 ) - { - if ( (str= SuperNET_login(myinfo,0,json,remoteaddr,jstr(json,"handle"),0,0,jstr(json,"passphrase"))) != 0 ) - free(str); - autologin = 1; - } - else if ( jobj(json,"password") != 0 ) - { - if ( (str= SuperNET_login(myinfo,0,json,remoteaddr,jstr(json,"handle"),jstr(json,"password"),jstr(json,"permanentfile"),0)) != 0 ) - free(str); - autologin = 1; - } - } - } - if ( remoteaddr == 0 ) - { - if ( jobj(json,"timestamp") != 0 ) - jdelete(json,"timestamp"); - timestamp = (uint32_t)time(NULL); - jaddnum(json,"timestamp",timestamp); - } - if ( (tag= j64bits(json,"tag")) == 0 ) - { - OS_randombytes((uint8_t *)&tag,sizeof(tag)); - jadd64bits(json,"tag",tag); - } - //printf("SuperNET_JSON.(%s) remote.(%s)\n",jprint(json,0),remoteaddr!=0?remoteaddr:""); - destflag = SuperNET_destination(myinfo,&destipbits,&category,&subhash,&maxdelay,json,remoteaddr); - //printf("destflag.%d\n",destflag); - if ( method != 0 && (hexmsg= jstr(json,"hexmsg")) == 0 && strcmp(agent,"bitcoinrpc") != 0 && (message= jstr(json,"message")) == 0 ) - { - jsonstr = jprint(json,0); - hexlen = (int32_t)strlen(jsonstr); - if ( hexlen*2+1 > sizeof(hexbuf) ) - hexmsg = malloc(hexlen*2+1), flag = 1; - else hexmsg = hexbuf; - init_hexbytes_noT(hexmsg,(uint8_t *)jsonstr,(int32_t)strlen(jsonstr)+1); - } - if ( (destflag & SUPERNET_FORWARD) != 0 ) - { - if ( hexmsg != 0 ) - { - if ( SuperNET_hexmsgfind(myinfo,category,subhash,hexmsg,0) < 0 ) - { - //printf("FORWARD.(%s)\n",hexmsg); - newflag = 1; - SuperNET_hexmsgadd(myinfo,category,subhash,hexmsg,tai_now(),remoteaddr); - forwardstr = SuperNET_forward(myinfo,hexmsg,destipbits,category,subhash,maxdelay,juint(json,"broadcast"),juint(json,"plaintext")!=0); - } - } - } - if ( (destflag & SUPERNET_ISMINE) != 0 && agent != 0 && method != 0 ) - { - if ( strcmp(agent,"bitcoinrpc") != 0 && newflag == 0 && hexmsg != 0 && SuperNET_hexmsgfind(myinfo,category,subhash,hexmsg,0) < 0 ) - { - //printf("SuperNET_JSON hexmsgadd\n"); - SuperNET_hexmsgadd(myinfo,category,subhash,hexmsg,tai_now(),remoteaddr); - } - if ( (retstr= SuperNET_processJSON(myinfo,json,remoteaddr,port)) == 0 ) - printf("null retstr from SuperNET_JSON\n"); - } - if ( flag != 0 && hexmsg != 0 && hexmsg != hexbuf ) - free(hexmsg); - if ( retstr == 0 ) - retstr = forwardstr, forwardstr = 0; - if ( forwardstr != 0 ) - free(forwardstr); - if ( jsonstr != 0 ) - free(jsonstr); - if ( autologin != 0 ) - SuperNET_logout(myinfo,0,json,remoteaddr); - return(retstr); -} - -char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen,int32_t compressed) -{ - struct supernet_info *myinfo;char *myipaddr,*method,*retstr,*checkstr; void *ptr=0; - bits256 senderpub,privkey,pubkey,nextprivkey,nextpubkey,nextdestpub; - uint16_t checkc,othercheckc; cJSON *json,*retjson; int32_t offset,maxdelay,msglen = datalen; - uint8_t space[8192],*msgbits = 0; - myinfo = SuperNET_MYINFO(0); - retstr = 0; - *delaymillisp = 0; - if ( compressed != 0 ) - { - //int32_t i; for (i=0; iipaddr); - addr->validpub >>= 1; - return(0); - } else { char str[65]; printf("GENESIS recv %s\n",bits256_str(str,senderpub)); } - } else printf("GENESIS recv GENESIS\n"); - } //else printf("decrypted mypriv.%llx senderpub.%llx\n",(long long)privkey.txid,(long long)senderpub.txid); - //for (i=0; iprivkey,senderpub,&senderpub.txid,sizeof(senderpub.txid)); - if ( checkc == othercheckc ) - addr->validpub += 1*0; - else if ( addr->validpub > 0 ) - addr->validpub >>= 1; - else addr->validpub--; - //printf("validpub.%d: %x vs %x priv.%llx senderpub.%llx\n",addr->validpub,checkc,othercheckc,(long long)myinfo->privkey.txid,(long long)senderpub.txid); - } - maxdelay = juint(json,"maxdelay"); - if ( 1 && jstr(json,"method") != 0 && strcmp(jstr(json,"method"),"getpeers") != 0 ) - printf("GOT >>>>>>>> SUPERNET P2P.(%s) from.%s %s valid.%d:%d\n",jprint(json,0),coin->symbol,addr->ipaddr,addr->validpub,addr->othervalid); - if ( (myipaddr= jstr(json,"yourip")) != 0 ) - SuperNET_checkipaddr(SuperNET_MYINFO(0),coin,addr,myipaddr,ipaddr); - jaddstr(json,"fromp2p",coin->symbol); - method = jstr(json,"method"); - if ( method != 0 && strcmp(method,"stop") == 0 ) - { - addr->dead = (uint32_t)time(NULL); - addr->rank = 0; - free_json(json); - if ( ptr != 0 ) - free(ptr); - //return(clonestr("{\"result\":\"peer marked as dead\"}")); - return(0); - } - retstr = SuperNET_JSON(myinfo,json,ipaddr,addr->A.port); - //printf("(%s) -> p2pret.(%s)\n",jprint(json,0),retstr); - *delaymillisp = SuperNET_delaymillis(myinfo,maxdelay); - senderpub = jbits256(json,"mypub"); - addr->othervalid = (int32_t)jdouble(json,"ov"); - addr->pubkey = senderpub; - free_json(json); - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( jstr(retjson,"error") != 0 || (jstr(retjson,"result") != 0 && jstr(retjson,"method") == 0) ) - { - //printf("filter.(%s) no need to send back\n",retstr); - free(retstr); - retstr = 0; - } - free_json(retjson); - } - } else printf("error decoding bits2json\n"); - if ( ptr != 0 ) - free(ptr); - return(retstr); -} -#else -char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr,uint16_t port) -{ - int32_t autologin = 0; uint32_t timestamp; char *retstr=0,*agent=0,*method=0,*jsonstr=0; uint64_t tag; - //printf("SuperNET_JSON.(%s)\n",jprint(json,0)); - if ( remoteaddr != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 ) - remoteaddr = 0; - if ( (agent = jstr(json,"agent")) == 0 ) - agent = "bitcoinrpc"; - method = jstr(json,"method"); - if ( remoteaddr == 0 ) - { - if ( jobj(json,"timestamp") != 0 ) - jdelete(json,"timestamp"); - timestamp = (uint32_t)time(NULL); - jaddnum(json,"timestamp",timestamp); - } - if ( (tag= j64bits(json,"tag")) == 0 ) - { - OS_randombytes((uint8_t *)&tag,sizeof(tag)); - jadd64bits(json,"tag",tag); - } - if ( (retstr= SuperNET_processJSON(myinfo,json,remoteaddr,port)) == 0 ) - printf("null retstr from SuperNET_JSON\n"); - if ( jsonstr != 0 ) - free(jsonstr); - if ( autologin != 0 ) - SuperNET_logout(myinfo,0,json,remoteaddr); - return(retstr); -} -#endif - -cJSON *SuperNET_peerarray(struct iguana_info *coin,int32_t max,int32_t supernetflag) -{ - int32_t i,r,j,n = 0; struct iguana_peer *addr; cJSON *array = cJSON_CreateArray(); - r = rand(); - for (j=0; jpeers->active[i]; - if ( addr->usock >= 0 && supernetflag == (addr->supernet != 0) ) - { - jaddistr(array,addr->ipaddr); - if ( ++n >= max ) - break; - } - } - if ( n == 0 ) - { - free_json(array); - return(0); - } - return(array); -} - -int32_t SuperNET_coinpeers(struct iguana_info *coin,cJSON *SNjson,cJSON *rawjson,int32_t max) -{ - cJSON *array,*item; - if ( (array= SuperNET_peerarray(coin,max,1)) != 0 ) - { - max -= cJSON_GetArraySize(array); - item = cJSON_CreateObject(); - jaddstr(item,"coin",coin->symbol); - jadd(item,"peers",array); - jaddi(SNjson,item); - } - if ( max > 0 && (array= SuperNET_peerarray(coin,max,0)) != 0 ) - { - max -= cJSON_GetArraySize(array); - item = cJSON_CreateObject(); - jaddstr(item,"coin",coin->symbol); - jadd(item,"peers",array); - jaddi(rawjson,item); - } - return(max); -} - -void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int32_t supernetflag) -{ - int32_t i,j,m; cJSON *coinarray,*item; char *symbol,*ipaddr; struct iguana_info *ptr; - if ( array != 0 && n > 0 ) - { - for (i=0; ichain->pubtype,rmdbuf,20); - bitcoin_address(p2shaddr,coin->chain->p2shtype,rmdbuf,20); - jaddstr(retjson,"result","success"); - jaddstr(retjson,"address",coinaddr); - jaddstr(retjson,"p2sh",p2shaddr); - } - return(jprint(retjson,1)); -} - -HASH_AND_INT(SuperNET,priv2pub,privkey,addrtype) -{ - cJSON *retjson; bits256 pub; uint8_t pubkey[33]; char coinaddr[64],pubkeystr[67]; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - retjson = cJSON_CreateObject(); - crypto_box_priv2pub(pub.bytes,privkey.bytes); - jaddbits256(retjson,"curve25519",pub); - pub = bitcoin_pubkey33(myinfo->ctx,pubkey,privkey); - init_hexbytes_noT(pubkeystr,pubkey,33); - jaddstr(retjson,"secp256k1",pubkeystr); - bitcoin_address(coinaddr,addrtype,pubkey,33); - jaddstr(retjson,"result",coinaddr); - return(jprint(retjson,1)); -} - -ZERO_ARGS(SuperNET,keypair) -{ - cJSON *retjson; bits256 pubkey,privkey; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - retjson = cJSON_CreateObject(); - crypto_box_keypair(pubkey.bytes,privkey.bytes); - jaddstr(retjson,"result","generated keypair"); - jaddbits256(retjson,"privkey",privkey); - jaddbits256(retjson,"pubkey",pubkey); - return(jprint(retjson,1)); -} - -TWOHASHES_AND_STRING(SuperNET,decipher,privkey,srcpubkey,cipherstr) -{ - int32_t cipherlen=0,msglen; char *retstr; cJSON *retjson; void *ptr = 0; uint8_t *cipher,*message,space[8192]; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - if ( cipherstr != 0 ) - cipherlen = (int32_t)strlen(cipherstr) >> 1; - if ( cipherlen < crypto_box_NONCEBYTES ) - return(clonestr("{\"error\":\"cipher is too short\"}")); - cipher = calloc(1,cipherlen); - decode_hex(cipher,cipherlen,cipherstr); - if ( (message= SuperNET_deciphercalc(&ptr,&msglen,privkey,srcpubkey,cipher,cipherlen,space,sizeof(space))) != 0 ) - { - message[msglen] = 0; - retjson = cJSON_CreateObject(); - jaddstr(retjson,"result","deciphered message"); - jaddstr(retjson,"message",(char *)message); - retstr = jprint(retjson,1); - if ( ptr != 0 ) - free(ptr); - } else retstr = clonestr("{\"error\":\"couldnt decipher message\"}"); - return(retstr); -} - -TWOHASHES_AND_STRING(SuperNET,cipher,privkey,destpubkey,message) -{ - cJSON *retjson; char *retstr,*hexstr,space[8129]; uint8_t space2[8129]; - uint8_t *cipher; int32_t cipherlen,onetimeflag; bits256 origprivkey; void *ptr = 0; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - if ( (cipher= SuperNET_ciphercalc(&ptr,&cipherlen,&privkey,&destpubkey,(uint8_t *)message,(int32_t)strlen(message)+1,space2,sizeof(space2))) != 0 ) - { - if ( cipherlen > sizeof(space)/2 ) - hexstr = calloc(1,(cipherlen<<1)+1); - else hexstr = (void *)space; - init_hexbytes_noT(hexstr,cipher,cipherlen); - retjson = cJSON_CreateObject(); - jaddstr(retjson,"result",hexstr); - onetimeflag = memcmp(origprivkey.bytes,privkey.bytes,sizeof(privkey)); - if ( onetimeflag != 0 ) - { - //jaddbits256(retjson,"onetime_privkey",privkey); - jaddbits256(retjson,"onetime_pubkey",destpubkey); - if ( onetimeflag == 2 ) - jaddstr(retjson,"warning","onetime keypair was used to broadcast"); - } - retstr = jprint(retjson,1); - if ( hexstr != (void *)space ) - free(hexstr); - if ( ptr != 0 ) - free(ptr); - return(retstr); - } - printf("error encrypting message.(%s)\n",message); - return(clonestr("{\"error\":\"cant encrypt message\"}")); -} - -bits256 SuperNET_pindecipher(IGUANA_ARGS,char *pin,char *privcipher) -{ - cJSON *testjson; char *mstr,*cstr; bits256 privkey,pinpriv,pinpub; - conv_NXTpassword(pinpriv.bytes,pinpub.bytes,(uint8_t *)pin,(int32_t)strlen(pin)); - privkey = GENESIS_PRIVKEY; - if ( (cstr= SuperNET_decipher(IGUANA_CALLARGS,pinpriv,pinpub,privcipher)) != 0 ) - { - if ( (testjson= cJSON_Parse(cstr)) != 0 ) - { - if ( (mstr= jstr(testjson,"message")) != 0 && strlen(mstr) == sizeof(bits256)*2 ) - { - decode_hex(privkey.bytes,sizeof(privkey),mstr); - } else printf("error cant find message privcipher\n"); - free_json(testjson); - } else printf("Error decipher.(%s)\n",cstr); - free(cstr); - } else printf("null return from deciphering privcipher\n"); - return(privkey); -} - -THREE_STRINGS(SuperNET,rosetta,passphrase,pin,showprivkey) -{ - uint8_t flag = 0; uint64_t nxt64bits; bits256 check,privkey,pubkey,pinpriv,pinpub; - char str[128],privcipher[512],*privcipherstr,*cstr; cJSON *retjson; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - nxt64bits = conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); - if ( showprivkey != 0 && strcmp(showprivkey,"yes") == 0 ) - flag = 1; - privcipher[0] = 0; - conv_NXTpassword(pinpriv.bytes,pinpub.bytes,(uint8_t *)pin,(int32_t)strlen(pin)); - if ( (cstr= SuperNET_cipher(IGUANA_CALLARGS,pinpriv,pinpub,bits256_str(str,privkey))) != 0 ) - { - if ( (retjson= cJSON_Parse(cstr)) != 0 ) - { - if ( (privcipherstr= jstr(retjson,"result")) != 0 ) - strcpy(privcipher,privcipherstr); - free_json(retjson); - } else printf("error parsing cipher retstr.(%s)\n",cstr); - free(cstr); - } else printf("error SuperNET_cipher null return\n"); - retjson = SuperNET_rosettajson(privkey,flag); - jaddstr(retjson,"privcipher",privcipher); - check = SuperNET_pindecipher(IGUANA_CALLARGS,pin,privcipher); - if ( memcmp(check.bytes,privkey.bytes,sizeof(check)) != 0 ) - { - jaddbits256(retjson,"deciphered",check); - jaddstr(retjson,"error","cant recreate privkey from (pin + privcipher)"); - } - else if ( flag != 0 ) - jaddbits256(retjson,"deciphered",check); - if ( jobj(retjson,"error") == 0 ) - jaddstr(retjson,"result","use pin and privcipher to access wallet"); - return(jprint(retjson,1)); -} - -STRING_ARG(SuperNET,broadcastcipher,message) -{ - bits256 zero; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - memset(zero.bytes,0,sizeof(zero)); - return(SuperNET_cipher(IGUANA_CALLARGS,zero,zero,message)); -} - -STRING_ARG(SuperNET,broadcastdecipher,message) -{ - bits256 zero; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - memset(zero.bytes,0,sizeof(zero)); - return(SuperNET_decipher(IGUANA_CALLARGS,zero,zero,message)); -} - -HASH_AND_STRING(SuperNET,multicastcipher,pubkey,message) -{ - bits256 zero; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - memset(zero.bytes,0,sizeof(zero)); - return(SuperNET_cipher(IGUANA_CALLARGS,zero,pubkey,message)); -} - -HASH_AND_STRING(SuperNET,multicastdecipher,privkey,cipherstr) -{ - bits256 zero; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - memset(zero.bytes,0,sizeof(zero)); - return(SuperNET_decipher(IGUANA_CALLARGS,privkey,zero,cipherstr)); -} - -ZERO_ARGS(SuperNET,stop) -{ - if ( remoteaddr == 0 || strncmp(remoteaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 ) - { - iguana_exit(); - return(clonestr("{\"result\":\"exit started\"}")); - } else return(clonestr("{\"error\":\"cant do a remote stop of this node\"}")); -} - -TWO_ARRAYS(SuperNET,mypeers,supernet,rawpeers) -{ - SuperNET_parsepeers(myinfo,supernet,cJSON_GetArraySize(supernet),1); - SuperNET_parsepeers(myinfo,rawpeers,cJSON_GetArraySize(rawpeers),0); - return(clonestr("{\"result\":\"peers parsed\"}")); -} - -STRING_ARG(SuperNET,getpeers,activecoin) -{ - int32_t i,max = 64; - cJSON *SNjson,*rawjson,*retjson = cJSON_CreateObject(); - SNjson = cJSON_CreateArray(); - rawjson = cJSON_CreateArray(); - if ( coin != 0 ) - max = SuperNET_coinpeers(coin,SNjson,rawjson,max); - else - { - for (i=0; i0; i++) - if ( Coins[i] != 0 ) - max = SuperNET_coinpeers(Coins[i],SNjson,rawjson,max); - } - if ( max != 64 ) - { - jaddstr(retjson,"agent","SuperNET"); - jaddstr(retjson,"method","mypeers"); - jadd(retjson,"supernet",SNjson); - jadd(retjson,"rawpeers",rawjson); - } - else - { - jaddstr(retjson,"error","no peers"); - free_json(SNjson); - free_json(rawjson); - } - return(jprint(retjson,1)); -} - -/*TWOSTRINGS_AND_TWOHASHES_AND_TWOINTS(SuperNET,DHT,hexmsg,destip,categoryhash,subhash,maxdelay,broadcast) -{ - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"cant remote DHT\"}")); - else if ( hexmsg == 0 || is_hexstr(hexmsg,(int32_t)strlen(hexmsg)) <= 0 ) - return(clonestr("{\"error\":\"hexmsg missing or not in hex\"}")); - return(SuperNET_DHTencode(myinfo,destip,categoryhash,subhash,hexmsg,maxdelay,broadcast,juint(json,"plaintext")!=0)); -}*/ - -HASH_AND_STRING(SuperNET,saveconf,wallethash,confjsonstr) -{ - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - return(clonestr("{\"result\":\"saveconf here\"}")); -} - -HASH_ARRAY_STRING(SuperNET,layer,mypriv,otherpubs,str) -{ - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - return(clonestr("{\"result\":\"layer encrypt here\"}")); -} - -TWO_STRINGS(SuperNET,categoryhashes,category,subcategory) -{ - bits256 categoryhash,subhash; cJSON *retjson = cJSON_CreateObject(); - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - categoryhash = calc_categoryhashes(&subhash,category,subcategory); - jaddstr(retjson,"result","category hashes calculated"); - jaddbits256(retjson,"categoryhash",categoryhash); - jaddbits256(retjson,"subhash",subhash); - return(jprint(retjson,1)); -} - -TWO_STRINGS(SuperNET,subscribe,category,subcategory) -{ - bits256 categoryhash,subhash; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - categoryhash = calc_categoryhashes(&subhash,category,subcategory); - if ( category_subscribe(myinfo,categoryhash,subhash) != 0 ) - return(clonestr("{\"result\":\"subscribed\"}")); - else return(clonestr("{\"error\":\"couldnt subscribe\"}")); -} - -TWO_STRINGS(SuperNET,gethexmsg,category,subcategory) -{ - bits256 categoryhash,subhash; struct category_msg *m; char *hexstr; cJSON *retjson; struct private_chain *cat; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - categoryhash = calc_categoryhashes(&subhash,category,subcategory); - if ( (m= category_gethexmsg(myinfo,&cat,categoryhash,subhash)) != 0 ) - { - hexstr = calloc(1,m->len*2+1); - init_hexbytes_noT(hexstr,m->msg,m->len); - retjson = cJSON_CreateObject(); - jaddstr(retjson,"result",hexstr); - free(hexstr); - return(jprint(retjson,1)); - } else return(clonestr("{\"result\":\"no message\"}")); -} - -THREE_STRINGS(SuperNET,posthexmsg,category,subcategory,hexmsg) -{ - bits256 categoryhash,subhash; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - categoryhash = calc_categoryhashes(&subhash,category,subcategory); - category_posthexmsg(myinfo,categoryhash,subhash,hexmsg,tai_now(),remoteaddr); - return(clonestr("{\"result\":\"posted message\"}")); -} - -THREE_STRINGS(SuperNET,announce,category,subcategory,message) -{ - bits256 categoryhash,subhash; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - categoryhash = calc_categoryhashes(&subhash,category,subcategory); - return(SuperNET_categorymulticast(myinfo,0,categoryhash,subhash,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext"),json,remoteaddr)); -} - -THREE_STRINGS(SuperNET,survey,category,subcategory,message) -{ - bits256 categoryhash,subhash; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - categoryhash = calc_categoryhashes(&subhash,category,subcategory); - return(SuperNET_categorymulticast(myinfo,1,categoryhash,subhash,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext"),json,remoteaddr)); -} - -STRING_ARG(SuperNET,wif2priv,wif) -{ - bits256 privkey; char str[65]; uint8_t privkeytype; cJSON *retjson = cJSON_CreateObject(); - if ( bitcoin_wif2priv(&privkeytype,&privkey,wif) == sizeof(privkey) ) - { - jaddstr(retjson,"result","success"); - jaddstr(retjson,"privkey",bits256_str(str,privkey)); - jaddnum(retjson,"type",privkeytype); - } else jaddstr(retjson,"error","couldnt convert wif"); - return(jprint(retjson,1)); -} - -STRING_ARG(SuperNET,priv2wif,priv) -{ - bits256 privkey; char wifstr[65]; uint8_t wiftype; cJSON *retjson = cJSON_CreateObject(); - if ( is_hexstr(priv,0) == sizeof(bits256)*2 ) - { - wiftype = coin != 0 ? coin->chain->wiftype : 0x80; - decode_hex(privkey.bytes,sizeof(privkey),priv); - if ( bitcoin_priv2wif(wifstr,privkey,wiftype) > 0 ) - { - jaddstr(retjson,"result","success"); - jaddstr(retjson,"privkey",priv); - jaddnum(retjson,"type",wiftype); - jaddstr(retjson,"wif",wifstr); - } else jaddstr(retjson,"error","couldnt convert privkey"); - } else jaddstr(retjson,"error","non 32 byte hex privkey"); - return(jprint(retjson,1)); -} - -STRING_ARG(SuperNET,myipaddr,ipaddr) -{ - cJSON *retjson = cJSON_CreateObject(); - if ( myinfo->ipaddr[0] == 0 ) - { - if ( is_ipaddr(ipaddr) != 0 ) - strcpy(myinfo->ipaddr,ipaddr); - } - jaddstr(retjson,"result",myinfo->ipaddr); - return(jprint(retjson,1)); -} - -STRING_ARG(SuperNET,setmyipaddr,ipaddr) -{ - cJSON *retjson = cJSON_CreateObject(); - if ( is_ipaddr(ipaddr) != 0 ) - { - strcpy(myinfo->ipaddr,ipaddr); - jaddstr(retjson,"result",myinfo->ipaddr); - } else jaddstr(retjson,"error","illegal ipaddr"); - return(jprint(retjson,1)); -} - -STRING_ARG(SuperNET,utime2utc,utime) -{ - uint32_t utc = 0; cJSON *retjson = cJSON_CreateObject(); - utc = OS_conv_utime(utime); - char str[65]; printf("utime.%s -> %u -> %s\n",utime,utc,utc_str(str,utc)); - jaddnum(retjson,"result",utc); - return(jprint(retjson,1)); -} - -INT_ARG(SuperNET,utc2utime,utc) -{ - char str[65]; cJSON *retjson = cJSON_CreateObject(); - jaddstr(retjson,"result",utc_str(str,utc)); - return(jprint(retjson,1)); -} - -ZERO_ARGS(SuperNET,logout) -{ - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - memset(myinfo->persistent_priv.bytes,0,sizeof(myinfo->persistent_priv)); - memset(myinfo->myaddr.persistent.bytes,0,sizeof(myinfo->myaddr.persistent)); - memset(myinfo->handle,0,sizeof(myinfo->handle)); - memset(myinfo->myaddr.NXTADDR,0,sizeof(myinfo->myaddr.NXTADDR)); - myinfo->myaddr.nxt64bits = 0; - myinfo->expiration = 0; - return(clonestr("{\"result\":\"logged out\"}")); -} - -ZERO_ARGS(SuperNET,activehandle) -{ - cJSON *retjson; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - retjson = SuperNET_rosettajson(myinfo->persistent_priv,0); - jaddstr(retjson,"result","success"); - jaddstr(retjson,"handle",myinfo->handle); - jaddbits256(retjson,"persistent",myinfo->myaddr.persistent); - if ( myinfo->expiration != 0 ) - { - jaddstr(retjson,"status","unlocked"); - jaddnum(retjson,"duration",myinfo->expiration - time(NULL)); - } else jaddstr(retjson,"status","locked"); - SuperNET_MYINFOadd(myinfo); - return(jprint(retjson,1)); -} - -struct supernet_info *SuperNET_accountfind(cJSON *json) -{ - int32_t num; char *decryptstr; struct supernet_info M,*myinfo; struct iguana_info *coin = 0; - char *password,*permanentfile,*passphrase,*remoteaddr,*perspriv; - myinfo = 0; - if ( (password= jstr(json,"password")) == 0 ) - password = ""; - if ( (permanentfile= jstr(json,"permanentfile")) == 0 ) - permanentfile = ""; - if ( (passphrase= jstr(json,"passphrase")) == 0 ) - passphrase = ""; - remoteaddr = jstr(json,"remoteaddr"); - if ( (passphrase == 0 || passphrase[0] == 0) && (decryptstr= SuperNET_decryptjson(IGUANA_CALLARGS,password,permanentfile)) != 0 ) - { - if ( (json= cJSON_Parse(decryptstr)) != 0 ) - { - memset(&M,0,sizeof(M)); - if ( (perspriv= jstr(json,"persistent_priv")) != 0 && strlen(perspriv) == sizeof(bits256)*2 ) - { - M.persistent_priv = bits256_conv(perspriv); - SuperNET_setkeys(&M,0,0,0); - if ( (myinfo = SuperNET_MYINFOfind(&num,M.myaddr.persistent)) != 0 ) - { - //printf("found account.(%s) %s %llu\n",myinfo!=0?myinfo->handle:"",M.myaddr.NXTADDR,(long long)M.myaddr.nxt64bits); - return(myinfo); - } - } - else if ( (passphrase= jstr(json,"result")) != 0 || (passphrase= jstr(json,"passphrase")) != 0 ) - { - SuperNET_setkeys(&M,passphrase,(int32_t)strlen(passphrase),1); - if ( (myinfo= SuperNET_MYINFOfind(&num,M.myaddr.persistent)) != 0 ) - { - //printf("found account.(%s) %s %llu\n",myinfo!=0?myinfo->handle:"",M.myaddr.NXTADDR,(long long)M.myaddr.nxt64bits); - return(myinfo); - } - } else printf("no passphrase in (%s)\n",jprint(json,0)); - free_json(json); - } else printf("cant parse.(%s)\n",decryptstr); - free(decryptstr); - } - return(SuperNET_MYINFO(0)); -} - -FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase) -{ - char *str,*decryptstr = 0; cJSON *argjson,*item,*walletitem; - if ( remoteaddr != 0 ) - return(clonestr("{\"error\":\"no remote\"}")); - if ( handle != 0 && handle[0] != 0 ) - safecopy(myinfo->handle,handle,sizeof(myinfo->handle)); - else memset(myinfo->handle,0,sizeof(myinfo->handle)); - if ( password == 0 || password[0] == 0 ) - password = passphrase; - /*if ( password != 0 && password[0] != 0 ) - safecopy(myinfo->secret,password,sizeof(myinfo->secret)); - else if ( passphrase != 0 && passphrase[0] != 0 ) - safecopy(myinfo->secret,passphrase,sizeof(myinfo->secret));*/ - if ( permanentfile != 0 ) - safecopy(myinfo->permanentfile,permanentfile,sizeof(myinfo->permanentfile)); - if ( (decryptstr= SuperNET_decryptjson(IGUANA_CALLARGS,password,myinfo->permanentfile)) != 0 ) - { - if ( (argjson= cJSON_Parse(decryptstr)) != 0 ) - { - if ( jobj(argjson,"error") == 0 ) - { - //printf("decrypted.(%s) exp.%u pass.(%s)\n",decryptstr,myinfo->expiration,password); - if ( myinfo->decryptstr != 0 ) - free(myinfo->decryptstr); - myinfo->decryptstr = decryptstr; - if ( (passphrase= jstr(argjson,"passphrase")) != 0 ) - { - SuperNET_setkeys(myinfo,passphrase,(int32_t)strlen(passphrase),1); - free_json(argjson); - myinfo->expiration = (uint32_t)(time(NULL) + 3600); - return(SuperNET_activehandle(IGUANA_CALLARGS)); - } - else - { - free_json(argjson); - return(clonestr("{\"error\":\"cant find passphrase in decrypted json\"}")); - } - } else free_json(argjson); - } - else - { - free(decryptstr); - return(clonestr("{\"error\":\"cant parse decrypted json\"}")); - } - } - if ( passphrase != 0 && passphrase[0] != 0 ) - { - SuperNET_setkeys(myinfo,passphrase,(int32_t)strlen(passphrase),1); - if ( myinfo->decryptstr != 0 && (argjson= cJSON_Parse(myinfo->decryptstr)) != 0 ) - { - if ( jobj(argjson,"passphrase") != 0 ) - jdelete(argjson,"passphrase"); - if ( jobj(argjson,"error") != 0 ) - jdelete(argjson,"error"); - } - else - { - char rmd160str[41],str[65]; uint8_t rmd160[20],pubkey33[33]; - item = cJSON_CreateObject(); - bitcoin_pubkey33(myinfo->ctx,pubkey33,myinfo->persistent_priv); - calc_rmd160_sha256(rmd160,pubkey33,33); - init_hexbytes_noT(rmd160str,rmd160,20); - jaddstr(item,rmd160str,bits256_str(str,myinfo->persistent_priv)); - walletitem = cJSON_CreateObject(); - jadd(walletitem,"default",item); - argjson = cJSON_CreateObject(); - jadd(argjson,"wallet",walletitem); - myinfo->dirty = (uint32_t)time(NULL); - } - jaddstr(argjson,"passphrase",passphrase); - if ( (str= SuperNET_encryptjson(myinfo,coin,argjson,remoteaddr,password,myinfo->permanentfile,"")) != 0 ) - free(str); - myinfo->expiration = (uint32_t)(time(NULL) + 3600); - return(SuperNET_activehandle(IGUANA_CALLARGS)); - } else return(clonestr("{\"error\":\"need passphrase\"}")); - printf("logged into (%s) %s %s\n",myinfo->myaddr.NXTADDR,myinfo->myaddr.BTC,myinfo->myaddr.BTCD); - return(SuperNET_activehandle(IGUANA_CALLARGS)); -} - -#include "../includes/iguana_apiundefs.h" diff --git a/iguana/SuperNET_keys.c b/iguana/SuperNET_keys.c index 312aa06c5..82429a059 100755 --- a/iguana/SuperNET_keys.c +++ b/iguana/SuperNET_keys.c @@ -276,7 +276,7 @@ int32_t _SuperNET_encryptjson(char *destfname,char *passphrase,int32_t passsize, void SuperNET_setkeys(struct supernet_info *myinfo,void *pass,int32_t passlen,int32_t dosha256) { - uint8_t pubkey33[33]; bits256 hash; + bits256 hash; if ( dosha256 != 0 ) { memcpy(myinfo->secret,pass,passlen+1); @@ -290,9 +290,9 @@ void SuperNET_setkeys(struct supernet_info *myinfo,void *pass,int32_t passlen,in myinfo->myaddr.nxt64bits = hash.txid; } RS_encode(myinfo->myaddr.NXTADDR,myinfo->myaddr.nxt64bits); - bitcoin_pubkey33(myinfo->ctx,pubkey33,myinfo->persistent_priv); - bitcoin_address(myinfo->myaddr.BTC,0,pubkey33,33); - bitcoin_address(myinfo->myaddr.BTCD,60,pubkey33,33); + bitcoin_pubkey33(myinfo->ctx,myinfo->persistent_pubkey33,myinfo->persistent_priv); + bitcoin_address(myinfo->myaddr.BTC,0,myinfo->persistent_pubkey33,33); + bitcoin_address(myinfo->myaddr.BTCD,60,myinfo->persistent_pubkey33,33); } void SuperNET_parsemyinfo(struct supernet_info *myinfo,cJSON *msgjson) @@ -346,6 +346,7 @@ char *SuperNET_keysinit(struct supernet_info *myinfo,char *argjsonstr) { OS_randombytes(myinfo->persistent_priv.bytes,sizeof(myinfo->persistent_priv)); myinfo->myaddr.persistent = curve25519(myinfo->persistent_priv,curve25519_basepoint9()); + bitcoin_pubkey33(myinfo->ctx,myinfo->persistent_pubkey33,myinfo->persistent_priv); } json = cJSON_CreateObject(); jaddstr(json,"ipaddr",myinfo->ipaddr); diff --git a/iguana/exchanges/bitcoin.c b/iguana/exchanges/bitcoin.c index ef06a8936..1dda1a288 100755 --- a/iguana/exchanges/bitcoin.c +++ b/iguana/exchanges/bitcoin.c @@ -451,36 +451,42 @@ char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr cJSON *BALANCES(struct exchange_info *exchange,cJSON *argjson) { - double balance; int32_t i,minconfirms; struct iguana_info *coin; // char *retstr,numunspents; - struct supernet_info *myinfo; cJSON *retjson;// item,*utxo; //struct bitcoin_unspent *unspents; + double balance; int16_t hdrsi; uint32_t unspentind; int32_t i,minconfirms,numunspents,max; struct iguana_info *coin,*tmp; struct supernet_info *myinfo; cJSON *retjson,*array,*item,*addresses=0; int64_t *unspents=0,value,avail; retjson = cJSON_CreateArray(); myinfo = SuperNET_accountfind(argjson); - for (i=0; iallcoins,coin,tmp) { - if ( (coin= Coins[i]) != 0 )//&& coin->chain->serverport[0] != 0 ) + balance = 0.; + minconfirms = juint(argjson,"minconfirms"); + if ( minconfirms < coin->minconfirms ) + minconfirms = coin->minconfirms; + max = 100000; + unspents = calloc(max,sizeof(*unspents)); + if ( (numunspents= iguana_unspentslists(myinfo,coin,&avail,unspents,max,((uint64_t)1 << 62),minconfirms,addresses)) > 0 ) { - balance = 0.; - minconfirms = juint(argjson,"minconfirms"); - if ( minconfirms < coin->minconfirms ) - minconfirms = coin->minconfirms; - /*if ( (unspents= iguana_unspentsget(myinfo,coin,&retstr,&balance,&numunspents,minconfirms,0)) != 0 ) + array = cJSON_CreateArray(); + for (i=0; isymbol,item); - }*/ + item = cJSON_CreateArray(); + hdrsi = (int16_t)(unspents[(i << 1)] >> 32); + unspentind = (uint32_t)unspents[(i << 1)]; + value = unspents[(i << 1) + 1]; + jaddinum(item,hdrsi); + jaddinum(item,unspentind); + jaddinum(item,dstr(value)); + jaddi(array,item); + } + item = cJSON_CreateObject(); + jadd(item,"unspents",array); + jaddnum(item,"numunspents",numunspents); + jaddnum(item,"balance",dstr(avail)); + jadd(retjson,coin->symbol,item); } + if ( unspents != 0 ) + free(unspents); } + //portable_mutex_unlock(&Allcoins_mutex); return(retjson); } @@ -497,8 +503,7 @@ int32_t is_valid_BTCother(char *other) uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume,cJSON *argjson) { - char *str,*retstr,coinaddr[64]; int32_t added; uint64_t txid = 0; cJSON *json=0; struct instantdex_accept *ap; - struct supernet_info *myinfo; uint8_t pubkey[33]; struct iguana_info *other; + char *str,*retstr,coinaddr[64]; int32_t added; uint64_t txid = 0; cJSON *json=0; struct instantdex_accept *ap; struct supernet_info *myinfo; struct iguana_info *other; myinfo = SuperNET_MYINFO(0);//SuperNET_accountfind(argjson); //printf("TRADE with myinfo.%p\n",myinfo); if ( retstrp != 0 ) @@ -522,8 +527,8 @@ uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,cha { if ( (other= iguana_coinfind(base)) != 0 ) { - bitcoin_pubkey33(0,pubkey,myinfo->persistent_priv); - bitcoin_address(coinaddr,other->chain->pubtype,pubkey,sizeof(pubkey)); + //bitcoin_pubkey33(0,pubkey,myinfo->persistent_priv); + bitcoin_address(coinaddr,other->chain->pubtype,myinfo->persistent_pubkey33,33); jaddstr(argjson,base,coinaddr); } else if ( strcmp(base,"NXT") == 0 || (is_decimalstr(base) > 0 && strlen(base) > 13) ) diff --git a/iguana/exchanges777.h b/iguana/exchanges777.h index da54f13a8..82803a5d5 100755 --- a/iguana/exchanges777.h +++ b/iguana/exchanges777.h @@ -49,6 +49,7 @@ #define EXCHANGES777_DEFAULT_TIMEOUT 30 typedef void CURL; struct exchange_info; +struct exchange_quote; struct exchange_funcs { diff --git a/iguana/iguana.sources b/iguana/iguana.sources index ccfd37f3d..295f0fdf3 100755 --- a/iguana/iguana.sources +++ b/iguana/iguana.sources @@ -1,2 +1,2 @@ -SOURCES := SuperNET.c iguana_bundles.c iguana_stake.c iguana_interpreter.c mini-gmp.c main.c iguana_payments.c iguana_spendvectors.c iguana_sign.c iguana_txidfind.c iguana_realtime.c iguana_volatiles.c peggy_price.c SuperNET_category.c iguana_chains.c iguana_ramchain.c iguana_secp.c pangea_api.c peggy_ramkv.c SuperNET_hexmsg.c iguana_exchanges.c iguana_recv.c pangea_bets.c peggy_serdes.c SuperNET_keys.c iguana_rpc.c pangea_hand.c peggy_tx.c cards777.c iguana_init.c iguana_scripts.c pangea_json.c peggy_txind.c iguana777.c iguana_instantdex.c iguana_tradebots.c pangea_summary.c peggy_update.c iguana_accept.c iguana_json.c iguana_tx.c peggy.c poker.c iguana_bitmap.c iguana_msg.c iguana_unspents.c peggy_accts.c ramchain_api.c iguana_blocks.c iguana_peers.c iguana_wallet.c peggy_consensus.c ../basilisk/basilisk.c ../basilisk/basilisk_privatechains.c secp256k1/src/secp256k1.c \ No newline at end of file +SOURCES := iguana_bundles.c iguana_stake.c iguana_interpreter.c mini-gmp.c main.c iguana_payments.c iguana_spendvectors.c iguana_sign.c iguana_txidfind.c iguana_realtime.c iguana_volatiles.c peggy_price.c iguana_chains.c iguana_ramchain.c iguana_secp.c pangea_api.c peggy_ramkv.c iguana_exchanges.c iguana_recv.c pangea_bets.c peggy_serdes.c SuperNET_keys.c iguana_rpc.c pangea_hand.c peggy_tx.c cards777.c iguana_init.c iguana_scripts.c pangea_json.c peggy_txind.c iguana777.c iguana_instantdex.c iguana_tradebots.c pangea_summary.c peggy_update.c iguana_accept.c iguana_json.c iguana_tx.c peggy.c poker.c iguana_bitmap.c iguana_msg.c iguana_unspents.c peggy_accts.c ramchain_api.c iguana_blocks.c iguana_peers.c iguana_wallet.c peggy_consensus.c ../gecko/gecko.c ../basilisk/basilisk.c secp256k1/src/secp256k1.c \ No newline at end of file diff --git a/iguana/iguana777.c b/iguana/iguana777.c index e72b095d0..64681ea83 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -22,89 +22,66 @@ const char *Hardcoded_coins[][3] = { { "BTC", "bitcoin", "0" }, { "BTCD", "BitcoinDark", "129" }, { "VPN", "VPNcoin", "129" }, { "LTC", "litecoin", "129" } , { "endmarker", "", "" } }; -struct iguana_info *iguana_coinfind(const char *symbol) +struct iguana_info *iguana_coinfind(char *symbol) { - int32_t i; - for (i=0; iallcoins_being_added != 0 ) { - if ( Coins[i] != 0 && strcmp(Coins[i]->symbol,symbol) == 0 ) - return(Coins[i]); + printf("wait for coinadd to complete, OK if rare\n"); + sleep(1); } - return(0); + symbolcrc = calc_crc32(0,symbol,(int32_t)strlen(symbol)); + HASH_FIND(hh,myinfo->allcoins,&symbolcrc,sizeof(coin->symbolcrc),coin); + return(coin); } -struct iguana_info *iguana_coinadd(const char *symbol,cJSON *argjson) +struct iguana_info *iguana_coinadd(char *symbol,char *name,cJSON *argjson) { - struct iguana_info *coin; int32_t i = 0; - if ( symbol == 0 ) + struct iguana_info *coin,*tmp; uint32_t symbolcrc; char *privatechain; int32_t j; struct supernet_info *myinfo = SuperNET_MYINFO(0); + if ( (coin= iguana_coinfind(symbol)) == 0 ) { - for (i=0; iallcoins_mutex); + if ( (coin= iguana_coinfind(symbol)) == 0 ) { - if ( Coins[i] == 0 ) + myinfo->allcoins_being_added = 1; + coin = mycalloc('C',1,sizeof(*coin)); + coin->blockspacesize = IGUANA_MAXPACKETSIZE + 8192; + coin->blockspace = calloc(1,coin->blockspacesize); + coin->peers = calloc(1,sizeof(*coin->peers)); + for (j=0; j %p\n",Coins[i]); - basilisk_functions(Coins[i],IGUANA_PROTOCOL_BITCOIN); - return(Coins[i]); - } return(0); - printf("i.%d (%s) vs name.(%s)\n",i,Coins[i]->name,symbol); + coin->peers->active[j].usock = -1; + strcpy(coin->peers->active[j].coinname,name); + strcpy(coin->peers->active[j].symbol,symbol); + } + if ( (coin->protocol= juint(argjson,"protocol")) == 0 ) + coin->protocol = IGUANA_PROTOCOL_BITCOIN; + coin->ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); + secp256k1_pedersen_context_initialize(coin->ctx); + secp256k1_rangeproof_context_initialize(coin->ctx); + strcpy(coin->name,name); + strcpy(coin->symbol,symbol); + if ( (privatechain= jstr(argjson,"privatechain")) != 0 && privatechain[0] != 0 ) + { + myinfo->allcoins_numvirts++; + coin->virtualchain = 1; + } else coin->chain = iguana_chainfind((char *)symbol,argjson,1); + iguana_initcoin(coin,argjson); + basilisk_functions(coin,coin->protocol); + printf("ADD ALLCOINS.(%s) name.(%s) size %ld numvirts.%d\n",symbol,name,sizeof(*coin),myinfo->allcoins_numvirts); + coin->symbolcrc = symbolcrc = calc_crc32(0,symbol,(int32_t)strlen(symbol)); + HASH_ADD(hh,myinfo->allcoins,symbolcrc,sizeof(coin->symbolcrc),coin); + myinfo->allcoins_being_added = 0; } - } - else - { - for (i=0; iallcoins_mutex); + HASH_ITER(hh,myinfo->allcoins,coin,tmp) { - if ( i >= sizeof(Hardcoded_coins)/sizeof(*Hardcoded_coins) ) - break; - //printf("Hardcoded_coins[i][0] %s vs.(%s)\n",Hardcoded_coins[i][0],symbol); - //if ( symbol[0] == 0 ) - // getchar(); - if ( strcmp("endmarker",Hardcoded_coins[i][0]) == 0 || strcmp(symbol,Hardcoded_coins[i][0]) == 0 ) - { - if ( Coins[i] == 0 ) - { - Coins[i] = mycalloc('C',1,sizeof(*Coins[i]) + sizeof(struct iguana_zcashRO)); - basilisk_functions(Coins[i],IGUANA_PROTOCOL_BITCOIN); - } - coin = Coins[i]; - if ( coin->chain == 0 ) - { - if ( i < sizeof(Hardcoded_coins)/sizeof(*Hardcoded_coins) ) - strcpy(coin->name,Hardcoded_coins[i][1]); - else if (argjson != 0 ) - { - if ( jstr(argjson,"name") != 0 ) - safecopy(coin->name,jstr(argjson,"name"),sizeof(coin->name)); - else strcpy(coin->name,symbol); - } - if ( jstr(argjson,"privatechain") != 0 ) - coin->virtualchain = 1; - coin->chain = iguana_chainfind((char *)symbol,argjson,1); - coin->ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - secp256k1_pedersen_context_initialize(coin->ctx); - secp256k1_rangeproof_context_initialize(coin->ctx); - strcpy(coin->symbol,symbol); - iguana_initcoin(coin,argjson); - } - return(coin); - } + printf("HASH_ITER.(%s)\n",coin->symbol); } + if ( (coin= iguana_coinfind(symbol)) == 0 ) + printf("error finding justadded.(%s)\n",symbol); } - return(0); -} - -struct iguana_info *iguana_coinselect() -{ - int32_t i; - for (i=0; isymbol[0] != 0 && Coins[i]->bundlescount > 0 ) - return(Coins[i]); - } - return(0); + return(coin); } void iguana_recvalloc(struct iguana_info *coin,int32_t numitems) @@ -153,7 +130,7 @@ int32_t iguana_inv2poll(struct supernet_info *myinfo,struct iguana_info *coin) struct exchange_info *exchange; int32_t i,n=0; struct iguana_peer *addr; char myipaddr[64]; expand_ipbits(myipaddr,myinfo->myaddr.myipbits); //printf("iguana_inv2poll exchange.%p %s maxpeers.%d\n",exchanges777_find("bitcoin"),coin->symbol,coin->MAXPEERS); - if ( coin != 0 && (exchange= exchanges777_find("bitcoin")) != 0 && strcmp(coin->symbol,"BTCD") == 0 ) + if ( coin != 0 && coin->peers != 0 && (exchange= exchanges777_find("bitcoin")) != 0 && strcmp(coin->symbol,"BTCD") == 0 ) { if ( time(NULL) > coin->lastinv2+10 ) { @@ -568,8 +545,8 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert void iguana_helper(void *arg) { static int32_t maxhelperid; - cJSON *argjson=0; int32_t iter,i,n,j,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0; - struct iguana_helper *ptr; struct iguana_info *coin; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp; + cJSON *argjson=0; int32_t iter,n,j,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0; + struct iguana_helper *ptr; struct iguana_info *coin,*tmp; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp; struct supernet_info *myinfo = SuperNET_MYINFO(0); if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 ) helperid = juint(argjson,"helperid"); if ( helperid > maxhelperid ) @@ -594,20 +571,19 @@ void iguana_helper(void *arg) flag = 0; allcurrent = 2; polltimeout = 100; - for (i=0; iallcoins,coin,tmp) { - if ( (coin= Coins[i]) != 0 ) + if ( coin->spendvectorsaved == 1 ) + iguana_utxogen(coin,helperid,0); + else if ( coin->spendvectorsaved > 1 ) { - if ( coin->spendvectorsaved == 1 ) - iguana_utxogen(coin,helperid,0); - else if ( coin->spendvectorsaved > 1 ) - { - for (j=helperid; jbundlescount-1; j+=IGUANA_NUMHELPERS) - if ( (bp= coin->bundles[j]) != 0 ) - iguana_bundlevalidate(coin,bp,0); - } + for (j=helperid; jbundlescount-1; j+=IGUANA_NUMHELPERS) + if ( (bp= coin->bundles[j]) != 0 ) + iguana_bundlevalidate(coin,bp,0); } } + //portable_mutex_unlock(&Allcoins_mutex); n = queue_size(&bundlesQ); for (iter=0; iterpeers == 0 ) { - coin->peers = calloc(1,sizeof(*coin->peers)); - for (j=0; jpeers->active[j].usock = -1; + printf("FATAL lack of peers struct\n"); + exit(-1); iguana_launchpeer(coin,"127.0.0.1"); } if ( coin->virtualchain == 0 ) @@ -740,6 +715,8 @@ void iguana_coinloop(void *arg) coin->polltimeout = 100; if ( coin->MAXPEERS > IGUANA_MINPEERS ) coin->MAXPEERS = IGUANA_MINPEERS; + if ( strcmp("BTCD",coin->symbol) == 0 ) + basilisk_geckogenesis(myinfo,coin,0,0,GENESIS_PUBKEY,0,0); } if ( coin->isRT != 0 && coin->current != 0 && coin->numverified >= coin->current->hdrsi ) { @@ -801,13 +778,30 @@ void iguana_coinargs(char *symbol,int64_t *maxrecvcachep,int32_t *minconfirmsp,i *servicesp = j64bits(json,"services"); } -struct iguana_info *iguana_setcoin(struct supernet_info *myinfo,char *symbol,void *launched,int32_t maxpeers,int64_t maxrecvcache,uint64_t services,int32_t initialheight,int32_t maphash,int32_t minconfirms,int32_t maxrequests,int32_t maxbundles,cJSON *json) +void iguana_nameset(char name[64],char *symbol,cJSON *json) +{ + if ( strcmp("BTC",symbol) == 0 ) + strcpy(name,"Bitcoin"); + else if ( strcmp("BTCD",symbol) == 0 ) + strcpy(name,"BitcoinDark"); + else + { + name[0] = 0; + if ( json != 0 ) + safecopy(name,jstr(json,"name"),64); + if ( name[0] == 0 ) + strcpy(name,symbol); + } +} + +struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,int64_t maxrecvcache,uint64_t services,int32_t initialheight,int32_t maphash,int32_t minconfirms,int32_t maxrequests,int32_t maxbundles,cJSON *json) { struct iguana_chain *iguana_createchain(cJSON *json); - struct iguana_info *coin; int32_t j,m,mult,maxval,mapflags; char dirname[512]; cJSON *peers; + struct iguana_info *coin; int32_t j,m,mult,maxval,mapflags; char dirname[512],name[64]; cJSON *peers; mapflags = IGUANA_MAPRECVDATA | maphash*IGUANA_MAPTXIDITEMS | maphash*IGUANA_MAPPKITEMS | maphash*IGUANA_MAPBLOCKITEMS | maphash*IGUANA_MAPPEERITEMS; + iguana_nameset(name,symbol,json); if ( (coin= iguana_coinfind(symbol)) == 0 ) - coin = iguana_coinadd(symbol,json); + coin = iguana_coinadd(symbol,name,json); mult = (strcmp("BTC",coin->symbol) != 0) ? 8 : 32; maxval = IGUANA_MAXPENDBUNDLES; if ( coin->virtualchain == 0 ) @@ -891,7 +885,7 @@ struct iguana_info *iguana_setcoin(struct supernet_info *myinfo,char *symbol,voi strcpy(coin->name,"illegalcoin"); coin->symbol[0] = 0; return(0); - } //else iguana_chainparms(coin->chain,json); + } if ( jobj(json,"RELAY") != 0 ) coin->RELAYNODE = juint(json,"RELAY"); else coin->RELAYNODE = (strcmp(coin->symbol,"BTCD") == 0); @@ -899,7 +893,7 @@ struct iguana_info *iguana_setcoin(struct supernet_info *myinfo,char *symbol,voi coin->VALIDATENODE = juint(json,"VALIDATE"); else coin->VALIDATENODE = (strcmp(coin->symbol,"BTCD") == 0); if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 ) - myinfo->IAMRELAY++; + SuperNET_MYINFO(0)->IAMRELAY++; #ifdef __PNACL coin->VALIDATENODE = coin->RELAYNODE = 0; #endif @@ -923,14 +917,14 @@ struct iguana_info *iguana_setcoin(struct supernet_info *myinfo,char *symbol,voi int32_t iguana_launchcoin(struct supernet_info *myinfo,char *symbol,cJSON *json) { - int32_t maxpeers,maphash,initialheight,minconfirms,maxrequests,maxbundles; - int64_t maxrecvcache; uint64_t services; struct iguana_info **coins,*coin; + int32_t maxpeers,maphash,initialheight,minconfirms,maxrequests,maxbundles; char name[64]; int64_t maxrecvcache; uint64_t services; struct iguana_info **coins,*coin; if ( symbol == 0 ) return(-1); if ( (coin= iguana_coinfind(symbol)) != 0 ) return(0); - printf("launchcoin.%s\n",symbol); - if ( (coin= iguana_coinadd(symbol,json)) == 0 ) + iguana_nameset(name,symbol,json); + printf("launchcoin.%s name.%s\n",symbol,name); + if ( (coin= iguana_coinadd(symbol,name,json)) == 0 ) return(-1); if ( myinfo->rpcsymbol[0] == 0 || iguana_coinfind(myinfo->rpcsymbol) == 0 ) strcpy(myinfo->rpcsymbol,symbol); @@ -941,11 +935,11 @@ int32_t iguana_launchcoin(struct supernet_info *myinfo,char *symbol,cJSON *json) else maphash = 0; iguana_coinargs(symbol,&maxrecvcache,&minconfirms,&maxpeers,&initialheight,&services,&maxrequests,&maxbundles,json); coins = mycalloc('A',1+1,sizeof(*coins)); - if ( (coin= iguana_setcoin(myinfo,symbol,coins,maxpeers,maxrecvcache,services,initialheight,maphash,minconfirms,maxrequests,maxbundles,json)) != 0 ) + if ( (coin= iguana_setcoin(symbol,coins,maxpeers,maxrecvcache,services,initialheight,maphash,minconfirms,maxrequests,maxbundles,json)) != 0 ) { coins[0] = (void *)((long)1); coins[1] = coin; - printf("launch coinloop for.%s services.%llx started.%p peers.%p\n",coin->symbol,(long long)services,coin->started,coin->peers); + printf("launch.%p coinloop for.%s services.%llx started.%p peers.%p\n",coin,coin->symbol,(long long)services,coin->started,coin->peers); coin->launched = iguana_launch(coin,"iguana_coinloop",iguana_coinloop,coins,IGUANA_PERMTHREAD); coin->active = 1; coin->started = 0; @@ -975,7 +969,7 @@ void iguana_coins(void *arg) if ( (symbol= jstr(json,"coin")) != 0 && strncmp(symbol,"BTC",3) == 0 ) { coins = mycalloc('A',1+1,sizeof(*coins)); - if ( (coins[1]= iguana_setcoin(myinfo,symbol,coins,0,0,0,0,0,0,0,0,json)) != 0 ) + if ( (coins[1]= iguana_setcoin(symbol,coins,0,0,0,0,0,0,0,0,json)) != 0 ) { _iguana_calcrmd160(coins[1],&V); coins[0] = (void *)((long)1); @@ -1003,7 +997,7 @@ void iguana_coins(void *arg) continue; } iguana_coinargs(symbol,&maxrecvcache,&minconfirms,&maxpeers,&initialheight,&services,&maxrequests,&maxbundles,item); - coins[1 + i] = coin = iguana_setcoin(myinfo,symbol,coins,maxpeers,maxrecvcache,services,initialheight,maphash,minconfirms,maxrequests,maxbundles,item); + coins[1 + i] = coin = iguana_setcoin(symbol,coins,maxpeers,maxrecvcache,services,initialheight,maphash,minconfirms,maxrequests,maxbundles,item); if ( coin == 0 ) { printf("iguana_coins: couldnt initialize.(%s)\n",symbol); diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 0ad703adb..7a2f25393 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -15,1087 +15,19 @@ #ifndef iguana777_net_h #define iguana777_net_h -#include "../crypto777/OS_portable.h" -#include "SuperNET.h" -#include "../basilisk/basilisk.h" - -#define SPARSECOUNT(x) ((x) << 1) - -typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t len); - -#define IGUANA_MAXSCRIPTSIZE 10001 -#define IGUANA_SERIALIZE_SPENDVECTORGEN -//#define IGUANA_DISABLEPEERS -#define _IGUANA_MAXSTUCKTIME 10 -#ifdef __PNACL__ -#define IGUANA_MAXITERATIONS 77 -#else -#define IGUANA_MAXITERATIONS 10000 -#endif -#define IGUANA_DEFAULTLAG 30 - -#define IGUANA_MAXHEIGHT (1 << 30) -#define IGUANA_MAXCOINS 64 -#define IGUANA_MAXDELAY_MILLIS (3600 * 1000 * 24) -#define IGUANA_DEFAULT_POLLTIMEOUT 10 - -#define IGUANA_EXCHANGEIDLE 10 -#define IGUANS_JSMILLIS 100 - -#define IGUANA_WIDTH 1024 -#define IGUANA_HEIGHT 200 - -#define IGUANA_HEADPERCENTAGE 0. -#define IGUANA_TAILPERCENTAGE 1.0 -#define IGUANA_MAXPENDHDRS 1 -#define IGUANA_MAXPENDINGREQUESTS 8 -#define IGUANA_PENDINGREQUESTS 500 -#define IGUANA_MINPENDBUNDLES 4 -#define IGUANA_MAXPENDBUNDLES 64 -#ifdef __APPLE__ -#define IGUANA_RPCPORT 7778 -#else -#define IGUANA_RPCPORT 7778 -#endif -#define IGUANA_MAXRAMCHAINSIZE ((uint64_t)1024L * 1024L * 1024L * 16) - -#define IGUANA_MAPHASHTABLES 1 -#define IGUANA_DEFAULTRAM 4 -#define IGUANA_MAXRECVCACHE ((int64_t)1024L * 1024 * 1024L) -#define IGUANA_MAXBUNDLES (50000000 / 500) - -#define IGUANA_MINPEERS 24 -#define IGUANA_LOG2MAXPEERS 10 -#define IGUANA_LOG2PACKETSIZE 21 -#define IGUANA_LOG2PEERFILESIZE 23 - -#define IGUANA_MAXPEERS (1 << IGUANA_LOG2MAXPEERS) -#define IGUANA_MAXPACKETSIZE (1 << IGUANA_LOG2PACKETSIZE) -#define IGUANA_PEERFILESIZE (1 << IGUANA_LOG2PEERFILESIZE) -struct iguana_txdatabits { uint64_t addrind:IGUANA_LOG2MAXPEERS,filecount:10,fpos:IGUANA_LOG2PEERFILESIZE,datalen:IGUANA_LOG2PACKETSIZE,isdir:1; }; - -#define IGUANA_MAXFILEITEMS 8192 -#define IGUANA_RECENTPEER (3600 * 24 * 7) - -#define IGUANA_PERMTHREAD 0 -#define IGUANA_CONNTHREAD 1 -#define IGUANA_SENDTHREAD 2 -#define IGUANA_RECVTHREAD 3 -#define IGUANA_HELPERTHREAD 4 -#define IGUANA_EXCHANGETHREAD 5 - -#define IGUANA_DEDICATED_THREADS -#ifdef IGUANA_DEDICATED_THREADS -#define IGUANA_MAXCONNTHREADS 128 -#define IGUANA_MAXSENDTHREADS (IGUANA_MAXPEERS>>2) -#define IGUANA_MAXRECVTHREADS (IGUANA_MAXPEERS>>2) -#else -#define IGUANA_MAXCONNTHREADS 16 -#define IGUANA_MAXSENDTHREADS 16 -#define IGUANA_MAXRECVTHREADS 16 -#endif - -#define IGUANA_SUBDIRDIVISOR 28000 -#define NTARGETSPACING 60 - -#define IGUANA_PROTOCOL_BITCOIN 'b' -#define IGUANA_PROTOCOL_NXT 'n' -#define IGUANA_PROTOCOL_ETHER 'e' -#define IGUANA_PROTOCOL_LISK 'l' -#define IGUANA_PROTOCOL_WAVES 'w' -#define IGUANA_PROTOCOL_IOTA 'i' - -#ifdef __PNACL -void PNACL_message(const char* format, ...); -#endif - -extern int32_t IGUANA_NUMHELPERS; - -#ifdef __PNACL -#define printf PNACL_message -#define MS_ASYNC 1 /* Sync memory asynchronously. */ -#define MS_SYNC 4 /* Synchronous memory sync. */ -#else -#define PNACL_message printf -#endif - -#ifndef MSG_NOSIGNAL -#define MSG_NOSIGNAL 0x4000 // Do not generate SIGPIPE -#endif - -#define BIP0031_VERSION 60000 -#define CADDR_TIME_VERSION 31402 -#define MIN_PROTO_VERSION 209 -#define MAX_BLOCK_SIZE 1000000 -#define COINBASE_MATURITY 100 - -#define _IGUANA_HDRSCOUNT 2000 -#define _IGUANA_BLOCKHASHES 500 -#define IGUANA_MAXBUNDLESIZE _IGUANA_HDRSCOUNT - -#define NODE_NETWORK (1 << 0) -#define NODE_GETUTXO (1 << 1) -#define NODE_BLOOM (1 << 2) - -#define PROTOCOL_VERSION 70002 -#define INIT_PROTO_VERSION 209 // initial proto version, to be increased after version/verack negotiation -#define GETHEADERS_VERSION 31800 // In this version, 'getheaders' was introduced. -#define MIN_PEER_PROTO_VERSION GETHEADERS_VERSION // disconnect from peers older than this proto version -// nTime field added to CAddress, starting with this version, if possible, avoid requesting addresses nodes older than this -#define CADDR_TIME_VERSION 31402 -// only request blocks from nodes outside this range of versions -#define NOBLKS_VERSION_START 32000 -#define NOBLKS_VERSION_END 32400 - -#define BIP0031_VERSION 60000 // BIP 0031, pong message, is enabled for all versions AFTER this one -#define MEMPOOL_GD_VERSION 60002 // "mempool" command, enhanced "getdata" behavior starts with this version -#define NO_BLOOM_VERSION 70011 // "filter*" disabled without NODE_BLOOM after and including this version -#define PROTOCOL_HEADERS_VERSION 70012 - -#define MSG_TX 1 -#define MSG_BLOCK 2 -#define MSG_FILTERED_BLOCK 3 -#define MSG_QUOTE 253 -#define MSG_BUNDLE 254 -#define MSG_BUNDLE_HEADERS 255 - -#define IGUANA_MAXLOCATORS 64 -#define IGUANA_MAXINV 50000 - -#define IGUANA_VOLATILE 1 -#define IGUANA_ITEMIND_DATA 2 -#define IGUANA_MAPPED_ITEM 4 -#define IGUANA_SHA256 0x80 -#define IGUANA_ALLOC_MULT 1.1 -#define IGUANA_ALLOC_INCR 1000 - -#define IGUANA_JSONTIMEOUT 10000 - -#define IGUANA_MAPRECVDATA 1 -#define IGUANA_MAPTXIDITEMS 2 -#define IGUANA_MAPPKITEMS 4 -#define IGUANA_MAPBLOCKITEMS 8 -#define IGUANA_MAPPEERITEMS 16 - -#define IGUANA_PEER_ELIGIBLE 1 -#define IGUANA_PEER_CONNECTING 2 -#define IGUANA_PEER_READY 3 -#define IGUANA_PEER_KILLED 4 - -//#define CHAIN_BTCD 0 -//#define CHAIN_TESTNET3 1 -//#define CHAIN_BITCOIN 2 -//#define CHAIN_VPN 3 - -#define IGUANA_SEARCHBUNDLE 1 -#define IGUANA_SEARCHNOLAST (IGUANA_SEARCHBUNDLE | 2) -#define IGUANA_SEARCHPREV 4 -#define IGUANA_SEARCHNEXT 8 -#define IGUANA_SEARCHALL (IGUANA_SEARCHBUNDLE | IGUANA_SEARCHPREV | IGUANA_SEARCHNEXT) - - -typedef void (*iguana_func)(void *); -struct iguana_thread -{ - struct queueitem DL; - pthread_t handle; - struct iguana_info *coin; - char name[16]; - uint8_t type; - iguana_func funcp; - void *arg; -}; - -struct iguana_blockreq { struct queueitem DL; bits256 hash2,*blockhashes; struct iguana_bundle *bp; int32_t n,height,bundlei; }; - -struct iguana_peermsgrequest { struct queueitem DL; struct iguana_peer *addr; bits256 hash2; int32_t type; }; - -struct iguana_chain -{ - //const int32_t chain_id; - char name[32],symbol[8],messagemagic[64]; - uint8_t pubtype,p2shtype,wiftype,netmagic[4]; - char *genesis_hash,*genesis_hex; // hex string - uint16_t portp2p,rpcport; - uint8_t txhastimestamp,unitval; - uint64_t rewards[512][2]; - uint8_t genesis_hashdata[32],minconfirms; - uint16_t ramchainport,bundlesize,hasheaders; - char gethdrsmsg[16]; - uint64_t txfee,minoutput,dust; - blockhashfunc hashalgo; - char userhome[512],serverport[128],userpass[1024]; - char use_addmultisig,do_opreturn; - int32_t estblocktime,protover; - bits256 genesishash2,PoWtarget,PoStargets[16]; int32_t numPoStargets,PoSheights[16]; - uint8_t zcash,auxpow,alertpubkey[65]; - uint16_t targetspacing,targettimespan; uint32_t nBits; -}; - -struct iguana_msgaddress { uint32_t nTime; uint64_t nServices; uint8_t ip[16]; uint16_t port; } __attribute__((packed)); - -struct iguana_msgversion -{ - uint32_t nVersion; - uint64_t nServices; - int64_t nTime; - struct iguana_msgaddress addrTo,addrFrom; - uint64_t nonce; - char strSubVer[80]; - uint32_t nStartingHeight; - uint8_t relayflag; -} __attribute__((packed)); - -struct iguana_msgalert // warning, many varints/variable length fields, struct is 1:1 -{ - int32_t version; - int64_t relayuntil,expiration; - int32_t ID,cancel; - uint32_t numcancellist; - int32_t minver,maxver; - uint32_t setsubvervar; char subver[1024]; - int32_t priority; - char comment[1024],statusbar[1024],reserved[1024]; - uint8_t siglen,sig[74]; - uint32_t list[64]; -}; - -struct iguana_VPNversion -{ - uint32_t nVersion; - uint64_t nServices; - int64_t nTime; - struct iguana_msgaddress addrTo,addrFrom; - uint64_t nonce; - char strSubVer[80]; - uint32_t nStartingHeight; - uint32_t iVer,v_Network_id; uint16_t wPort; uint8_t bIsGui; uint16_t wCtPort,wPrPort; -} __attribute__((packed)); - -struct iguana_msgblockhdr -{ - uint32_t version; - bits256 prev_block,merkle_root; - uint32_t timestamp,bits,nonce; -} __attribute__((packed)); - -#define ZKSNARK_PROOF_SIZE 584 -#define ZCASH_SOLUTION_ELEMENTS 32 - -struct iguana_msgblockhdr_zcash -{ - bits256 bignonce; - uint8_t numelements; - uint32_t solution[ZCASH_SOLUTION_ELEMENTS]; - //bits256 reserved; // only here if auxpow is set -} __attribute__((packed)); - -struct iguana_msgmerkle -{ - uint32_t branch_length; - bits256 branch_hash[4096]; - uint32_t branch_side_mask; -} __attribute__((packed)); - -struct iguana_msgblock -{ - struct iguana_msgblockhdr H; // double hashed for blockhash - struct iguana_msgblockhdr_zcash zH; - uint32_t txn_count; -} __attribute__((packed)); - -struct iguana_msgvin { bits256 prev_hash; uint8_t *vinscript,*spendscript,*redeemscript; uint32_t prev_vout,sequence; uint16_t scriptlen,p2shlen,suffixlen,spendlen; } __attribute__((packed)); - -struct iguana_msgvout { uint64_t value; uint32_t pk_scriptlen; uint8_t *pk_script; } __attribute__((packed)); - -struct iguana_msgtx -{ - uint32_t version,tx_in,tx_out,lock_time; - struct iguana_msgvin *vins; - struct iguana_msgvout *vouts; - bits256 txid; - int32_t allocsize,timestamp; -} __attribute__((packed)); - -struct iguana_msgjoinsplit -{ - uint64_t vpub_old,vpub_new; - bits256 anchor,nullifiers[2],commitments[2],ephemeralkey; - uint8_t ciphertexts[2][217]; - bits256 randomseed,vmacs[2]; - uint8_t zkproof[ZKSNARK_PROOF_SIZE-1]; -} __attribute__((packed)); - -struct iguana_packet { struct queueitem DL; struct iguana_peer *addr; struct tai embargo; int32_t datalen,getdatablock; uint8_t serialized[]; }; - -struct msgcounts { uint32_t version,verack,getaddr,addr,inv,getdata,notfound,getblocks,getheaders,headers,tx,block,mempool,ping,pong,reject,filterload,filteradd,filterclear,merkleblock,alert; }; - -struct iguana_fileitem { bits256 hash2; struct iguana_txdatabits txdatabits; }; - -struct iguana_kvitem { UT_hash_handle hh; uint8_t keyvalue[]; };// __attribute__((packed)); - -struct iguana_iAddr -{ - UT_hash_handle hh; uint64_t ipbits; - uint32_t lastkilled,lastconnect; - int32_t status,height,numkilled,numconnects; -}; - -struct iguana_cacheptr { struct queueitem DL; int32_t allocsize,recvlen; uint8_t *data; }; - -// iguana blocks -struct iguana_blockRO -{ - bits256 hash2,prev_block,merkle_root; - uint32_t timestamp,nonce,bits,version; - uint32_t firsttxidind,firstvin,firstvout,firstpkind,firstexternalind,recvlen:24,tbd:8; - uint16_t txn_count,numvouts,numvins,allocsize; -} __attribute__((packed)); - -struct iguana_zcashRO { bits256 bignonce; uint32_t solution[ZCASH_SOLUTION_ELEMENTS]; } __attribute__((packed)); -struct iguana_zblockRO -{ - struct iguana_blockRO RO; - struct iguana_zcashRO zRO; -} __attribute__((packed)); +struct supernet_info; +struct exchange_info; -#define iguana_blockfields double PoW; \ - int32_t height,fpos; uint32_t fpipbits,issued,lag:20,peerid:12; \ - uint16_t hdrsi:15,mainchain:1,bundlei:11,valid:1,queued:1,txvalid:1,newtx:1,processed:1; \ - UT_hash_handle hh; struct iguana_bundlereq *req; \ - struct iguana_blockRO RO - -struct iguana_block -{ - iguana_blockfields; - struct iguana_zcashRO zRO[]; -} __attribute__((packed)); - -struct iguana_zblock // mu -{ - iguana_blockfields; - struct iguana_zcashRO zRO; -} __attribute__((packed)); - -#define IGUANA_LHASH_BLOCKS 0 -#define IGUANA_LHASH_TXIDS 1 // -#define IGUANA_LHASH_UNSPENTS 2 // -#define IGUANA_LHASH_SPENDS 3 // -#define IGUANA_LHASH_PKHASHES 4 // -#define IGUANA_LHASH_ACCOUNTS 5 // -#define IGUANA_LHASH_EXTERNALS 6 // -#define IGUANA_LHASH_KSPACE 7 // -#define IGUANA_LHASH_TXBITS 8 // -#define IGUANA_LHASH_PKBITS 9 // -#define IGUANA_NUMLHASHES (IGUANA_LHASH_PKBITS + 1) - -struct iguana_counts -{ - uint32_t firsttxidind,firstunspentind,firstspendind,firstpkind; - uint64_t credits,debits; - struct iguana_block block; -} __attribute__((packed)); - -struct iguana_blocks -{ - char coin[8]; - struct iguanakv *db; - struct iguana_block *hash; //struct iguana_blockRO *RO; int32_t maxbits; - int32_t maxblocks,initblocks,hashblocks,pending,issuedblocks,recvblocks,emitblocks,parsedblocks,dirty; - struct iguana_zblock hwmchain; -}; - -struct iguana_ledger -{ - struct iguana_counts snapshot; - //struct iguana_account accounts[]; -} __attribute__((packed)); - -// ramchain temp file structures -struct iguana_unspent20 { uint64_t value; uint32_t scriptpos,txidind:28,type:4; uint16_t scriptlen,fileid; uint8_t rmd160[20]; } __attribute__((packed)); -struct iguana_spend256 { bits256 prevhash2; uint64_t scriptpos:48,vinscriptlen:16; uint32_t sequenceid; int16_t prevout; uint16_t spendind,fileid; } __attribute__((packed)); - -// permanent readonly structs -struct iguana_txid { bits256 txid; uint32_t txidind:29,firstvout:28,firstvin:28,bundlei:11,locktime,version,timestamp,extraoffset; uint16_t numvouts,numvins; } __attribute__((packed)); - -struct iguana_unspent { uint64_t value; uint32_t txidind,pkind,prevunspentind,scriptpos; uint16_t scriptlen,hdrsi; uint16_t fileid:11,type:5; int16_t vout; } __attribute__((packed)); - -struct iguana_spend { uint64_t scriptpos:48,scriptlen:16; uint32_t spendtxidind,sequenceid; int16_t prevout; uint16_t fileid:15,external:1; } __attribute__((packed)); // numsigs:4,numpubkeys:4,p2sh:1,sighash:4 - -struct iguana_pkhash { uint8_t rmd160[20]; uint32_t pkind; } __attribute__((packed)); //firstunspentind,pubkeyoffset - -// dynamic -struct iguana_account { int64_t total; uint32_t lastunspentind; } __attribute__((packed)); -struct iguana_utxo { uint32_t fromheight:31,lockedflag:1,prevunspentind:31,spentflag:1; } __attribute__((packed)); -struct iguana_hhaccount { UT_hash_handle hh; uint64_t pval; struct iguana_account a; } __attribute__((packed)); -struct iguana_hhutxo { UT_hash_handle hh; uint64_t uval; struct iguana_utxo u; } __attribute__((packed)); - -// GLOBAL one zero to non-zero write (unless reorg) -struct iguana_spendvector { uint64_t value; uint32_t pkind,unspentind; int32_t fromheight; uint16_t hdrsi:15,tmpflag:1; } __attribute__((packed)); // unspentind -//struct iguana_pkextra { uint32_t firstspendind; } __attribute__((packed)); // pkind - -struct iguana_txblock -{ - uint32_t numtxids,numunspents,numspends,extralen,recvlen; - // following set during second pass (still in peer context) - uint32_t numpkinds,numexternaltxids,datalen,pkoffset; - uint8_t space[256]; // order: extra[], T, U, S, P, external txids - struct iguana_zblock zblock; -}; - -#define RAMCHAIN_PTR(rdata,offset) ((void *)(long)((long)(rdata) + (long)(rdata)->offset)) -struct iguana_ramchaindata -{ - bits256 sha256; - bits256 lhashes[IGUANA_NUMLHASHES],firsthash2,prevhash2; - int64_t allocsize,Boffset,Toffset,Uoffset,Soffset,Poffset,Aoffset,Xoffset,TXoffset,PKoffset,Koffset; - int32_t numblocks,height,firsti,hdrsi,txsparsebits,pksparsebits; - uint32_t numtxids,numunspents,numspends,numpkinds,numexternaltxids,numtxsparse,numpksparse,scriptspace,stackspace; - uint8_t rdata[]; -}; - -struct iguana_ramchain_hdr -{ - uint32_t txidind,unspentind,spendind,scriptoffset,stacksize; uint16_t hdrsi,bundlei:15,ROflag:1; - struct iguana_ramchaindata *data; -}; - -struct iguana_ramchain -{ - struct iguana_ramchain_hdr H; bits256 lasthash2; uint64_t datasize,allocatedA2,allocatedU2; - uint32_t numblocks:31,expanded:1,pkind,externalind,height,numXspends; - long sparseadds,sparsesearches,sparseadditers,sparsesearchiters,sparsehits,sparsemax; - struct iguana_kvitem *txids,*pkhashes; - struct OS_memspace *hashmem; long filesize,sigsfilesize,debitsfilesize,lastspendsfilesize; - void *fileptr,*sigsfileptr,*Xspendptr,*debitsfileptr,*lastspendsfileptr; - char from_ro,from_roX,from_roA,from_roU; - struct iguana_account *A,*A2,*creditsA; struct iguana_spendvector *Xspendinds; - struct iguana_utxo *Uextras; uint8_t *txbits; struct iguana_txid *cacheT; - //int16_t permutation[IGUANA_MAXBUNDLES]; -//struct iguana_Uextra *U2,*roU2; struct iguana_pkextra *P2,*roP2; -}; - -struct iguana_peer -{ - struct queueitem DL; - queue_t sendQ; - bits256 iphash,pubkey,persistent; uint32_t lastpersist; uint8_t netmagic[4]; - struct iguana_msgaddress A; - char ipaddr[64],lastcommand[16],coinstr[16],symbol[16]; - uint64_t pingnonce,totalsent,totalrecv,ipbits; double pingtime,sendmillis,pingsum,getdatamillis; - uint32_t lastcontact,sendtime,ready,startsend,startrecv,pending,lastgotaddr,lastblockrecv,pendtime,lastflush,lastpoll,myipbits,persistent_peer,protover; - int32_t supernet,basilisk,dead,addrind,usock,lastheight,relayflag,numpackets,numpings,ipv6,height,rank,pendhdrs,pendblocks,recvhdrs,lastlefti,validpub,othervalid,dirty[2],laggard,headerserror; - double recvblocks,recvtotal; - int64_t allocated,freed; - bits256 RThashes[IGUANA_MAXBUNDLESIZE]; int32_t numRThashes; - struct msgcounts msgcounts; - struct OS_memspace RAWMEM,TXDATA,HASHMEM; - struct iguana_ramchain ramchain; - struct iguana_fileitem *filehash2; int32_t numfilehash2,maxfilehash2; - //struct iguana_bundle *bp; - FILE *voutsfp,*vinsfp; - uint8_t *blockspace;//[IGUANA_MAXPACKETSIZE + 8192]; -#ifdef IGUANA_PEERALLOC - struct OS_memspace *SEROUT[128]; -#endif -}; - -struct iguana_peers -{ - bits256 lastrequest; - struct iguana_peer active[IGUANA_MAXPEERS+1],*ranked[IGUANA_MAXPEERS+1],*localaddr; - struct iguana_thread *peersloop,*recvloop; pthread_t *acceptloop; - double topmetrics[IGUANA_MAXPEERS+1],avemetric; - long vinptrs[IGUANA_MAXPEERS+1][2],voutptrs[IGUANA_MAXPEERS+1][2]; - uint32_t numranked,mostreceived,shuttingdown,lastpeer,lastmetrics,numconnected; - int32_t numfiles; -}; - -struct iguana_bloom16 { uint8_t hash2bits[65536 / 8]; }; -struct iguana_bloominds { uint16_t inds[8]; }; - -struct iguana_bundle -{ - struct queueitem DL; struct iguana_info *coin; struct iguana_bundle *nextbp; - struct iguana_bloom16 bloom; int64_t totaldurations,duplicatedurations; int32_t durationscount,duplicatescount; - uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime,queued,startutxo,utxofinish,balancefinish,validated,lastspeculative,dirty,nexttime,currenttime,lastprefetch,lastRT,missingstime,unsticktime,converted; - int32_t numhashes,numrecv,numsaved,numcached,generrs,currentflag,origmissings,numissued,Xvalid; - int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents,numspec,isRT; - double avetime,threshold,metric; uint64_t datasize,estsize; - struct iguana_block *blocks[IGUANA_MAXBUNDLESIZE]; - uint8_t *speculativecache[IGUANA_MAXBUNDLESIZE],haveblock[IGUANA_MAXBUNDLESIZE/3+1]; - uint32_t issued[IGUANA_MAXBUNDLESIZE]; - bits256 prevbundlehash2,hashes[IGUANA_MAXBUNDLESIZE+1],nextbundlehash2,allhash,*speculative,validatehash; - struct iguana_ramchain ramchain; uint8_t red,green,blue; - struct iguana_spendvector *tmpspends; int32_t numtmpspends; -}; - -struct iguana_bundlereq -{ - struct queueitem DL; struct iguana_info *coin; int32_t type; - struct iguana_peer *addr; struct iguana_zblock *blocks; bits256 *hashes,txid; - struct iguana_txdatabits txdatabits; - struct iguana_msghdr H; - int32_t allocsize,datalen,n,recvlen,numtx; uint32_t ipbits; - struct iguana_zblock zblock; - uint8_t copyflag,serializeddata[]; -}; - -struct iguana_bitmap { int32_t width,height,amplitude; char name[52]; uint8_t data[IGUANA_WIDTH*IGUANA_HEIGHT*3]; }; - -struct iguana_waddress { UT_hash_handle hh; uint64_t balance,*unspents; uint32_t maxunspents,numunspents; uint16_t scriptlen; uint8_t rmd160[20],pubkey[33],wiftype,addrtype; bits256 privkey; char symbol[8],coinaddr[36],wifstr[54]; uint8_t redeemScript[]; }; -struct iguana_waccount { UT_hash_handle hh; char account[128]; struct iguana_waddress *waddr,*current; }; -struct iguana_wallet { UT_hash_handle hh; struct iguana_waccount *wacct; }; - -struct scriptinfo { UT_hash_handle hh; uint32_t fpos; uint16_t scriptlen; uint8_t script[]; }; -struct hhbits256 { UT_hash_handle hh; bits256 txid; int32_t height; uint16_t firstvout; }; - -struct iguana_monitorinfo { bits256 txid; int32_t numreported; uint8_t peerbits[IGUANA_MAXPEERS >> 3]; }; - -typedef void *(*basilisk_func)(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *vals); -typedef double (*basilisk_metricfunc)(struct supernet_info *myinfo,struct basilisk_item *ptr,char *result); - -struct iguana_info -{ - char name[64],symbol[64],protocol,statusstr[512],scriptsfname[2][512]; - struct iguana_peers *peers; struct iguana_peer internaladdr; - basilisk_func basilisk_rawtx,basilisk_balances,basilisk_value; - basilisk_metricfunc basilisk_rawtxmetric,basilisk_balancesmetric,basilisk_valuemetric; - - uint32_t fastfind; FILE *fastfps[0x100]; uint8_t *fast[0x100]; int32_t *fasttables[0x100]; long fastsizes[0x100]; - uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime; - int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,PREFETCHLAG,estsize,activebundles; - int32_t MAXPEERS,MAXPENDINGREQUESTS,MAXBUNDLES,MAXSTUCKTIME,active,closestbundle,numemitted,lastsweep,numemit,startutc,newramchain,numcached,cachefreed,helperdepth,startPEND,endPEND,enableCACHE,RELAYNODE,VALIDATENODE,origbalanceswritten,balanceswritten,RTheight,RTdatabad; - bits256 balancehash,allbundles; - uint32_t lastsync,parsetime,numiAddrs,lastpossible,bundlescount,savedblocks,backlog,spendvectorsaved,laststats,lastinv2; char VALIDATEDIR[512]; - int32_t longestchain,badlongestchain,longestchain_strange,RTramchain_busy,emitbusy,stuckiters,virtualchain; - struct tai starttime; double startmillis; - struct iguana_chain *chain; - struct iguana_iAddr *iAddrs; - void *ctx; - struct iguana_bitmap *screen; - struct OS_memspace TXMEM,MEM,MEMB[IGUANA_MAXBUNDLESIZE]; - queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,cacheQ,recvQ,msgrequestQ; - double parsemillis,avetime; uint32_t Launched[8],Terminated[8]; - portable_mutex_t peers_mutex,blocks_mutex; - char changeaddr[64]; - struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending; - struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem; bits256 RThash1; - int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle,numsaved,pendbalances,numverified,blockdepth; - uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,firstRTgenesis,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime,RThdrstime,nextchecked; - double bandwidth,maxbandwidth,backstopmillis; bits256 backstophash2; int64_t spaceused; - int32_t initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids,allhashes,balanceflush; bits256 reqtxids[64]; - void *launched,*started,*rpcloop; - uint64_t bloomsearches,bloomhits,bloomfalse,collisions,txfee_perkb,txfee; - uint8_t blockspace[IGUANA_MAXPACKETSIZE + 8192]; struct OS_memspace blockMEM; - bits256 APIblockhash,APItxid; char *APIblockstr; - struct iguana_hhutxo *utxotable; struct iguana_hhaccount *accountstable; char lastdispstr[2048]; - double txidfind_totalmillis,txidfind_num,spendtxid_totalmillis,spendtxid_num; - struct iguana_monitorinfo monitoring[256]; - struct basilisk_sequences SEQ; - struct iguana_blocks blocks; -}; - -struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; }; - -struct vin_info -{ - struct iguana_msgvin vin; uint64_t amount; cJSON *extras; bits256 sigtxid; - int32_t M,N,validmask,spendlen,type,p2shlen,suffixlen,numpubkeys,numsigs,height,hashtype; - uint32_t sequence,unspentind; struct vin_signer signers[16]; char coinaddr[65]; - uint8_t rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE],p2shscript[IGUANA_MAXSCRIPTSIZE]; -}; - -struct bitcoin_unspent -{ - bits256 txid,privkeys[16]; uint64_t value; int32_t vout,spendlen,p2shlen,numpubkeys; uint32_t sequence; - uint8_t addrtype,rmd160[20],pubkeys[16][65],spendscript[IGUANA_MAXSCRIPTSIZE],p2shscript[IGUANA_MAXSCRIPTSIZE]; -}; - -struct bitcoin_spend -{ - char changeaddr[64]; uint8_t change160[20]; - int32_t numinputs; - int64_t txfee,input_satoshis,satoshis,change; - struct bitcoin_unspent inputs[]; -}; - -// peers -int32_t iguana_verifypeer(struct iguana_info *coin,void *key,void *value,int32_t itemind,int32_t itemsize); -int32_t iguana_peermetrics(struct supernet_info *myinfo,struct iguana_info *coin); -void iguana_peersloop(void *arg); -int32_t iguana_queue_send(struct iguana_peer *addr,int32_t delay,uint8_t *serialized,char *cmd,int32_t len); -uint32_t iguana_rwiAddrind(struct iguana_info *coin,int32_t rwflag,struct iguana_iAddr *iA,uint32_t ind); -void iguana_connections(void *arg); -uint32_t iguana_possible_peer(struct iguana_info *coin,char *ip_port); -//int32_t iguana_set_iAddrheight(struct iguana_info *coin,uint32_t ipbits,int32_t height); -//struct iguana_peer *iguana_choosepeer(struct iguana_info *coin); -void iguana_initpeer(struct iguana_info *coin,struct iguana_peer *addr,uint64_t ipbits); -void iguana_startconnection(void *arg); -void iguana_shutdownpeers(struct iguana_info *coin,int32_t forceflag); -void iguana_acceptloop(void *args); -void iguana_recvloop(void *args); -int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *serialized,int32_t len); -uint32_t iguana_updatemetrics(struct supernet_info *myinfo,struct iguana_info *coin); -void *iguana_peeralloc(struct iguana_info *coin,struct iguana_peer *addr,int32_t datalen); -int64_t iguana_peerfree(struct iguana_info *coin,struct iguana_peer *addr,void *ptr,int32_t datalen); -int64_t iguana_peerallocated(struct iguana_info *coin,struct iguana_peer *addr); - -// serdes -int32_t iguana_rwmem(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_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp); -int32_t iguana_rwblock(char *symbol,uint8_t zcash,uint8_t auxpow,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 maxlen); -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(uint8_t zcash,uint8_t auxpow,struct iguana_block *dest,struct iguana_msgblock *msg,bits256 hash2,int32_t height); -//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); - -// send message -int32_t iguana_validatehdr(char *symbol,struct iguana_msghdr *H); -int32_t iguana_sethdr(struct iguana_msghdr *H,const uint8_t netmagic[4],char *command,uint8_t *data,int32_t datalen); -int32_t iguana_send_version(struct iguana_info *coin,struct iguana_peer *addr,uint64_t myservices); -int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struct iguana_txblock *txblock,int32_t *lenp,uint8_t *data,int32_t datalen); -int32_t iguana_gethdrs(struct iguana_info *coin,uint8_t *serialized,char *cmd,char *hashstr); -int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,bits256 *hashes,int32_t n); -void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgblock *msg,struct iguana_block *src,int32_t cleartxn_count); -int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs); -int32_t iguana_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin); - -// ramchain -int64_t iguana_verifyaccount(struct iguana_info *coin,struct iguana_account *acct,uint32_t pkind); -int32_t iguana_initramchain(struct iguana_info *coin,int32_t initialheight,int32_t mapflags,int32_t fullverify); -void iguana_syncramchain(struct iguana_info *coin); -//int32_t iguana_validateramchain(struct iguana_info *coin,int64_t *netp,uint64_t *creditsp,uint64_t *debitsp,int32_t height,struct iguana_block *block,int32_t hwmheight,struct iguana_prevdep *lp); -int32_t iguana_calcrmd160(struct iguana_info *coin,char *asmstr,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence); -uint32_t iguana_updatescript(struct iguana_info *coin,uint32_t blocknum,uint32_t txidind,uint32_t spendind,uint32_t unspentind,uint64_t value,uint8_t *script,int32_t scriptlen,uint32_t sequence); -void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *txdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t datalen); -int32_t iguana_parseblock(struct iguana_info *coin,struct iguana_block *block,struct iguana_msgtx *tx,int32_t numtx); -uint32_t iguana_txidind(struct iguana_info *coin,uint32_t *firstvoutp,uint32_t *firstvinp,bits256 txid); -bits256 iguana_txidstr(struct iguana_info *coin,uint32_t *firstvoutp,uint32_t *firstvinp,char *txidstr,uint32_t txidind); -int32_t iguana_updateramchain(struct iguana_info *coin); -//void iguana_emittxarray(struct iguana_info *coin,FILE *fp,struct iguana_bundle *bundle,struct iguana_block *block,struct iguana_msgtx *txarray,int32_t numtx); - -// blockchain -int32_t iguana_needhdrs(struct iguana_info *coin); -struct iguana_chain *iguana_chainfind(char *name,cJSON *argjson,int32_t createflag); -int32_t iguana_chainextend(struct iguana_info *coin,struct iguana_block *newblock); -uint64_t iguana_miningreward(struct iguana_info *coin,uint32_t blocknum); - -// tx -int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin); -void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *txids,int32_t n); -void iguana_gotquotesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *quotes,int32_t n); -void iguana_gotunconfirmedM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msgtx *tx,uint8_t *data,int32_t datalen); -void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *blockhashes,int32_t n); - -// blocks -bits256 iguana_blockhash(struct iguana_info *coin,int32_t height); -#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_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,int32_t targetspacing,int32_t targettimespan); - -uint32_t iguana_syncs(struct iguana_info *coin); -void iguana_gotdata(struct iguana_info *coin,struct iguana_peer *addr,int32_t height); -//int64_t iguana_getbalance(struct iguana_info *coin,uint64_t *creditsp,uint64_t *debitsp,int32_t *nump,uint32_t *unspents,long max,struct iguana_pkhash *P,uint32_t pkind); -int32_t iguana_queueblock(struct iguana_info *coin,int32_t height,bits256 hash2,int32_t priority); -int32_t iguana_updatewaiting(struct iguana_info *coin,int32_t starti,int32_t max); - -// recvbits -int32_t iguana_recvinit(struct iguana_info *coin,int32_t initialheight); -int32_t ramcoder_decompress(uint8_t *data,int32_t maxlen,uint8_t *bits,uint32_t numbits,bits256 seed); -int32_t ramcoder_compress(uint8_t *bits,int32_t maxlen,uint8_t *data,int32_t datalen,bits256 seed); -uint64_t hconv_bitlen(uint64_t bitlen); -struct iguana_block *iguana_blockptr(char *debugstr,struct iguana_info *coin,int32_t height); -int32_t iguana_processrecv(struct supernet_info *myinfo,struct iguana_info *coin); // single threaded -//void iguana_recvalloc(struct iguana_info *coin,int32_t numitems); -void iguana_coins(void *arg); -int32_t iguana_savehdrs(struct iguana_info *coin); - -// hdrs -struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bundleip,int32_t bundleheight,bits256 bundlehash2,bits256 allhash,int32_t issueflag); -struct iguana_block *iguana_updatehdrs(struct iguana_info *coin,int32_t *newhwmp,struct iguana_block *block,bits256 prevhash2,bits256 hash2); -void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp); -void iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_zblock *zblocks,int32_t n); -void iguana_emittxdata(struct iguana_info *coin,struct iguana_bundle *bp); -int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr); -int32_t iguana_avail(struct iguana_info *coin,int32_t height,int32_t n); -int32_t iguana_updatebundles(struct iguana_info *coin); -void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag); -void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson); -void iguana_coinargs(char *symbol,int64_t *maxrecvcachep,int32_t *minconfirmsp,int32_t *maxpeersp,int32_t *initialheightp,uint64_t *servicesp,int32_t *maxrequestsp,int32_t *maxbundlesp,cJSON *json); -struct iguana_info *iguana_setcoin(struct supernet_info *myinfo,char *symbol,void *launched,int32_t maxpeers,int64_t maxrecvcache,uint64_t services,int32_t initialheight,int32_t maphash,int32_t minconfirms,int32_t maxrequests,int32_t maxbundles,cJSON *json); - -// init -struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialheight,int32_t mapflags); -void iguana_callcoinstart(struct iguana_info *coin); -void iguana_initcoin(struct iguana_info *coin,cJSON *argjson); -void iguana_coinloop(void *arg); - -// utils -double PoW_from_compact(uint32_t nBits,uint8_t unitval); -void calc_rmd160(char *hexstr,uint8_t buf[20],uint8_t *msg,int32_t len); -void calc_OP_HASH160(char *hexstr,uint8_t hash160[20],char *msg); -double dxblend(double *destp,double val,double decay); - -// json -int32_t iguana_processjsonQ(struct iguana_info *coin); // reentrant, can be called during any idletime -char *iguana_JSON(char *,uint16_t port); -char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen,int32_t compressed); - -char *mbstr(char *str,double); -int init_hexbytes_noT(char *hexbytes,unsigned char *message,long len); -int32_t decode_hex(unsigned char *bytes,int32_t n,char *hex); -char hexbyte(int32_t c); -char *clonestr(char *str); -long _stripwhite(char *buf,int accept); -int32_t myatoi(char *str,int32_t range); -int32_t safecopy(char *dest,char *src,long len); -void escape_code(char *escaped,char *str); -int32_t is_zeroes(char *str); -int64_t conv_floatstr(char *numstr); -int32_t has_backslash(char *str); - -struct iguana_thread *iguana_launch(struct iguana_info *coin,char *name,iguana_func funcp,void *arg,uint8_t type); -int32_t iguana_numthreads(struct iguana_info *coin,int32_t mask); -void iguana_terminator(void *arg); - -int32_t is_hexstr(char *str,int32_t n); -void iguana_initQ(queue_t *Q,char *name); -void iguana_emitQ(struct iguana_info *coin,struct iguana_bundle *bp); -void iguana_txdataQ(struct iguana_info *coin,struct iguana_peer *addr,FILE *fp,long fpos,int32_t datalen); -void iguana_helper(void *arg); - -struct iguana_helper { struct queueitem DL; void *coin,*addr,*bp,*nextbp,*fp; long fpos; int32_t allocsize,type,hdrsi,bundlei,datalen,timelimit; uint32_t starttime; }; -int32_t iguana_helpertask(FILE *fp,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_helper *ptr); -void iguana_flushQ(struct iguana_info *coin,struct iguana_peer *addr); -//struct iguana_txdatabits iguana_peerfilePT(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2,struct iguana_txdatabits txdatabits,int32_t recvlen); -struct iguana_txdatabits iguana_calctxidbits(uint32_t addrind,uint32_t filecount,uint32_t fpos,uint32_t datalen); -int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,uint32_t starttime); // helper thread -int32_t iguana_bundlemergeHT(char *fname,struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,struct iguana_bundle *nextbp,uint32_t starttime); // helper thread - -void iguana_peerfilename(struct iguana_info *coin,char *fname,uint32_t addrind,uint32_t filecount); - -struct iguana_txblock *iguana_ramchainptrs(struct iguana_txid **Tptrp,struct iguana_unspent20 **Uptrp,struct iguana_spend256 **Sptrp,struct iguana_pkhash **Pptrp,bits256 **externalTptrp,struct OS_memspace *mem,struct iguana_txblock *origtxdata); - -int32_t iguana_ramchainsave(struct iguana_info *coin,struct iguana_ramchain *ramchain); -int32_t iguana_ramchainfree(struct iguana_info *coin,struct OS_memspace *mem,struct iguana_ramchain *ramchain); -struct iguana_ramchain *iguana_ramchainmergeHT(struct iguana_info *coin,struct OS_memspace *mem,struct iguana_ramchain *ramchains[],int32_t n,struct iguana_bundle *bp); -void iguana_ramchainmerge(struct iguana_info *coin); - -int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t priority); -void iguana_blockcopy(uint8_t zcash,uint8_t auxpow,struct iguana_info *coin,struct iguana_block *block,struct iguana_block *origblock); -int32_t iguana_rpctest(struct iguana_info *coin); -extern queue_t helperQ; -extern const char *Hardcoded_coins[][3]; -void iguana_main(void *arg); -extern struct iguana_info *Coins[64]; -int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,char *fname,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t numblocks,int32_t dispflag); -struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundleip,char *fname,struct OS_memspace *mem,uint32_t ipbits,bits256 hash2); -int32_t iguana_peerfile_exists(struct iguana_info *coin,struct iguana_peer *addr,char *dirname,char *fname,bits256 hash2,bits256 prevhash2,int32_t numblocks); -struct iguana_ramchain *iguana_ramchainset(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_txblock *txdata); -void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA); -long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,int32_t txn_count,uint8_t *data,int32_t recvlen); -int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blockp,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2); -struct iguana_block *iguana_bundleblockadd(struct iguana_info *coin,struct iguana_bundle **bpp,int32_t *bundleip,struct iguana_block *origblock); -int32_t iguana_chainextend(struct iguana_info *coin,struct iguana_block *newblock); -int32_t iguana_blockvalidate(struct iguana_info *coin,int32_t *validp,struct iguana_block *block,int32_t dispflag); -char *iguana_bundledisp(struct iguana_info *coin,struct iguana_bundle *prevbp,struct iguana_bundle *bp,struct iguana_bundle *nextbp,int32_t m); -struct iguana_bundle *iguana_bundlefind(struct iguana_info *coin,struct iguana_bundle **bpp,int32_t *bundleip,bits256 hash2); -//int32_t iguana_chainheight(struct iguana_info *coin,struct iguana_block *origblock); -bits256 *iguana_blockhashptr(struct iguana_info *coin,int32_t height); -int32_t iguana_hash2set(struct iguana_info *coin,char *debugstr,struct iguana_bundle *bp,int32_t bundlei,bits256 newhash2); -struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_block *newblock); -int32_t iguana_hashfree(struct iguana_kvitem *hashtable,int32_t freeitem); -int32_t iguana_processbundlesQ(struct iguana_info *coin,int32_t *newhwmp); // single threaded -int32_t iguana_ramchainverifyPT(struct iguana_info *coin,struct iguana_ramchain *ramchain); -void *map_file(char *fname,long *filesizep,int32_t enablewrite); -void iguana_rpcloop(void *args); -int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port); -void iguana_mergeQ(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_bundle *nextbp); - -#define bits256_nonz(a) (((a).ulongs[0] | (a).ulongs[1] | (a).ulongs[2] | (a).ulongs[3]) != 0) -//int32_t btc_addr2univ(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr); - -struct iguana_agent -{ - char name[32],hostname[64]; void *methods; uint16_t port; int32_t sock,nummethods; - bits256 pubkey,privkey; - char *(*parsefunc)(struct iguana_agent *agent,char *method,void *json,char *remoteaddr); -}; - -int32_t iguana_txbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts); -int32_t iguana_vinset(struct iguana_info *coin,uint8_t *scriptspace,int32_t height,struct iguana_msgvin *vin,struct iguana_txid *tx,int32_t i); -int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmstr,int32_t height,struct iguana_msgvout *vout,struct iguana_txid *tx,int32_t i); -//int32_t btc_convrmd160(char *coinaddr,uint8_t addrtype,uint8_t rmd160[20]); -struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_txid *tx,int32_t txidind); -int32_t iguana_txidreq(struct iguana_info *coin,char **retstrp,bits256 txid); -void iguana_bundleiclear(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei); -int32_t hcalc_bitsize(uint64_t x); -struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,struct iguana_txid *tx,bits256 txid,int32_t lasthdrsi); -int32_t iguana_scriptgen(struct iguana_info *coin,int32_t *Mp,int32_t *nump,char *coinaddr,uint8_t *script,char *asmstr,uint8_t rmd160[20],uint8_t type,const struct vin_info *vp,int32_t txi); -int32_t iguana_ramchain_spendtxid(struct iguana_info *coin,uint32_t *unspentindp,bits256 *txidp,struct iguana_txid *T,int32_t numtxids,bits256 *X,int32_t numexternaltxids,struct iguana_spend *s); -struct iguana_info *iguana_coinselect(); -void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr); -struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int32_t forceflag); -void iguana_dedicatedglue(void *arg); -void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag); -void SuperNET_yourip(struct supernet_info *myinfo,char *yourip); -void iguana_peerkill(struct iguana_info *coin); -int32_t blockhash_sha256(uint8_t *blockhashp,uint8_t *serialized,int32_t len); - -char *busdata_sync(uint32_t *noncep,char *jsonstr,char *broadcastmode,char *destNXTaddr); -void peggy(); -int32_t opreturns_init(uint32_t blocknum,uint32_t blocktimestamp,char *path); -struct iguana_info *iguana_coinfind(const char *symbol); -struct iguana_info *iguana_coinadd(const char *symbol,cJSON *json); -struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int32_t extraflag); -int32_t iguana_sendblockreq(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe); -int32_t iguana_send_supernet(struct iguana_peer *addr,char *jsonstr,int32_t delay); - -struct iguana_waccount *iguana_waccountfind(struct supernet_info *myinfo,struct iguana_info *coin,char *account); -struct iguana_waddress *iguana_waccountadd(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount **wacctp,char *walletaccount,char *coinaddr); -struct iguana_waddress *iguana_waccountswitch(struct supernet_info *myinfo,struct iguana_info *coin,char *account,char *coinaddr,char *redeemScript); -struct iguana_waddress *iguana_waddresscalc(struct supernet_info *myinfo,uint8_t pubval,uint8_t wiftype,struct iguana_waddress *addr,bits256 privkey); -struct iguana_waddress *iguana_waddressfind(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,char *coinaddr); -char *iguana_coinjson(struct iguana_info *coin,char *method,cJSON *json); -cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly); -//int32_t btc_priv2wif(char *wifstr,uint8_t privkey[32],uint8_t addrtype); -//int32_t btc_pub2rmd(uint8_t rmd160[20],uint8_t pubkey[33]); -int32_t iguana_launchcoin(struct supernet_info *myinfo,char *symbol,cJSON *json); -int32_t iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1); -int32_t iguana_jsonQ(); -int32_t is_bitcoinrpc(struct supernet_info *myinfo,char *method,char *remoteaddr); -char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr,uint16_t port); -cJSON *iguana_pubkeyjson(struct iguana_info *coin,char *pubkeystr); -void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit); -int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,int32_t timelimit,int32_t lag); -void ramcoder_test(void *data,int64_t len); -void iguana_exit(); -int32_t iguana_pendingaccept(struct iguana_info *coin); -char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t tag,int32_t maxmillis,char *remoteaddr,uint16_t port); -void iguana_iAkill(struct iguana_info *coin,struct iguana_peer *addr,int32_t markflag); -cJSON *SuperNET_bits2json(uint8_t *serialized,int32_t datalen); -int32_t SuperNET_sendmsg(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,bits256 destpub,bits256 mypriv,bits256 mypub,uint8_t *msg,int32_t len,uint8_t *data,int32_t delaymillis); -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_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype); -bits256 iguana_chaingenesis(char *symbol,uint8_t zcash,uint8_t auxpow,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); -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_rawtxbytes(struct iguana_info *coin,cJSON *json,struct iguana_msgtx *msgtx); -int32_t iguana_send_VPNversion(struct iguana_info *coin,struct iguana_peer *addr,uint64_t myservices); -void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sleepflag); -int32_t iguana_rwvout(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvout *msg); -int32_t iguana_rwvin(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvin *msg); -int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins); -int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts,int32_t validatesigs); -cJSON *bitcoin_txtest(struct iguana_info *coin,char *rawtxstr,bits256 txid); -cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag); -int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct iguana_msgblock *msg); -//int32_t iguana_sig(uint8_t *sig,int32_t maxsize,uint8_t *data,int32_t datalen,bits256 privkey); -//int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,bits256 pubkey); -//int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,uint8_t *pubkey); -void calc_rmd160_sha256(uint8_t rmd160[20],uint8_t *data,int32_t datalen); -int32_t bitcoin_checklocktimeverify(uint8_t *script,int32_t n,uint32_t locktime); -struct bitcoin_spend *iguana_spendset(struct supernet_info *myinfo,struct iguana_info *coin,int64_t amount,int64_t txfee,cJSON *addresses,int32_t minconf); -cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes,uint8_t *extrapace,int32_t extralen,uint8_t *serialized); -cJSON *iguana_signtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,char **signedtxp,struct bitcoin_spend *spend,cJSON *txobj,cJSON *vins); -void iguana_addscript(struct iguana_info *coin,cJSON *dest,uint8_t *script,int32_t scriptlen,char *fieldname); -bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain); - -cJSON *bitcoin_txcreate(int32_t txhastimestamp,int64_t locktime); -cJSON *bitcoin_txoutput(cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t satoshis); -cJSON *bitcoin_txinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys); - -int32_t bitcoin_changescript(struct iguana_info *coin,uint8_t *changescript,int32_t n,uint64_t *changep,char *changeaddr,uint64_t inputsatoshis,uint64_t satoshis,uint64_t txfee); -//cJSON *bitcoin_addinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys); -int32_t bitcoin_verifytx(struct iguana_info *coin,bits256 *signedtxidp,char **signedtx,char *rawtxstr,struct vin_info *V,int32_t numinputs); -int32_t bitcoin_verify(void *ctx,uint8_t *sig,int32_t siglen,bits256 txhash2,uint8_t *pubkey,int32_t plen); -char *bitcoin_json2hex(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,cJSON *txjson,struct vin_info *V); -int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr); -char *issue_startForging(struct supernet_info *myinfo,char *secret); -struct bitcoin_unspent *iguana_unspentsget(struct supernet_info *myinfo,struct iguana_info *coin,char **retstrp,double *balancep,int32_t *numunspentsp,double minconfirms,char *address); -void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson); -int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,int64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp,int32_t maxunspents); -long iguana_spentsfile(struct iguana_info *coin,int32_t n); -uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp,cJSON *array,int32_t firsti); -int64_t iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp); -uint8_t *iguana_walletrmds(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp); -char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi); -uint32_t iguana_sparseaddpk(uint8_t *bits,int32_t width,uint32_t tablesize,uint8_t rmd160[20],struct iguana_pkhash *P,uint32_t pkind,struct iguana_ramchain *ramchain); -int32_t iguana_vinscriptparse(struct iguana_info *coin,struct vin_info *vp,uint32_t *sigsizep,uint32_t *pubkeysizep,uint32_t *p2shsizep,uint32_t *suffixp,uint8_t *vinscript,int32_t scriptlen); -void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len); -int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp); -int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain,int32_t starti,int32_t numblocks,int32_t convertflag,int32_t iterate); -int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t startheight,int32_t endheight,int32_t startemit); -int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag); -void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp); -struct iguana_bloominds iguana_calcbloom(bits256 hash2); -int32_t iguana_bloomfind(struct iguana_info *coin,struct iguana_bloom16 *bloom,int32_t incr,struct iguana_bloominds bit); -struct iguana_bloominds iguana_bloomset(struct iguana_info *coin,struct iguana_bloom16 *bloom,int32_t incr,struct iguana_bloominds bit); -int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp); -//void iguana_balancesQ(struct iguana_info *coin,struct iguana_bundle *bp); -int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi); -int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int32_t starti,int32_t max); -int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight); -int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe); -int32_t iguana_blockreq(struct iguana_info *coin,int32_t height,int32_t priority); -int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t lag); -int32_t iguana_ramchain_prefetch(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t txonly); -int32_t iguana_realtime_update(struct iguana_info *coin); -int32_t iguana_volatilesmap(struct iguana_info *coin,struct iguana_ramchain *ramchain); -void iguana_volatilespurge(struct iguana_info *coin,struct iguana_ramchain *ramchain); -int32_t iguana_volatilesinit(struct iguana_info *coin); -void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle); -int64_t iguana_ramchainopen(char *fname,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,int32_t bundleheight,bits256 hash2); -int32_t iguana_ramchain_free(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t deleteflag); -void iguana_blocksetcounters(struct iguana_info *coin,struct iguana_block *block,struct iguana_ramchain * ramchain); -int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int16_t bundlei); -void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,struct iguana_bundle *bp,int32_t bundlei); -int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_ramchain *mapchain,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block,void *ptr,long filesize); -void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp); -void iguana_RTramchainfree(struct iguana_info *coin,struct iguana_bundle *bp); -void iguana_coinpurge(struct iguana_info *coin); -int32_t iguana_setmaxbundles(struct iguana_info *coin); -void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp); -uint32_t iguana_sparseaddtx(uint8_t *bits,int32_t width,uint32_t tablesize,bits256 txid,struct iguana_txid *T,uint32_t txidind,struct iguana_ramchain *ramchain); -void iguana_launchpeer(struct iguana_info *coin,char *ipaddr); -//void iguana_spendvectorsQ(struct iguana_info *coin,struct iguana_bundle *bp); -int8_t iguana_blockstatus(struct iguana_info *coin,struct iguana_block *block); -int32_t iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,int32_t slotid,uint64_t ipbits); -void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,struct iguana_bundle *bp,int32_t i,int32_t deletefile); -int32_t iguana_reqblocks(struct iguana_info *coin); -void iguana_walletlock(struct supernet_info *myinfo,struct iguana_info *coin); -int32_t _SuperNET_encryptjson(char *destfname,char *passphrase,int32_t passsize,char *fname2fa,int32_t fnamesize,cJSON *argjson); -int32_t bitcoin_pubkeylen(const uint8_t *pubkey); -struct iguana_block *iguana_bundleblock(struct iguana_info *coin,bits256 *hash2p,struct iguana_bundle *bp,int32_t i); -void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *R,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block); -int32_t iguana_bundlehashadd(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block); -int32_t iguana_convert(struct iguana_info *coin,int32_t helperid,struct iguana_bundle *bp,int32_t RTflag,int32_t starti); -int32_t iguana_bundleissuemissing(struct iguana_info *coin,struct iguana_bundle *bp,int32_t priority,double mult); -FILE *myfopen(char *fname,char *mode); -int32_t myfclose(FILE *fp); -int32_t iguana_walkchain(struct iguana_info *coin,int32_t skipflag); -struct iguana_block *iguana_fastlink(struct iguana_info *coin,int32_t hwmheight); -int32_t iguana_balancenormal(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight); -int32_t iguana_spendvectorsaves(struct iguana_info *coin); -int32_t iguana_convertfinished(struct iguana_info *coin); -int32_t iguana_emitfinished(struct iguana_info *coin,int32_t queueincomplete); -int32_t iguana_utxofinished(struct iguana_info *coin); -int32_t iguana_balancefinished(struct iguana_info *coin); -int32_t iguana_alloctxbits(struct iguana_info *coin,struct iguana_ramchain *ramchain); -void iguana_allocvolatile(struct iguana_info *coin,struct iguana_ramchain *ramchain); -int32_t iguana_rwaddr(int32_t rwflag,uint8_t *serialized,struct iguana_msgaddress *addr,int32_t protover); -struct iguana_waddress *iguana_waddresscreate(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,char *coinaddr,char *redeemScript); - -int32_t iguana_peerhdrrequest(struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_peer *addr,bits256 hash2); -int32_t iguana_peeraddrrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max); -int32_t iguana_peerdatarequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max); -int32_t iguana_peergetrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *data,int32_t recvlen,int32_t getblock); -int32_t iguana_bundlefname(struct iguana_info *coin,struct iguana_bundle *bp,char *fname); -int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfiles); -int32_t iguana_voutsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid); -int32_t iguana_vinsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid); -bits256 iguana_merkle(bits256 *tree,int32_t txn_count); -int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag); -int32_t iguana_blast(struct iguana_info *coin,struct iguana_peer *addr); -int32_t iguana_validated(struct iguana_info *coin); -void iguana_volatilesalloc(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t copyflag); -int32_t iguana_send_ping(struct iguana_info *coin,struct iguana_peer *addr); -int32_t iguana_process_msgrequestQ(struct supernet_info *myinfo,struct iguana_info *coin); -uint32_t iguana_fastfindinit(struct iguana_info *coin); -int32_t iguana_unspentindfind(struct iguana_info *coin,char *coinaddr,uint8_t *spendscript,int32_t *scriptlenp,uint64_t *valuep,int32_t *heightp,bits256 txid,int32_t vout,int32_t lasthdrsi); -int32_t iguana_addressvalidate(struct iguana_info *coin,uint8_t *addrtypep,char *address); -int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256 privkey,int32_t recoverflag); -bits256 iguana_str2priv(struct supernet_info *myinfo,struct iguana_info *coin,char *str); -int32_t iguana_spentflag(struct iguana_info *coin,int64_t *RTspendp,int32_t *spentheightp,struct iguana_ramchain *ramchain,int16_t spent_hdrsi,uint32_t spent_unspentind,int32_t height,int32_t minconf,int32_t maxconf,uint64_t amount); -int32_t iguana_voutscript(struct iguana_info *coin,struct iguana_bundle *bp,uint8_t *scriptspace,char *asmstr,struct iguana_unspent *u,struct iguana_pkhash *p,int32_t txi); -cJSON *iguana_unspentjson(struct supernet_info *myinfo,struct iguana_info *coin,int32_t hdrsi,uint32_t unspentind,struct iguana_txid *T,struct iguana_unspent *up,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33); -int32_t bitcoin_standardspend(uint8_t *script,int32_t n,uint8_t rmd160[20]); -struct iguana_waddress *iguana_waddresssearch(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount **wacctp,char *coinaddr); -int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,cJSON *txids,cJSON *vouts,char *coinaddr,int32_t minconf); -cJSON *iguana_walletjson(struct supernet_info *myinfo); -int32_t iguana_payloadupdate(struct supernet_info *myinfo,struct iguana_info *coin,char *retstr,struct iguana_waddress *waddr,char *account); -int32_t bitcoin_MofNspendscript(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,const struct vin_info *vp); -cJSON *iguana_p2shjson(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *retjson,struct iguana_waddress *waddr); -char *setaccount(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waddress **waddrp,char *account,char *coinaddr,char *redeemScript); -char *iguana_APIrequest(struct iguana_info *coin,bits256 blockhash,bits256 txid,int32_t seconds); -int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxsize,struct vin_info *V,int32_t sighash); -int64_t iguana_fastfindcreate(struct iguana_info *coin); -int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr); -int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struct iguana_ramchain *spentchain,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight); -int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight); -int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,int64_t *unspents,int32_t max,int64_t required,int32_t minconf,cJSON *addresses); -int64_t iguana_unspentset(struct supernet_info *myinfo,struct iguana_info *coin); -int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 txid,int32_t lasthdrsi); -uint8_t iguana_addrtype(struct iguana_info *coin,uint8_t script_type); -struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,struct iguana_waddress *addwaddr,char *redeemScript); -cJSON *iguana_createvins(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *txobj,cJSON *vins); -bits256 bitcoin_pubkey33(void *ctx,uint8_t *data,bits256 privkey); -bits256 bitcoin_randkey(void *ctx); -int32_t bitcoin_recoververify(void *ctx,char *symbol,uint8_t *sig64,bits256 messagehash2,uint8_t *pubkey); -int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t script[IGUANA_MAXSCRIPTSIZE],cJSON *scriptobj,int32_t interpret,int64_t nLockTime,struct vin_info *V); -cJSON *iguana_spendasm(struct iguana_info *coin,uint8_t *spendscript,int32_t spendlen); -int64_t iguana_unspentavail(struct iguana_info *coin,uint64_t hdrsi_unspendind,int32_t minconf,int32_t maxconf); -struct iguana_utxo iguana_utxofind(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t spent_unspentind,int32_t *RTspendflagp,int32_t lockflag); -int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeys); -cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins); -char *iguana_inputaddress(struct iguana_info *coin,char *coinaddr,int16_t *spent_hdrsip,uint32_t *unspentindp,cJSON *vinobj); -struct iguana_waddress *iguana_getaccountaddress(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,char *coinaddr,char *account); -int32_t iguana_uvaltxid(struct supernet_info *myinfo,bits256 *txidp,struct iguana_info *coin,int16_t hdrsi,uint32_t unspentind); -struct instantdex_accept *instantdex_quotefind(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,bits256 encodedhash); -int32_t instantdex_quoterequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,struct iguana_peer *addr,bits256 encodedhash); -int32_t instantdex_peerhas_clear(struct iguana_info *coin,struct iguana_peer *addr); -int32_t instantdex_quotep2p(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,uint8_t *serialized,int32_t recvlen); -void instantdex_update(struct supernet_info *myinfo); -cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *account); -int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLockTime,struct vin_info *V,int32_t numvins); -int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_msgvin *vin,cJSON *vinobj,struct vin_info *V); -//int64_t iguana_availunspents(struct supernet_info *myinfo,uint64_t **unspentsp,int32_t *nump,struct iguana_info *coin,int32_t minconf,char *account,void *ptr,int32_t maxsize); -char *iguana_signunspents(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *txobj,uint64_t satoshis,char *changeaddr,uint64_t txfee,uint64_t *unspents,int32_t num); -bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx); -int32_t iguana_inv2packet(uint8_t *serialized,int32_t maxsize,int32_t type,bits256 *hashes,int32_t n); -int32_t instantdex_inv2data(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct exchange_info *exchange); -struct iguana_bundlereq *instantdex_recvquotes(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *encodedhash,int32_t n); -struct exchange_info *exchange_create(char *exchangestr,cJSON *argjson); -int32_t iguana_inv2poll(struct supernet_info *myinfo,struct iguana_info *coin); -struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,uint8_t *data,int32_t datalen); -void instantdex_FSMinit(); -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_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkey); -bits256 scrypt_blockhash(const void *input); -bits256 iguana_calcblockhash(char *symbol,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),uint8_t *serialized,int32_t len); -struct bitcoin_eventitem *instantdex_event(char *cmdstr,cJSON *argjson,cJSON *newjson,uint8_t *serdata,int32_t serdatalen); -void instantdex_eventfree(struct bitcoin_eventitem *ptr); -struct iguana_monitorinfo *iguana_txidmonitor(struct iguana_info *coin,bits256 txid); -struct iguana_monitorinfo *iguana_txidreport(struct iguana_info *coin,bits256 txid,struct iguana_peer *addr); -double iguana_txidstatus(struct iguana_info *coin,bits256 txid); -void basilisk_functions(struct iguana_info *coin,int32_t protocol); -char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *method,char *params); -char *bitcoin_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,int64_t satoshis,char *paymentscriptstr,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf,uint32_t locktime); -char *bitcoin_blockhashstr(char *coinstr,char *serverport,char *userpass,int32_t height); -bits256 basilisk_blockhash(struct iguana_info *coin,bits256 prevhash2); -void calc_scrypthash(uint32_t *hash,void *data); -int32_t iguana_rwvarstr(int32_t rwflag,uint8_t *serialized,int32_t maxlen,char *endianedp); -bits256 bitcoin_sharedsecret(void *ctx,bits256 privkey,uint8_t *pubkey,int32_t plen); -int32_t iguana_blockhdrsize(char *symbol,uint8_t zcash,uint8_t auxpow);//,uint8_t *serialized,int32_t maxlen); -int32_t iguana_blockROsize(uint8_t zcash); -void *iguana_blockzcopyRO(uint8_t zcash,struct iguana_blockRO *dest,int32_t desti,struct iguana_blockRO *src,int32_t srci); -void iguana_blockzcopy(uint8_t zcash,struct iguana_block *dest,struct iguana_block *src); -int32_t iguana_blocksizecheck(char *debugstr,uint8_t zcash,struct iguana_block *block); - -extern int32_t HDRnet,netBLOCKS; - -extern queue_t bundlesQ,emitQ,TerminateQ; -extern char GLOBAL_TMPDIR[],GLOBAL_VALIDATEDIR[],GLOBAL_HELPDIR[],GLOBAL_DBDIR[],GLOBAL_CONFSDIR[]; +#include "../crypto777/OS_portable.h" +#include "../basilisk/basilisk.h" +#include "../gecko/gecko.h" +#include "../includes/iguana_defines.h" +#include "../includes/iguana_types.h" +#include "../includes/iguana_structs.h" +#include "../includes/iguana_funcs.h" +#include "../includes/iguana_globals.h" -#include "../includes/iguana_api.h" #endif diff --git a/iguana/iguana_accept.c b/iguana/iguana_accept.c index cca937e2b..04ee6ebaa 100755 --- a/iguana/iguana_accept.c +++ b/iguana/iguana_accept.c @@ -196,7 +196,7 @@ int32_t iguana_process_msgrequestQ(struct supernet_info *myinfo,struct iguana_in { if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 ) { - if ( (addr= msg->addr) != 0 && (len= iguana_peerblockrequest(coin,coin->blockspace,(int32_t)(sizeof(coin->blockspace) - sizeof(struct iguana_msghdr)),0,msg->hash2,0)) > 0 ) + if ( (addr= msg->addr) != 0 && (len= iguana_peerblockrequest(coin,coin->blockspace,(int32_t)(coin->blockspacesize - sizeof(struct iguana_msghdr)),0,msg->hash2,0)) > 0 ) { //char str[65]; printf("msg Sendlen.%d block %s to %s\n",len,bits256_str(str,msg->hash2),addr->ipaddr); iguana_queue_send(addr,0,coin->blockspace,"block",len); @@ -209,7 +209,7 @@ int32_t iguana_process_msgrequestQ(struct supernet_info *myinfo,struct iguana_in { if ( (tx= iguana_txidfind(coin,&height,&T,msg->hash2,coin->bundlescount-1)) != 0 ) { - if ( (len= iguana_ramtxbytes(coin,&coin->blockspace[sizeof(struct iguana_msghdr)],sizeof(coin->blockspace),&checktxid,tx,height,0,0,0)) > 0 ) + if ( (len= iguana_ramtxbytes(coin,&coin->blockspace[sizeof(struct iguana_msghdr)],coin->blockspacesize,&checktxid,tx,height,0,0,0)) > 0 ) { char str[65],str2[65]; if ( bits256_cmp(msg->hash2,checktxid) == 0 ) @@ -233,7 +233,7 @@ int32_t iguana_process_msgrequestQ(struct supernet_info *myinfo,struct iguana_in } else if ( msg->type == MSG_QUOTE ) { - if ( (len= instantdex_quoterequest(myinfo,coin,&coin->blockspace[sizeof(struct iguana_msghdr)],sizeof(coin->blockspace),msg->addr,msg->hash2)) > 0 ) + if ( (len= instantdex_quoterequest(myinfo,coin,&coin->blockspace[sizeof(struct iguana_msghdr)],coin->blockspacesize,msg->addr,msg->hash2)) > 0 ) { //iguana_sethdr((void *)coin->blockspace,coin->chain->netmagic,"quote",&coin->blockspace[sizeof(struct iguana_msghdr)],len); //iguana_msgparser(coin,msg->addr,0,0,0,(void *)coin->blockspace,&coin->blockspace[sizeof(struct iguana_msghdr)],len); diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index d747d4fa0..f9bdfab09 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -222,9 +222,10 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin if ( prev != 0 ) _iguana_blocklink(coin,prev,block); } - //char str[65]; printf("added.(%s) height.%d (%p %p)\n",bits256_str(str,hash2),height,block->hh.prev,block->hh.next); - if ( 0 ) + //char str[65]; + if ( coin->virtualchain != 0 ) { + //printf("%s added.(%s) height.%d (%p %p)\n",coin->symbol,bits256_str(str,hash2),height,block->hh.prev,block->hh.next); struct iguana_block *tmp; HASH_FIND(hh,coin->blocks.hash,&hash2,sizeof(hash2),tmp); char str[65]; @@ -378,7 +379,7 @@ double PoW_from_compact(uint32_t nBits,uint8_t unitval) // NOT consensus safe, b nbytes = (nBits >> 24) & 0xFF; nbits = (8 * (nbytes - 3)); PoW = (nBits & 0xFFFFFF); - if ( 1 && nbytes > unitval ) + if ( 0 && nbytes > unitval ) { printf("illegal nBits.%x unitval.%02x\n",nBits,unitval); return(0.); @@ -534,6 +535,10 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl bits256 *hash2p=0; double prevPoW = 0.; struct iguana_bundle *bp; if ( newblock == 0 ) return(0); + if ( coin->virtualchain != 0 ) + { + ; + } iguana_blocksizecheck("chainlink new",coin->chain->zcash,newblock); hwmchain = (struct iguana_block *)&coin->blocks.hwmchain; if ( 0 && hwmchain->height > 0 && ((bp= coin->current) == 0 || hwmchain->height/coin->chain->bundlesize > bp->hdrsi+0*bp->isRT) ) @@ -669,7 +674,12 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl return(block); } } - } //else printf("chainlink error from block.%p\n",block); + } + else + { + char str[65]; + printf("chainlink error from block.%p %s\n",block,bits256_str(str,newblock->RO.hash2)); + } return(0); } diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index 407647904..605044871 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -994,7 +994,7 @@ int32_t iguana_bundlefinalize(struct iguana_info *coin,struct iguana_bundle *bp, coin->numemitted++; for (i=0; in; i++) iguana_hash2set(coin,"bundlefinalize",bp,i,bp->hashes[i]); - /*if ( bp->hdrsi == 0 && iguana_peerblockrequest(coin,coin->blockspace,sizeof(coin->blockspace),0,bp->hashes[0],1) > 0 ) + /*if ( bp->hdrsi == 0 && iguana_peerblockrequest(coin,coin->blockspace,coin->blockspacesize,0,bp->hashes[0],1) > 0 ) printf("GENESIS block validated\n"); else printf("GENESIS didnt validate bp.%p\n",bp);*/ //if ( strcmp("BTC",coin->symbol) != 0 ) @@ -1046,7 +1046,7 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru starti = currentbp == 0 ? 0 : currentbp->hdrsi; lasti = lastbp == 0 ? coin->bundlescount-1 : lastbp->hdrsi; iguana_bundlecalcs(coin,bp,lag); - if ( coin->blockdepth == 0 && bp->hdrsi == coin->bundlescount-1 ) + if ( coin->blockdepth == 0 && coin->blockdepth == 0 && bp->hdrsi == coin->bundlescount-1 ) iguana_autoextend(coin,bp); if ( 0 && bp->hdrsi == 0 ) printf("ITER utxo.%u now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",bp->utxofinish,(uint32_t)time(NULL),bp->numspec,bp->bundleheight/coin->chain->bundlesize,bp->numhashes,bp->numrecv,bp->numsaved,bp->emitfinish,timelimit,counter,coin->MAXBUNDLES,coin->bundlescount); @@ -1186,7 +1186,9 @@ void iguana_bundlemissings(struct iguana_info *coin,struct iguana_bundle *bp,uin void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) { int32_t i,n,m,j,numv,numconverted,count,starti,lasti,pending,capacity,displag,numutxo,numbalances,numrecv,done,numhashes,numcached,numsaved,numemit; struct iguana_block *block; bits256 hash2; - int64_t spaceused=0,estsize = 0; struct iguana_bundle *currentbp,*lastbp,*bp,*lastpending = 0,*firstgap = 0; uint32_t now; + int64_t spaceused=0,estsize = 0; struct iguana_bundle *currentbp,*lastbp,*bp,*lastpending = 0,*firstgap = 0; uint32_t now; + if ( coin->bundlescount <= 0 ) + return; now = (uint32_t)time(NULL); displag = (now - coin->lastdisp); numrecv = numhashes = numcached = numconverted = numsaved = numemit = done = numutxo = numbalances = 0; diff --git a/iguana/iguana_chains.c b/iguana/iguana_chains.c index 30b9f6fdd..2b5b503fe 100755 --- a/iguana/iguana_chains.c +++ b/iguana/iguana_chains.c @@ -26,7 +26,7 @@ static struct iguana_chain Chains[] = { - //[CHAIN_TESTNET3] = + /*//[CHAIN_TESTNET3] = { //CHAIN_TESTNET3, "testnet3", "tBTC", "Bitcoin Signed Message:\n", // strMessageMagic @@ -35,7 +35,7 @@ static struct iguana_chain Chains[] = "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943", "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4adae5494dffff001d1aa4ae180101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000", 18333,18334,0, - }, + },*/ //[CHAIN_BITCOIN] = { //CHAIN_BITCOIN, @@ -64,7 +64,7 @@ static struct iguana_chain Chains[] = //iguana_chaingenesis("VPN",0,bits256_conv("00000ac7d764e7119da60d3c832b1d4458da9bc9ef9d5dd0d91a15f690a46d99"),genesisblock,"scrypt",1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN - //[CHAIN_VPN] = + /*//[CHAIN_VPN] = { "VPNcoin", "VPN", "VPNcoin Signed Message:\n", // strMessageMagic 71, 5, 199, // PUBKEY_ADDRESS + SCRIPT_ADDRESS addrman.h, use wif2priv API on any valid wif @@ -75,7 +75,7 @@ static struct iguana_chain Chains[] = 1920,1921,1,0x1e // port and rpcport vpncoin.conf }, - /* //[CHAIN_LTC] = + //[CHAIN_LTC] = { "Litecoin", "LTC", "Litecoin Signed Message:\n", 0, 5, 176, // PUBKEY_ADDRESS + SCRIPT_ADDRESS addrman.h, use wif2priv API on any valid wif @@ -291,18 +291,6 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson) { if ( strcmp(chain->symbol,"BTCD") == 0 ) chain->pubtype = 60, chain->p2shtype = 85; -/* if ( strcmp(chain->symbol,"LTC") == 0 ) - chain->pubtype = 48, chain->p2shtype = 5, chain->minconfirms = 1, chain->txfee = 100000; - else if ( strcmp(chain->symbol,"BTCD") == 0 ) - else if ( strcmp(chain->symbol,"DOGE") == 0 ) - chain->pubtype = 30, chain->p2shtype = 35, chain->txfee = SATOSHIDEN; - else if ( strcmp(chain->symbol,"VRC") == 0 ) - chain->pubtype = 70, chain->p2shtype = 85; - else if ( strcmp(chain->symbol,"OPAL") == 0 ) - chain->pubtype = 115, chain->p2shtype = 28; - else if ( strcmp(chain->symbol,"BITS") == 0 ) - chain->pubtype = 25, chain->p2shtype = 8; - }*/ if ( (chain->minoutput= j64bits(argjson,"minoutput")) == 0 ) chain->minoutput = 10000; chain->minconfirms = juint(argjson,"minconfirms"); @@ -324,20 +312,18 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson) if ( juint(argjson,"p2p") != 0 ) chain->portp2p = juint(argjson,"p2p"); else chain->portp2p = juint(argjson,"portp2p"); - if ( (chain->ramchainport= juint(argjson,"ramchain")) == 0 ) - chain->ramchainport = chain->portp2p - 1; if ( (chain->rpcport= juint(argjson,"rpc")) == 0 ) { if ( chain->portp2p != 0 ) chain->rpcport = chain->portp2p-1; } chain->zcash = juint(argjson,"zcash"); + if ( (chain->normal_txversion= juint(argjson,"normal_txversion")) == 0 ) + chain->normal_txversion = IGUANA_NORMAL_TXVERSION; + if ( (chain->locktime_txversion= juint(argjson,"locktime_txversion")) == 0 ) + chain->locktime_txversion = IGUANA_LOCKTIME_TXVERSION; if ( jobj(argjson,"isPoS") != 0 ) - chain->txhastimestamp = juint(argjson,"isPoS"); - else if ( jobj(argjson,"oldtx_format") != 0 ) - chain->txhastimestamp = !juint(argjson,"oldtx_format"); - else if ( jobj(argjson,"txhastimestamp") != 0 ) - chain->txhastimestamp = !juint(argjson,"txhastimestamp"); + chain->isPoS = juint(argjson,"isPoS"); if ( jstr(argjson,"userhome") != 0 ) strcpy(chain->userhome,jstr(argjson,"userhome")); else strcpy(chain->userhome,Userhome); @@ -391,18 +377,19 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson) memcpy(chain->genesis_hashdata,chain->genesishash2.bytes,32); char str[65]; init_hexbytes_noT(str,chain->genesis_hashdata,32); chain->genesis_hash = clonestr(str); - //chain->genesis_hash = clonestr(bits256_str(str,hash)); chain->genesis_hex = clonestr(genesisblock); } else { if ( (hexstr= jstr(argjson,"genesisblock")) != 0 ) { - uint8_t hexbuf[1024],*ptr,*data; int32_t datalen,hdrsize = (chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr); - chain->genesis_hex = mycalloc('G',1,strlen(hexstr)+1); - strcpy(chain->genesis_hex,hexstr); + uint8_t hexbuf[1024],*ptr,*data; int32_t datalen,hdrsize; + hdrsize = chain->zcash != 0 ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr); + chain->genesis_hex = clonestr(hexstr); data = get_dataptr(&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr); - memcpy(chain->genesis_hashdata,data,hdrsize); + chain->genesishash2 = iguana_calcblockhash(chain->symbol,chain->hashalgo,data,hdrsize); + memcpy(chain->genesis_hashdata,chain->genesishash2.bytes,32); + //char str[65]; printf("%s -> calculated %s from %d datalen\n",hexstr,bits256_str(str,chain->genesishash2),hdrsize); if ( ptr != 0 ) free(ptr); } @@ -427,6 +414,8 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson) void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson) { int32_t i; + if ( chain->hashalgo != 0 ) + return; if ( strcmp(chain->symbol,"BTCD") == 0 ) { chain->numPoStargets = 1; @@ -437,7 +426,6 @@ void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjs chain->PoWtarget = bits256_from_compact(0x1e0fffff); } chain->hasheaders = hasheaders; - //chain->minoutput = 10000; chain->hashalgo = blockhash_sha256; // most all coins seem to use this for blockchain if ( strcmp(chain->symbol,"BTC") == 0 ) { @@ -460,8 +448,6 @@ void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjs chain->bundlesize = _IGUANA_BLOCKHASHES; } decode_hex((uint8_t *)chain->genesis_hashdata,32,(char *)chain->genesis_hash); - if ( chain->ramchainport == 0 ) - chain->ramchainport = chain->portp2p - 1; if ( chain->rpcport == 0 ) chain->rpcport = chain->portp2p + 1; } @@ -472,7 +458,7 @@ struct iguana_chain *iguana_chainfind(char *name,cJSON *argjson,int32_t createfl for (i=0; igenesis_hash,chain->name,name,strcmp(name,chain->name)); + //printf("chain.(%s).%s vs %s.%d\n",chain->genesis_hash,chain->name,name,strcmp(name,chain->name)); if ( chain->name[0] == 0 || chain->genesis_hash == 0 ) { if ( createflag != 0 && argjson != 0 ) @@ -488,7 +474,9 @@ struct iguana_chain *iguana_chainfind(char *name,cJSON *argjson,int32_t createfl return(chain); } } - return NULL; + chain = calloc(1,sizeof(*chain)); + iguana_chaininit(chain,1,argjson); + return(chain); } struct iguana_chain *iguana_findmagic(uint8_t netmagic[4]) diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 6b6881dbf..dcd9048f4 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -51,33 +51,36 @@ void iguana_initpeer(struct iguana_info *coin,struct iguana_peer *addr,uint64_t expand_ipbits(addr->ipaddr,(uint32_t)addr->ipbits); //addr->pending = (uint32_t)time(NULL); strcpy(addr->symbol,coin->symbol); - strcpy(addr->coinstr,coin->name); + strcpy(addr->coinname,coin->name); iguana_initQ(&addr->sendQ,"addrsendQ"); } void iguana_initcoin(struct iguana_info *coin,cJSON *argjson) { int32_t i; char dirname[1024]; - sprintf(dirname,"%s/%s",GLOBAL_TMPDIR,coin->symbol), OS_portable_path(dirname); - portable_mutex_init(&coin->peers_mutex); - portable_mutex_init(&coin->blocks_mutex); - coin->txfee = 10000; - iguana_meminit(&coin->blockMEM,"blockMEM",coin->blockspace,sizeof(coin->blockspace),0); - iguana_initQs(coin); - coin->bindsock = -1; - OS_randombytes((unsigned char *)&coin->instance_nonce,sizeof(coin->instance_nonce)); - coin->startutc = (uint32_t)time(NULL); - while ( time(NULL) == coin->startutc ) - usleep(1); - coin->startutc++; - printf("start.%u\n",coin->startutc); - coin->startmillis = OS_milliseconds(), coin->starttime = tai_now(); - coin->avetime = 1 * 100; - //coin->R.maxrecvbundles = IGUANA_INITIALBUNDLES; - if ( coin->MAXPEERS > 0 ) + if ( coin->instance_nonce == 0 ) { - for (i=0; ipeers->active[i].usock = -1; + sprintf(dirname,"%s/%s",GLOBAL_TMPDIR,coin->symbol), OS_portable_path(dirname); + portable_mutex_init(&coin->peers_mutex); + portable_mutex_init(&coin->blocks_mutex); + coin->txfee = 10000; + iguana_meminit(&coin->blockMEM,"blockMEM",coin->blockspace,coin->blockspacesize,0); + iguana_initQs(coin); + coin->bindsock = -1; + OS_randombytes((unsigned char *)&coin->instance_nonce,sizeof(coin->instance_nonce)); + coin->startutc = (uint32_t)time(NULL); + while ( time(NULL) == coin->startutc ) + usleep(1); + coin->startutc++; + printf("start.%u\n",coin->startutc); + coin->startmillis = OS_milliseconds(), coin->starttime = tai_now(); + coin->avetime = 1 * 100; + //coin->R.maxrecvbundles = IGUANA_INITIALBUNDLES; + if ( coin->MAXPEERS > 0 ) + { + for (i=0; ipeers->active[i].usock = -1; + } } } diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index 6e1624edd..71d3b4d21 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -389,7 +389,7 @@ bits256 instantdex_rwoffer(int32_t rwflag,int32_t *lenp,uint8_t *serialized,stru char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extraser,int32_t extralen,struct iguana_peer *addr,struct bitcoin_swapinfo *swap) { - cJSON *sendjson; char *reqstr,*hexstr,*retstr; struct instantdex_msghdr *msg; bits256 orderhash,tmphash; int32_t i,j,len,dir=0,serflag,olen,slen,datalen; uint8_t *buf,*allocptr,space[4096],serialized[sizeof(*offer) + sizeof(struct iguana_msghdr) + 4096 + INSTANTDEX_DECKSIZE*33]; uint64_t x,nxt64bits; + cJSON *sendjson; char *reqstr; struct instantdex_msghdr *msg; bits256 orderhash,tmphash; int32_t i,j,len,dir=0,serflag,olen,slen,datalen; uint8_t *buf,*allocptr,space[4096],serialized[sizeof(*offer) + sizeof(struct iguana_msghdr) + 4096 + INSTANTDEX_DECKSIZE*33]; uint64_t x,nxt64bits; //,*hexstr,*retstr //if ( strcmp(cmdstr,"poll") == 0 ) // return(clonestr("{\"result\":\"skip sending poll\"}")); //category_subscribe(myinfo,myinfo->instantdex_category,GENESIS_PUBKEY); @@ -480,7 +480,7 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o free(allocptr); return(clonestr("{\"result\":\"success\"}")); - if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 ) + /* if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 ) { //printf(">>>>>>>>>>>> instantdex send.(%s) datalen.%d allocsize.%d crc.%x\n",cmdstr,datalen,msg->sig.allocsize,calc_crc32(0,(void *)((long)msg + 8),datalen-8)); if ( addr != 0 ) @@ -508,7 +508,7 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o free(msg); printf("cant msgcreate datalen.%d\n",datalen); return(clonestr("{\"error\":\"couldnt create instantdex message\"}")); - } + }*/ } int32_t instantdex_updatesources(struct exchange_info *exchange,struct exchange_quote *sortbuf,int32_t n,int32_t max,int32_t ind,int32_t dir,struct exchange_quote *quotes,int32_t numquotes) @@ -1445,7 +1445,7 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms return(clonestr("{\"error\":\"request needs argjson\"}")); } -char *InstantDEX_hexmsg(struct supernet_info *myinfo,struct private_chain *cat,void *ptr,int32_t len,char *remoteaddr) +char *InstantDEX_hexmsg(struct supernet_info *myinfo,struct gecko_chain *cat,void *ptr,int32_t len,char *remoteaddr) { struct instantdex_msghdr *msg = ptr; int32_t olen,slen,datalen,newlen,flag = 0; uint8_t *serdata; struct instantdex_offer rawoffer; // struct supernet_info *myinfos[64]; @@ -1554,7 +1554,7 @@ char *instantdex_createaccept(struct supernet_info *myinfo,struct instantdex_acc void instantdex_update(struct supernet_info *myinfo) { - struct instantdex_msghdr *pm; struct category_msg *m; char *str,remote[64]; queue_t *Q; struct queueitem *item; struct private_chain *cat; + /*struct instantdex_msghdr *pm; struct category_msg *m; char *str,remote[64]; queue_t *Q; struct queueitem *item; struct gecko_chain *cat; //char str2[65]; printf("myinfo->instantdex_category.(%s)\n",bits256_str(str2,myinfo->instantdex_category)); if ( (Q= category_Q(&cat,myinfo->instantdex_category,myinfo->myaddr.persistent)) != 0 && queue_size(Q) > 0 && (item= Q->list) != 0 ) { @@ -1571,7 +1571,7 @@ void instantdex_update(struct supernet_info *myinfo) if ( (str= InstantDEX_hexmsg(myinfo,cat,pm,m->len,remote)) != 0 ) free(str); free(m); - } + }*/ } #include "../includes/iguana_apidefs.h" diff --git a/iguana/iguana_json.c b/iguana/iguana_json.c index 509c9f810..b33d7fa53 100755 --- a/iguana/iguana_json.c +++ b/iguana/iguana_json.c @@ -14,7 +14,7 @@ ******************************************************************************/ #include "iguana777.h" -#include "SuperNET.h" +//#include "SuperNET.h" cJSON *helpjson(cJSON *json,cJSON *array,cJSON *agents,char *agentstr,char *method,cJSON *methodargs) { diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index 89d705975..779d55e17 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -142,7 +142,7 @@ int32_t iguana_eatauxpow(int32_t rwflag,char *symbol,uint8_t zcash,uint8_t *seri memset(&MEM,0,sizeof(MEM)); ptr = calloc(1,1000000); iguana_meminit(&MEM,"auxpow",ptr,1000000,0); - len += iguana_rwtx(coin->chain->zcash,rwflag,&MEM,&serialized[len],&msg,(int32_t)MEM.totalsize,&coinbasetxid,coin->chain->txhastimestamp,0); + len += iguana_rwtx(coin->chain->zcash,rwflag,&MEM,&serialized[len],&msg,(int32_t)MEM.totalsize,&coinbasetxid,coin->chain->isPoS,0); if ( len > maxlen ) return(-1); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(auxhash2),auxhash2.bytes); @@ -188,9 +188,10 @@ int32_t iguana_rwblock(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hasha } *hash2p = iguana_calcblockhash(symbol,hashalgo,serialized,len); //char str[65],str2[65]; printf("zcash.%d len.%d: block version.%d timestamp.%u bits.%x nonce.%u prev.(%s) %llx hash2.%s\n",zcash,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,bits256_str(str2,*hash2p)); - if ( rwflag == 0 && auxpow != 0 && (msg->H.version & 0x100) != 0 ) + if ( auxpow != 0 && (msg->H.version & 0x100) != 0 ) len += iguana_eatauxpow(rwflag,symbol,zcash,&serialized[len],maxlen-len); - else x = msg->txn_count; + if ( rwflag == 1 ) + x = msg->txn_count; len += iguana_rwvarint(rwflag,&serialized[len],&x); if ( rwflag == 0 ) { @@ -671,30 +672,34 @@ int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struc return(-1); } iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(struct iguana_block *)&txdata->zblock,&msg,hash2,-1); - tx = iguana_memalloc(mem,msg.txn_count*sizeof(*tx),1); - for (i=numvins=numvouts=0; i 0 ) { - if ( len > recvlen ) + tx = iguana_memalloc(mem,msg.txn_count*sizeof(*tx),1); + for (i=0; i recvlen.%d\n",len,recvlen); - break; + if ( len > recvlen ) + { + printf("gentxarray error len.%d > recvlen.%d\n",len,recvlen); + break; + } + if ( (n= iguana_rwtx(coin->chain->zcash,0,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0)) < 0 ) + { + printf("gentxarray error len.%d > recvlen.%d\n",len,recvlen); + break; + } + numvouts += tx[i].tx_out; + numvins += tx[i].tx_in; + len += n; } - if ( (n= iguana_rwtx(coin->chain->zcash,0,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->txhastimestamp,strcmp(coin->symbol,"VPN")==0)) < 0 ) + if ( coin->chain->isPoS != 0 && len != recvlen && data[len] == (recvlen - len - 1) ) { - printf("gentxarray error len.%d > recvlen.%d\n",len,recvlen); - break; - } - numvouts += tx[i].tx_out; - numvins += tx[i].tx_in; - len += n; + //printf("\n>>>>>>>>>>> len.%d vs recvlen.%d [%d]\n",len,recvlen,data[len]); + memcpy(txdata->space,&data[len],recvlen-len); + len += (recvlen-len); + txdata->extralen = (recvlen - len); + } else txdata->extralen = 0; } - if ( coin->chain->txhastimestamp != 0 && len != recvlen && data[len] == (recvlen - len - 1) ) - { - //printf("\n>>>>>>>>>>> len.%d vs recvlen.%d [%d]\n",len,recvlen,data[len]); - memcpy(txdata->space,&data[len],recvlen-len); - len += (recvlen-len); - txdata->extralen = (recvlen - len); - } else txdata->extralen = 0; if ( coin->chain->auxpow != 0 && len != recvlen ) printf("numtx.%d %s hdrlen.%d len.%d vs recvlen.%d v.%08x\n",msg.txn_count,bits256_str(str,hash2),hdrlen,len,recvlen,txdata->zblock.RO.version); txdata->recvlen = len; @@ -900,7 +905,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc { iguana_memreset(rawmem); tx = iguana_memalloc(rawmem,sizeof(*tx),1); - len += iguana_rwtx(coin->chain->zcash,0,rawmem,&data[len],tx,recvlen-len,&tx->txid,coin->chain->txhastimestamp,strcmp(coin->symbol,"VPN")==0); + len += iguana_rwtx(coin->chain->zcash,0,rawmem,&data[len],tx,recvlen-len,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0); len += iguana_rwbignum(0,&data[len],sizeof(auxhash2),auxhash2.bytes); len += iguana_rwmerklebranch(0,&data[len],coinbase_branch); len += iguana_rwmerklebranch(0,&data[len],blockchain_branch); @@ -1045,7 +1050,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc struct iguana_msgtx *tx; iguana_memreset(rawmem); tx = iguana_memalloc(rawmem,sizeof(*tx),1);//mycalloc('u',1,sizeof(*tx)); - len = iguana_rwtx(coin->chain->zcash,0,rawmem,data,tx,recvlen,&tx->txid,coin->chain->txhastimestamp,strcmp(coin->symbol,"VPN")==0); + len = iguana_rwtx(coin->chain->zcash,0,rawmem,data,tx,recvlen,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0); if ( addr != 0 ) { iguana_gotunconfirmedM(coin,addr,tx,data,recvlen); diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index bcc940917..f94f98f85 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -54,7 +54,7 @@ bits256 iguana_str2priv(struct supernet_info *myinfo,struct iguana_info *coin,ch decode_hex(privkey.bytes,sizeof(privkey),str); else if ( bitcoin_wif2priv(&addrtype,&privkey,str) != sizeof(bits256) ) { - if ( (waddr= iguana_waddresssearch(myinfo,coin,&wacct,str)) != 0 ) + if ( (waddr= iguana_waddresssearch(myinfo,&wacct,str)) != 0 ) privkey = waddr->privkey; else memset(privkey.bytes,0,sizeof(privkey)); } @@ -68,7 +68,7 @@ int32_t iguana_pubkeyget(struct supernet_info *myinfo,struct iguana_info *coin,u len = (int32_t)strlen(str); if ( is_hexstr(str,len) == 0 ) { - if ( (waddr= iguana_waddresssearch(myinfo,coin,&wacct,str)) != 0 ) + if ( (waddr= iguana_waddresssearch(myinfo,&wacct,str)) != 0 ) { if ( (plen= bitcoin_pubkeylen(waddr->pubkey)) > 0 ) memcpy(pubkeydata,waddr->pubkey,plen); @@ -111,7 +111,7 @@ cJSON *iguana_p2shjson(struct supernet_info *myinfo,struct iguana_info *coin,cJS addresses = cJSON_CreateArray(); for (i=0; iwifstr[0] != 0 ) + if ( V.signers[i].coinaddr[0] != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,V.signers[i].coinaddr)) != 0 && waddr->wifstr[0] != 0 ) jaddistr(privkeys,waddr->wifstr); else jaddistr(privkeys,""); if ( (plen= bitcoin_pubkeylen(V.signers[i].pubkey)) > 0 ) @@ -763,7 +763,7 @@ HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose) if ( (tx= iguana_txidfind(coin,&height,&T,txid,coin->bundlescount-1)) != 0 ) { retjson = cJSON_CreateObject(); - if ( (len= iguana_ramtxbytes(coin,coin->blockspace,sizeof(coin->blockspace),&checktxid,tx,height,0,0,0)) > 0 ) + if ( (len= iguana_ramtxbytes(coin,coin->blockspace,coin->blockspacesize,&checktxid,tx,height,0,0,0)) > 0 ) { txbytes = calloc(1,len*2+1); init_hexbytes_noT(txbytes,coin->blockspace,len); @@ -941,7 +941,7 @@ cJSON *iguana_createvins(struct supernet_info *myinfo,struct iguana_info *coin,c if ( (unspentind= iguana_unspentindfind(coin,coinaddr,spendscript,&spendlen,&satoshis,&height,txid,vout,coin->bundlescount-1)) > 0 ) { //printf("[%d] unspentind.%d (%s) spendlen.%d %.8f\n",height/coin->chain->bundlesize,unspentind,coinaddr,spendlen,dstr(satoshis)); - if ( coinaddr[0] != 0 && (waddr= iguana_waddresssearch(myinfo,coin,&wacct,coinaddr)) != 0 ) + if ( coinaddr[0] != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) { init_hexbytes_noT(pubkeystr,waddr->pubkey,bitcoin_pubkeylen(waddr->pubkey)); jaddistr(pubkeys,pubkeystr); @@ -976,7 +976,7 @@ ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime) bits256 txid; int32_t offset,spendlen=0,n; uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; uint64_t satoshis; char *hexstr,*field,*txstr; cJSON *txobj,*item,*obj,*retjson = cJSON_CreateObject(); if ( remoteaddr != 0 ) return(clonestr("{\"error\":\"no remote\"}")); - if ( coin != 0 && (txobj= bitcoin_txcreate(coin->chain->txhastimestamp,locktime)) != 0 ) + if ( coin != 0 && (txobj= bitcoin_txcreate(coin->chain->isPoS,locktime,locktime==0?coin->chain->normal_txversion:coin->chain->locktime_txversion)) != 0 ) { iguana_createvins(myinfo,coin,txobj,vins); if ( (n= cJSON_GetArraySize(vouts)) > 0 ) diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index 35db27fcb..e24170dd3 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -651,7 +651,7 @@ void iguana_startconnection(void *arg) int32_t i,n; uint16_t port; char ipaddr[64]; struct iguana_peer *addr = arg; struct iguana_info *coin = 0; if ( addr == 0 || (coin= iguana_coinfind(addr->symbol)) == 0 ) { - printf("iguana_startconnection nullptrs addr.%p coin.%p\n",addr,coin); + printf("iguana_startconnection nullptrs addr.%p (%s) coin.%p\n",addr,addr!=0?addr->symbol:"",coin); return; } if ( coin->virtualchain != 0 ) @@ -662,9 +662,9 @@ void iguana_startconnection(void *arg) printf("%s usock.%d skip connection\n",addr->ipaddr,addr->usock); return; } - if ( strcmp(coin->name,addr->coinstr) != 0 ) + if ( strcmp(coin->name,addr->coinname) != 0 ) { - printf("iguana_startconnection.%s:%04x mismatched coin.%p (%s) vs (%s)\n",addr->ipaddr,coin->chain->portp2p,coin,coin->symbol,addr->coinstr); + printf("iguana_startconnection.%s:%04x mismatched coin.%p (%s) vs (%s)\n",addr->ipaddr,coin->chain->portp2p,coin,coin->symbol,addr->coinname); return; } //printf("iguana_startconnection.%s:%04x (%s)\n",addr->ipaddr,coin->chain->portp2p,addr->coinstr); @@ -694,7 +694,7 @@ void iguana_startconnection(void *arg) addr->pending = 0; addr->height = iguana_iAddrheight(coin,addr->ipbits); strcpy(addr->symbol,coin->symbol); - strcpy(addr->coinstr,coin->name); + strcpy(addr->coinname,coin->name); coin->peers->lastpeer = (uint32_t)time(NULL); for (i=n=0; iMAXPEERS; i++) if ( coin->peers->active[i].usock > 0 ) @@ -767,6 +767,10 @@ struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int void iguana_launchpeer(struct iguana_info *coin,char *ipaddr) { struct iguana_peer *addr; uint32_t ipbits = (uint32_t)calc_ipbits(ipaddr); + if ( coin == 0 ) + { + printf("iguana_launchpeer: null coin?\n"); + } if ( coin->virtualchain != 0 ) return; if ( (addr= iguana_peerslot(coin,ipbits,0)) != 0 ) @@ -1098,7 +1102,7 @@ int32_t iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,in void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr) { - static uint32_t lastping; + //static uint32_t lastping; struct pollfd fds; struct iguana_bundlereq *req; uint8_t *buf; uint32_t ipbits; int32_t bufsize,flag,run,timeout = coin->polltimeout == 0 ? 10 : coin->polltimeout; if ( coin->virtualchain != 0 ) @@ -1211,11 +1215,11 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin, } if ( flag != 0 ) run = 0; - else if ( 0 && addr->supernet != 0 && time(NULL) > lastping+SUPERNET_PINGGAP ) + /*else if ( 0 && addr->supernet != 0 && time(NULL) > lastping+SUPERNET_PINGGAP ) { iguana_send_supernet(addr,SUPERNET_GETPEERSTR,0); lastping = (uint32_t)time(NULL); - } + }*/ if ( addr->persistent_peer != 0 ) { if ( addr->usock < 0 || addr->dead != 0 ) diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index 10afcec34..9da773f99 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -1824,7 +1824,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru #ifdef __PNACL__ //verifyflag = 1; #endif - if ( (addr_ipbits= (uint32_t)addr->ipbits) == 0 ) + if ( addr == 0 || (addr_ipbits= (uint32_t)addr->ipbits) == 0 ) addr_ipbits = 1; if ( bits256_nonz(origtxdata->zblock.RO.merkle_root) == 0 ) { @@ -1833,8 +1833,11 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru origtxdata->zblock.issued = 0; return(-1); } - for (i=0; idirty)/sizeof(*addr->dirty); i++) - addr->dirty[i] = 0; + if ( addr != 0 ) + { + for (i=0; idirty)/sizeof(*addr->dirty); i++) + addr->dirty[i] = 0; + } msize = (int32_t)sizeof(bits256) * (txn_count+1) * 2; if ( msize <= addr->TXDATA.totalsize ) { diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 545b434a4..c61bd90a0 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -340,7 +340,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i else if ( 0 && coin->enableCACHE != 0 ) printf("cache.%d validated.(%s)\n",coin->enableCACHE,bits256_str(str,origtxdata->zblock.RO.hash2)); origtxdata->zblock.txvalid = 1; - if ( addr != 0 && addr != &coin->internaladdr ) + if ( coin->virtualchain == 0 && addr != 0 && addr != &coin->internaladdr ) { static uint64_t received[IGUANA_MAXPEERS],count[IGUANA_MAXPEERS],lastcount,lastreceived,last; received[addr->addrind] += recvlen; @@ -486,7 +486,8 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i } //else printf("cant save block\n"); } req->zblock = txdata->zblock; - //printf("recvlen.%d ipbits.%x prev.(%s)\n",req->zblock.RO.recvlen,req->zblock.fpipbits,bits256_str(str,txdata->zblock.RO.prev_block)); + if ( coin->virtualchain != 0 ) + printf("%s recvlen.%d ipbits.%x prev.(%s)\n",coin->symbol,req->zblock.RO.recvlen,req->zblock.fpipbits,bits256_str(str,txdata->zblock.RO.prev_block)); req->zblock.RO.txn_count = req->numtx = txdata->zblock.RO.txn_count; coin->recvcount++; coin->recvtime = (uint32_t)time(NULL); diff --git a/iguana/iguana_rpc.c b/iguana/iguana_rpc.c index cc99b9c42..f50827196 100755 --- a/iguana/iguana_rpc.c +++ b/iguana/iguana_rpc.c @@ -14,7 +14,7 @@ ******************************************************************************/ #include "iguana777.h" -#include "SuperNET.h" +//#include "SuperNET.h" #define RPCARGS struct supernet_info *myinfo,uint16_t port,struct iguana_info *coin,cJSON *params[],int32_t n,cJSON *json,char *remoteaddr,cJSON *array #define GLUEARGS cJSON *json,struct supernet_info *myinfo,uint16_t port,struct iguana_info *coin,char *remoteaddr,cJSON *params[] @@ -644,7 +644,7 @@ char *iguana_bitcoinrpc(struct supernet_info *myinfo,uint16_t port,struct iguana char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr,uint16_t port) { - cJSON *params[16],*array; struct iguana_info *coin = 0; char symbol[16]; int32_t i,c,n; char *retstr = 0; + cJSON *params[16],*array; struct iguana_info *tmp,*coin = 0; char symbol[16]; int32_t i,c,n; char *retstr = 0; symbol[0] = 0; memset(params,0,sizeof(params)); if ( json != 0 ) @@ -671,11 +671,14 @@ char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,ch } else { - for (i=0; ichain->rpcport == port ) + //portable_mutex_lock(&Allcoins_mutex); + HASH_ITER(hh,myinfo->allcoins,coin,tmp) + { + if ( coin->chain->rpcport == port ) break; - if ( i == IGUANA_MAXCOINS ) - coin = 0; + else coin = 0; + } + //portable_mutex_unlock(&Allcoins_mutex); } if ( coin == 0 && symbol[0] != 0 ) coin = iguana_coinfind(symbol); diff --git a/iguana/iguana_sign.c b/iguana/iguana_sign.c index 386d394b7..fcf0f80cb 100755 --- a/iguana/iguana_sign.c +++ b/iguana/iguana_sign.c @@ -127,6 +127,10 @@ cJSON *iguana_vinjson(struct iguana_info *coin,struct iguana_msgvin *vin,bits256 int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_msgvin *vin,cJSON *vinobj,struct vin_info *V) { struct iguana_waddress *waddr; struct iguana_waccount *wacct; int32_t i,n,plen,len = 0; char *suffixstr,*pubkeystr,*hexstr = 0,*redeemstr = 0,*spendstr = 0; cJSON *scriptjson = 0,*obj,*pubkeysjson = 0; + if ( serialized == 0 ) + { + ; + } //printf("PARSEVIN.(%s) vin.%p\n",jprint(vinobj,0),vin); if ( V == 0 ) memset(vin,0,sizeof(*vin)); @@ -165,7 +169,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin { if ( (V->unspentind= iguana_unspentindfind(coin,V->coinaddr,V->spendscript,&V->spendlen,&V->amount,&V->height,vin->prev_hash,vin->prev_vout,coin->bundlescount-1)) > 0 ) { - if ( V->coinaddr[0] != 0 && (waddr= iguana_waddresssearch(myinfo,coin,&wacct,V->coinaddr)) != 0 ) + if ( V->coinaddr[0] != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,V->coinaddr)) != 0 ) { memcpy(V->signers[0].pubkey,waddr->pubkey,bitcoin_pubkeylen(waddr->pubkey)); } @@ -344,7 +348,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8 //printf("json.%p array.%p sigser.%p\n",json,array,sigser); } //printf("version.%d\n",msg->version); - if ( coin->chain->txhastimestamp != 0 ) + if ( coin->chain->isPoS != 0 ) { len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->timestamp),&msg->timestamp); //char str[65]; printf("version.%d timestamp.%08x %u %s\n",msg->version,msg->timestamp,msg->timestamp,utc_str(str,msg->timestamp)); @@ -481,7 +485,7 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin, vpnstr[0] = 0; if ( (msg->version= juint(txobj,"version")) == 0 ) msg->version = 1; - if ( coin->chain->txhastimestamp != 0 ) + if ( coin->chain->isPoS != 0 ) { if ( (msg->timestamp= juint(txobj,"timestamp")) == 0 ) msg->timestamp = (uint32_t)time(NULL); @@ -735,7 +739,7 @@ int32_t iguana_vininfo_create(struct supernet_info *myinfo,struct iguana_info *c if ( (plen= bitcoin_pubkeylen(vp->signers[0].pubkey)) > 0 ) bitcoin_address(vp->coinaddr,coin->chain->pubtype,vp->signers[0].pubkey,plen); } - if ( vp->coinaddr[i] != 0 && (waddr= iguana_waddresssearch(myinfo,coin,&wacct,vp->coinaddr)) != 0 ) + if ( vp->coinaddr[i] != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,vp->coinaddr)) != 0 ) { vp->signers[0].privkey = waddr->privkey; if ( (plen= bitcoin_pubkeylen(waddr->pubkey)) != vp->spendscript[1] || vp->spendscript[vp->spendlen-1] != 0xac ) @@ -766,7 +770,7 @@ void iguana_ensure_privkey(struct supernet_info *myinfo,struct iguana_info *coin bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey); bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33); //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,&wacct,coinaddr)) == 0 || bits256_nonz(waddr->privkey) == 0) ) { if ( waddr == 0 ) { @@ -911,20 +915,12 @@ cJSON *bitcoin_txinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_ return(txobj); } -cJSON *bitcoin_txcreate(int32_t txhastimestamp,int64_t locktime) +cJSON *bitcoin_txcreate(int32_t isPoS,int64_t locktime,uint32_t txversion) { cJSON *json = cJSON_CreateObject(); - if ( locktime == 0 ) - { - jaddnum(json,"version",1); - jadd64bits(json,"locktime",0); - } - else - { - jaddnum(json,"version",4); - jadd64bits(json,"locktime",locktime); - } - if ( txhastimestamp != 0 ) + jaddnum(json,"version",txversion); + jadd64bits(json,"locktime",locktime); + if ( isPoS != 0 ) jaddnum(json,"timestamp",time(NULL)); jadd(json,"vin",cJSON_CreateArray()); jadd(json,"vout",cJSON_CreateArray()); @@ -1004,7 +1000,7 @@ P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount if ( M > N || N > 3 ) return(clonestr("{\"error\":\"illegal M or N\"}")); memset(&V,0,sizeof(V)); - txobj = bitcoin_txcreate(active->chain->txhastimestamp,0); + txobj = bitcoin_txcreate(active->chain->isPoS,0,coin->chain->normal_txversion); if ( destaddress[0] != 0 && destamount > 0. ) bitcoin_txaddspend(active,txobj,destaddress,destamount * SATOSHIDEN); if ( destaddress2[0] != 0 && destamount2 > 0. ) diff --git a/iguana/iguana_spendvectors.c b/iguana/iguana_spendvectors.c index ff6f35d3b..9e0b97cce 100755 --- a/iguana/iguana_spendvectors.c +++ b/iguana/iguana_spendvectors.c @@ -1067,7 +1067,7 @@ int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp, } if ( forceflag != 0 || bp->validated <= 1 ) { - max = sizeof(coin->blockspace); + max = coin->blockspacesize; blockspace = calloc(1,max); iguana_volatilesmap(coin,&bp->ramchain); for (i=0; in; i++) diff --git a/iguana/iguana_tx.c b/iguana/iguana_tx.c index 18b92d8cb..3eb558eab 100755 --- a/iguana/iguana_tx.c +++ b/iguana/iguana_tx.c @@ -14,7 +14,7 @@ ******************************************************************************/ #include "iguana777.h" -#include "SuperNET.h" +//#include "SuperNET.h" //struct iguana_txid { bits256 txid; uint32_t txidind,firstvout,firstvin,locktime,version,timestamp; uint16_t numvouts,numvins; } __attribute__((packed)); @@ -174,7 +174,7 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m int32_t i,rwflag=1,len = 0; char asmstr[512],txidstr[65]; uint32_t numvins,numvouts; struct iguana_msgvin vin; struct iguana_msgvout vout; uint8_t space[IGUANA_MAXSCRIPTSIZE]; len += iguana_rwnum(rwflag,&serialized[len],sizeof(tx->version),&tx->version); - if ( coin->chain->txhastimestamp != 0 ) + if ( coin->chain->isPoS != 0 ) len += iguana_rwnum(rwflag,&serialized[len],sizeof(tx->timestamp),&tx->timestamp); numvins = tx->numvins, numvouts = tx->numvouts; len += iguana_rwvarint32(rwflag,&serialized[len],&numvins); @@ -206,7 +206,7 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m } if ( len > maxlen ) { - printf("len.%d > maxlen.%d\n",len,maxlen); + printf("len.%d > maxlenB.%d\n",len,maxlen); return(0); } len += iguana_rwnum(rwflag,&serialized[len],sizeof(tx->locktime),&tx->locktime); @@ -388,7 +388,7 @@ cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int3 jadd(json,"tx",array); //printf("add txids[%d]\n",block->txn_count); } - if ( (size= iguana_peerblockrequest(coin,coin->blockspace,sizeof(coin->blockspace),0,block->RO.hash2,0)) < 0 ) + if ( (size= iguana_peerblockrequest(coin,coin->blockspace,coin->blockspacesize,0,block->RO.hash2,0)) < 0 ) jaddstr(json,"error","couldnt generate raw bytes for block"); else jaddnum(json,"size",size); return(json); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 78b29bf6f..2910cce34 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -121,7 +121,7 @@ cJSON *iguana_unspentjson(struct supernet_info *myinfo,struct iguana_info *coin, jaddnum(item,"confirmations",coin->blocks.hwmchain.height - height + 1); jaddnum(item,"checkind",checkind); } - if ( (waddr= iguana_waddresssearch(myinfo,coin,&wacct,coinaddr)) != 0 ) + if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) { jaddstr(item,"account",wacct->account); jadd(item,"spendable",jtrue()); diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index 01e9a0126..106fc49af 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -29,7 +29,7 @@ void scrubfree(char *sensitivestr) } } -struct iguana_waddress *iguana_waddressfind(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,char *coinaddr) +struct iguana_waddress *iguana_waddressfind(struct supernet_info *myinfo,struct iguana_waccount *wacct,char *coinaddr) { struct iguana_waddress *waddr; uint8_t addrtype,rmd160[20]; bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); @@ -95,7 +95,7 @@ struct iguana_waddress *iguana_waddresscreate(struct supernet_info *myinfo,struc printf("create (%s)scriptlen.%d -> (%s)\n",coinaddr,waddr->scriptlen,wacct->account); } else printf("error iguana_waddressalloc null waddr\n"); } //else printf("have (%s) in (%s)\n",coinaddr,wacct->account); - if ( (ptr= iguana_waddressfind(myinfo,coin,wacct,coinaddr)) != waddr ) + if ( (ptr= iguana_waddressfind(myinfo,wacct,coinaddr)) != waddr ) printf("iguana_waddresscreate verify error %p vs %p\n",ptr,waddr); return(waddr); } @@ -147,7 +147,7 @@ struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct i bitcoin_address(waddr->coinaddr,waddr->addrtype,waddr->rmd160,sizeof(waddr->rmd160)); myinfo->dirty = (uint32_t)time(NULL); } - if ( (ptr= iguana_waddressfind(myinfo,coin,wacct,waddr->coinaddr)) != waddr ) + if ( (ptr= iguana_waddressfind(myinfo,wacct,waddr->coinaddr)) != waddr ) { HASH_ADD_KEYPTR(hh,wacct->waddr,waddr->rmd160,sizeof(waddr->rmd160),waddr); myinfo->dirty = (uint32_t)time(NULL); @@ -171,22 +171,19 @@ struct iguana_waddress *iguana_waddressdelete(struct supernet_info *myinfo,struc return(waddr); } -struct iguana_waddress *iguana_waddresssearch(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount **wacctp,char *coinaddr) +struct iguana_waddress *iguana_waddresssearch(struct supernet_info *myinfo,struct iguana_waccount **wacctp,char *coinaddr) { struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr; HASH_ITER(hh,myinfo->wallet,wacct,tmp) { - if ( (waddr= iguana_waddressfind(myinfo,coin,wacct,coinaddr)) != 0 ) + if ( (waddr= iguana_waddressfind(myinfo,wacct,coinaddr)) != 0 ) { - if ( waddr != 0 && bits256_nonz(waddr->privkey) != 0 ) + if ( waddr != 0 && bits256_nonz(waddr->privkey) != 0 && waddr->wifstr[0] == 0 ) { - if ( bitcoin_priv2wif(waddr->wifstr,waddr->privkey,coin->chain->wiftype) > 0 ) - { - if ( 0 && waddr->wiftype != coin->chain->wiftype ) - printf("waddresssearch warning: mismatched wiftype %02x != %02x\n",waddr->wiftype,coin->chain->wiftype); - if ( 0 && waddr->addrtype != coin->chain->pubtype ) - printf("waddresssearch warning: mismatched addrtype %02x != %02x\n",waddr->addrtype,coin->chain->pubtype); - } + printf("coinaddr.(%s) no wifstr\n",coinaddr); + //if ( bitcoin_priv2wif(waddr->wifstr,waddr->privkey,coin->chain->wiftype) > 0 ) + //{ + //} } (*wacctp) = wacct; return(waddr); @@ -218,7 +215,7 @@ struct iguana_waddress *iguana_waddresscalc(struct supernet_info *myinfo,uint8_t struct iguana_waddress *iguana_waccountswitch(struct supernet_info *myinfo,struct iguana_info *coin,char *account,char *coinaddr,char *redeemScript) { struct iguana_waccount *wacct = 0; struct iguana_waddress addr,*waddr = 0; int32_t flag = 0; - if ( (waddr= iguana_waddresssearch(myinfo,coin,&wacct,coinaddr)) != 0 ) + if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) { if ( strcmp(wacct->account,account) != 0 ) { @@ -302,7 +299,7 @@ struct iguana_waddress *iguana_ismine(struct supernet_info *myinfo,struct iguana { char coinaddr[65]; struct iguana_waccount *wacct; struct iguana_waddress *waddr = 0; if ( bitcoin_address(coinaddr,addrtype,rmd160,20) > 0 ) - waddr = iguana_waddresssearch(myinfo,coin,&wacct,coinaddr); + waddr = iguana_waddresssearch(myinfo,&wacct,coinaddr); return(waddr); } @@ -374,7 +371,7 @@ char *getaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *coi struct iguana_waccount *wacct; struct iguana_waddress *waddr; uint8_t addrtype; cJSON *retjson; if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 ) return(clonestr("{\"error\":\"invalid coin address\"}")); - if ( (waddr= iguana_waddresssearch(myinfo,coin,&wacct,coinaddr)) == 0 ) + if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) == 0 ) return(clonestr("{\"result\":\"no account for address\"}")); if ( wacct != 0 ) { @@ -489,7 +486,7 @@ cJSON *iguana_walletadd(struct supernet_info *myinfo,struct iguana_waddress **wa wacct = iguana_waccountcreate(myinfo,coin,account); if ( wacct != 0 ) { - //waddr = iguana_waddressfind(myinfo,coin,wacct,refwaddr->coinaddr); + //waddr = iguana_waddressfind(myinfo,wacct,refwaddr->coinaddr); waddr = iguana_waddressadd(myinfo,coin,wacct,refwaddr,redeemScript); if ( setcurrent != 0 ) wacct->current = waddr; @@ -596,7 +593,7 @@ uint8_t iguana_waddrvalidate(struct supernet_info *myinfo,struct iguana_info *co struct iguana_waccount *checkwacct; struct iguana_waddress *checkwaddr; uint8_t checkpub[33],rmd160[20],addrtype,checktype,plen,flag=0; int32_t i; if ( waddr != 0 ) { - if ( (checkwaddr= iguana_waddresssearch(myinfo,coin,&checkwacct,waddr->coinaddr)) != waddr || checkwacct != wacct ) + if ( (checkwaddr= iguana_waddresssearch(myinfo,&checkwacct,waddr->coinaddr)) != waddr || checkwacct != wacct ) { //errors[5]++; //flag |= (5 << 0); @@ -810,10 +807,14 @@ void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coi void iguana_walletlock(struct supernet_info *myinfo,struct iguana_info *coin) { memset(&myinfo->persistent_priv,0,sizeof(myinfo->persistent_priv)); + memset(&myinfo->persistent_pubkey33,0,sizeof(myinfo->persistent_pubkey33)); memset(myinfo->secret,0,sizeof(myinfo->secret)); memset(myinfo->permanentfile,0,sizeof(myinfo->permanentfile)); if ( myinfo->decryptstr != 0 ) scrubfree(myinfo->decryptstr), myinfo->decryptstr = 0; + memset(myinfo->handle,0,sizeof(myinfo->handle)); + memset(myinfo->myaddr.NXTADDR,0,sizeof(myinfo->myaddr.NXTADDR)); + myinfo->myaddr.nxt64bits = 0; myinfo->expiration = 0; iguana_walletiterate(myinfo,coin,-2,0,0,0,0); } @@ -851,7 +852,7 @@ cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin } for (i=0; iwifstr); } free(addresses); @@ -907,7 +908,7 @@ char *getnewaddress(struct supernet_info *myinfo,struct iguana_waddress **waddrp STRING_ARG(bitcoinrpc,validateaddress,address) { - cJSON *retjson; int32_t i; uint8_t addrtype,rmd160[20],pubkey[65]; struct iguana_info *other; char str[256]; + cJSON *retjson; uint8_t addrtype,rmd160[20],pubkey[65]; struct iguana_info *other,*tmp; char str[256]; if ( remoteaddr != 0 ) return(clonestr("{\"error\":\"no remote\"}")); if ( iguana_addressvalidate(coin,&addrtype,address) < 0 ) @@ -929,14 +930,16 @@ STRING_ARG(bitcoinrpc,validateaddress,address) cJSON_AddTrueToObject(retjson,"ismine"); } else cJSON_AddFalseToObject(retjson,"ismine"); - for (i=0; iallcoins,other,tmp) { - if ( (other= Coins[i]) != 0 && strcmp(other->symbol,coin->symbol) != 0 ) + if ( strcmp(other->symbol,coin->symbol) != 0 ) { iguana_addressconv(coin,str,other,addrtype == coin->chain->p2shtype,rmd160); jaddstr(retjson,other->symbol,str); } } + //portable_mutex_unlock(&Allcoins_mutex); return(jprint(retjson,1)); } @@ -1147,7 +1150,7 @@ TWOSTRINGS_AND_INT(bitcoinrpc,importprivkey,wif,account,rescan) memset(&addr,0,sizeof(addr)); if ( iguana_waddresscalc(myinfo,coin->chain->pubtype,coin->chain->wiftype,&addr,privkey) != 0 ) { - if ( (waddr= iguana_waddresssearch(myinfo,coin,&wacct,addr.coinaddr)) != 0 ) + if ( (waddr= iguana_waddresssearch(myinfo,&wacct,addr.coinaddr)) != 0 ) { waddr = iguana_waccountswitch(myinfo,coin,account,addr.coinaddr,0); return(clonestr("{\"result\":\"privkey already in wallet\"}")); @@ -1195,7 +1198,7 @@ STRING_ARG(bitcoinrpc,dumpprivkey,address) } if ( strlen(coinaddr) > sizeof(V.coinaddr) || iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 ) return(clonestr(p2shflag == 0 ? "{\"error\":\"invalid address\"}" : "{\"error\":\"invalid P2SH address\"}")); - if ( (waddr= iguana_waddresssearch(myinfo,coin,&wacct,coinaddr)) != 0 ) + if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) { if ( (waddr->wifstr[0] != 0 || waddr->scriptlen > 0) ) { diff --git a/iguana/m_unix b/iguana/m_unix index 618cc655f..87db2ba66 100755 --- a/iguana/m_unix +++ b/iguana/m_unix @@ -3,7 +3,6 @@ rm ../agents/iguana *.o git pull cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_unix; cd ../iguana -gcc -g -Wno-deprecated -c -O2 *.c ../basilisk/basilisk.c ../basilisk/basilisk_privatechains.c #databases/iguana_DB.c +gcc -g -Wno-deprecated -c -O2 *.c ../basilisk/basilisk.c ../gecko/gecko.c gcc -g -Wno-deprecated -c main.c iguana777.c iguana_bundles.c -#gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lcrypto -lpthread -lm #../includes/libsecp256k1.a -lgmp gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lpthread -lm diff --git a/iguana/main.c b/iguana/main.c index 7b0d64c63..d8432d1df 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -19,77 +19,15 @@ #define CHROMEAPP_MAIN iguana_main #define CHROMEAPP_JSON iguana_JSON #define CHROMEAPP_HANDLER Handler_iguana +#define ACTIVELY_DECLARE #include "../pnacl_main.h" #include "iguana777.h" -#include "SuperNET.h" + #include "secp256k1/include/secp256k1.h" #include "secp256k1/include/secp256k1_schnorr.h" #include "secp256k1/include/secp256k1_rangeproof.h" -/*#undef fopen -#undef fclose -int32_t Fopen_count,Fclose_count; - -FILE *myfopen(char *fname,char *mode) -{ - FILE *fp; - if ( (fp= fopen(fname,mode)) != 0 ) - { - Fopen_count++; - if ( Fopen_count > 2*Fclose_count ) - printf("Fopens.%d vs Fcloses.%d [%d]\n",Fopen_count,Fclose_count,Fopen_count-Fclose_count); - return(fp); - } - return(0); -} - -int32_t myfclose(FILE *fp) -{ - Fclose_count++; - return(fclose(fp)); -}*/ - -// ALL globals must be here! -char *Iguana_validcommands[] = -{ - "inv2", "getdata2", "ConnectTo", - "version", "verack", "getaddr", "addr", "inv", "getdata", "notfound", "getblocks", "getheaders", "headers", "tx", "block", "mempool", "ping", "pong", - "reject", "filterload", "filteradd", "filterclear", "merkleblock", "alert", "" -}; -int32_t Showmode,Autofold,PANGEA_MAXTHREADS = 1; - -struct private_chain *Categories; -struct iguana_info *Coins[IGUANA_MAXCOINS]; -char Userhome[512]; -int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel,IGUANA_BIGENDIAN; -uint32_t prices777_NXTBLOCK,MAX_DEPTH = 100; -queue_t helperQ,jsonQ,finishedQ,bundlesQ,emitQ; -struct supernet_info MYINFO,**MYINFOS; -int32_t MAIN_initflag; -int32_t HDRnet,netBLOCKS; -cJSON *API_json; - -#ifdef __PNACL__ -char GLOBAL_TMPDIR[512] = "/DB/tmp"; -char GLOBAL_DBDIR[512] = "/DB"; -char GLOBAL_HELPDIR[512] = "/DB/help"; -char GLOBAL_VALIDATEDIR[512] = "/DB/purgeable"; -char GLOBAL_CONFSDIR[512] = "/DB/confs"; -int32_t IGUANA_NUMHELPERS = 1; -#else -char GLOBAL_TMPDIR[512] = "tmp"; -char GLOBAL_HELPDIR[512] = "help"; -char GLOBAL_DBDIR[512] = "DB"; -char GLOBAL_VALIDATEDIR[512] = "DB/purgeable"; -char GLOBAL_CONFSDIR[512] = "confs"; -#ifdef __linux -int32_t IGUANA_NUMHELPERS = 8; -#else -int32_t IGUANA_NUMHELPERS = 4; -#endif -#endif - struct iguana_jsonitem { struct queueitem DL; struct supernet_info *myinfo; uint32_t fallback,expired,allocsize; char *retjsonstr; char remoteaddr[64]; uint16_t port; char jsonstr[]; }; uint16_t SuperNET_API2num(char *agent,char *method) @@ -293,7 +231,7 @@ char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr,uint16_t port) { - cJSON *retjson; uint64_t tag; uint32_t timeout; char *jsonstr,*hexmsg,*method,*retjsonstr,*retstr = 0; + cJSON *retjson; uint64_t tag; uint32_t timeout; char *jsonstr,*retjsonstr,*retstr = 0; //*hexmsg,*method, //char str[65]; printf("processJSON %p %s\n",&myinfo->privkey,bits256_str(str,myinfo->privkey)); if ( json != 0 ) { @@ -304,12 +242,12 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remote } if ( (timeout= juint(json,"timeout")) == 0 ) timeout = IGUANA_JSONTIMEOUT; - if ( (method= jstr(json,"method")) != 0 && strcmp(method,"DHT") == 0 && remoteaddr != 0 && (hexmsg= jstr(json,"hexmsg")) != 0 ) + /*if ( (method= jstr(json,"method")) != 0 && strcmp(method,"DHT") == 0 && remoteaddr != 0 && (hexmsg= jstr(json,"hexmsg")) != 0 ) { //printf("hexmsgprocess myinfo.%p\n",myinfo); SuperNET_hexmsgprocess(myinfo,0,json,hexmsg,remoteaddr); return(clonestr("{\"result\":\"processed remote DHT\"}")); - } + }*/ jsonstr = jprint(json,0); //printf("RPC? (%s)\n",jsonstr); if ( jstr(json,"immediate") != 0 || ((remoteaddr == 0 || remoteaddr[0] == 0) && port == IGUANA_RPCPORT) ) @@ -341,9 +279,39 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remote return(retstr); } +char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr,uint16_t port) +{ + int32_t autologin = 0; uint32_t timestamp; char *retstr=0,*agent=0,*method=0,*jsonstr=0; uint64_t tag; + //printf("SuperNET_JSON.(%s)\n",jprint(json,0)); + if ( remoteaddr != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 ) + remoteaddr = 0; + if ( (agent = jstr(json,"agent")) == 0 ) + agent = "bitcoinrpc"; + method = jstr(json,"method"); + if ( remoteaddr == 0 ) + { + if ( jobj(json,"timestamp") != 0 ) + jdelete(json,"timestamp"); + timestamp = (uint32_t)time(NULL); + jaddnum(json,"timestamp",timestamp); + } + if ( (tag= j64bits(json,"tag")) == 0 ) + { + OS_randombytes((uint8_t *)&tag,sizeof(tag)); + jadd64bits(json,"tag",tag); + } + if ( (retstr= SuperNET_processJSON(myinfo,json,remoteaddr,port)) == 0 ) + printf("null retstr from SuperNET_JSON\n"); + if ( jsonstr != 0 ) + free(jsonstr); + if ( autologin != 0 ) + SuperNET_logout(myinfo,0,json,remoteaddr); + return(retstr); +} + void iguana_exit() { - int32_t i,j,iter; + int32_t j,iter; struct iguana_info *coin,*tmp; printf("start EXIT\n"); for (iter=0; iter<3; iter++) { @@ -351,23 +319,22 @@ void iguana_exit() basilisk_request_goodbye(SuperNET_MYINFO(0)); else { - for (i=0; ipeers->active[j].dead = (uint32_t)time(NULL); break; - case 2: - if ( Coins[i]->peers->active[j].usock >= 0 ) - closesocket(Coins[i]->peers->active[j].usock); - break; - } + case 1: coin->peers->active[j].dead = (uint32_t)time(NULL); break; + case 2: + if ( coin->peers->active[j].usock >= 0 ) + closesocket(coin->peers->active[j].usock); + break; } } } + //portable_mutex_unlock(&Allcoins_mutex); } sleep(3); } @@ -425,7 +392,7 @@ rm BTC.xz; mksquashfs DB/BTC BTC.xz -comp xz -b 1048576 -comp xz -Xdict-size 102 void mainloop(struct supernet_info *myinfo) { - int32_t i,j,n,flag,isRT,numpeers; struct iguana_info *coin; struct iguana_bundle *bp; + int32_t j,n,flag,isRT,numpeers; struct iguana_info *coin,*tmp; struct iguana_bundle *bp; sleep(3); printf("mainloop\n"); while ( 1 ) @@ -438,60 +405,62 @@ void mainloop(struct supernet_info *myinfo) numpeers = 0; if ( 1 ) { - for (i=0; icurrent != 0 ) + coin = 0; + //portable_mutex_lock(&Allcoins_mutex); + HASH_ITER(hh,myinfo->allcoins,coin,tmp) + { + if ( coin->current != 0 && coin->active != 0 && coin->started != 0 ) { - if ( coin->active != 0 && coin->started != 0 ) + isRT *= coin->isRT; + numpeers += coin->peers->numranked; + if ( time(NULL) > coin->startutc+10 && coin->spendvectorsaved == 0 && coin->blocks.hwmchain.height/coin->chain->bundlesize >= (coin->longestchain-coin->minconfirms)/coin->chain->bundlesize ) { - isRT *= coin->isRT; - numpeers += coin->peers->numranked; - if ( time(NULL) > coin->startutc+10 && coin->spendvectorsaved == 0 && coin->blocks.hwmchain.height/coin->chain->bundlesize >= (coin->longestchain-coin->minconfirms)/coin->chain->bundlesize ) + n = coin->bundlescount-1; + if ( iguana_emitfinished(coin,1) >= n ) { - n = coin->bundlescount-1; - if ( iguana_emitfinished(coin,1) >= n ) + if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 ) { - if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 ) - { - for (j=0; jbundles[j]->ramchain); - sleep(3); - } - if ( iguana_validated(coin) < n || iguana_utxofinished(coin) < n || iguana_balancefinished(coin) < n ) - { - coin->spendvectorsaved = 1; - printf("update volatile data, need.%d vs utxo.%d balances.%d validated.%d\n",n,iguana_utxofinished(coin),iguana_balancefinished(coin),iguana_validated(coin)); - } - else - { - coin->spendvectorsaved = (uint32_t)time(NULL); - //printf("already done UTXOGEN (%d %d) (%d %d)\n",iguana_utxofinished(coin),n,iguana_balancefinished(coin),n); - } - } //else printf("only emit.%d vs %d\n",iguana_emitfinished(coin),n); - } - if ( (bp= coin->current) != 0 && coin->stucktime != 0 && coin->isRT == 0 && coin->RTheight == 0 && (time(NULL) - coin->stucktime) > coin->MAXSTUCKTIME ) + for (j=0; jbundles[j]->ramchain); + sleep(3); + } + if ( iguana_validated(coin) < n || iguana_utxofinished(coin) < n || iguana_balancefinished(coin) < n ) + { + coin->spendvectorsaved = 1; + printf("update volatile data, need.%d vs utxo.%d balances.%d validated.%d\n",n,iguana_utxofinished(coin),iguana_balancefinished(coin),iguana_validated(coin)); + } + else + { + coin->spendvectorsaved = (uint32_t)time(NULL); + //printf("already done UTXOGEN (%d %d) (%d %d)\n",iguana_utxofinished(coin),n,iguana_balancefinished(coin),n); + } + } //else printf("only emit.%d vs %d\n",iguana_emitfinished(coin),n); + } + if ( (bp= coin->current) != 0 && coin->stucktime != 0 && coin->isRT == 0 && coin->RTheight == 0 && (time(NULL) - coin->stucktime) > coin->MAXSTUCKTIME ) + { + if ( 0 ) { - if ( 0 ) + printf("%s is stuck too long, restarting due to %d\n",coin->symbol,bp->hdrsi); + if ( coin->started != 0 ) { - printf("%s is stuck too long, restarting due to %d\n",coin->symbol,bp->hdrsi); - if ( coin->started != 0 ) + iguana_coinpurge(coin); + sleep(3); + while ( coin->started == 0 ) { - iguana_coinpurge(coin); - sleep(3); - while ( coin->started == 0 ) - { - printf("wait for coin to reactivate\n"); - sleep(1); - } - sleep(3); + printf("wait for coin to reactivate\n"); + sleep(1); } + sleep(3); } } - if ( 0 && flag != 0 ) - printf("call RT update busy.%d\n",coin->RTramchain_busy); } + if ( 0 && flag != 0 ) + printf("call RT update busy.%d\n",coin->RTramchain_busy); } + } + //portable_mutex_unlock(&Allcoins_mutex); } - pangea_queues(SuperNET_MYINFO(0)); + //pangea_queues(SuperNET_MYINFO(0)); if ( flag == 0 ) usleep(10000 + isRT*100000 + (numpeers == 0)*1000000); //iguana_jsonQ(); // cant do this here safely, need to send to coin specific queue @@ -1241,6 +1210,7 @@ void iguana_ensuredirs() { char dirname[512]; sprintf(dirname,"%s",GLOBAL_HELPDIR), OS_ensure_directory(dirname); + sprintf(dirname,"%s",GLOBAL_GENESISDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s",GLOBAL_CONFSDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s/purgeable",GLOBAL_DBDIR), OS_ensure_directory(dirname); @@ -1258,7 +1228,7 @@ void iguana_Qinit() iguana_initQ(&finishedQ,"finishedQ"); iguana_initQ(&bundlesQ,"bundlesQ"); iguana_initQ(&emitQ,"emitQ"); - iguana_initQ(&TerminateQ,"TerminateQ"); + //iguana_initQ(&TerminateQ,"TerminateQ"); } void iguana_helpinit(struct supernet_info *myinfo) @@ -1350,15 +1320,17 @@ void iguana_main(void *arg) iguana_Qinit(); myinfo = SuperNET_MYINFO(0); myinfo->rpcport = IGUANA_RPCPORT; + portable_mutex_init(&myinfo->allcoins_mutex); strcpy(myinfo->rpcsymbol,"BTCD"); iguana_urlinit(myinfo,ismainnet,usessl); - category_init(myinfo); + //category_init(myinfo); exchange_create("bitcoin",0); argjson = arg != 0 ? cJSON_Parse(arg) : cJSON_Parse("{}"); //iguana_coinadd("BTC",argjson); dont do this here, coin args not set ///iguana_coinadd("LTC",argjson); free_json(argjson); iguana_helpinit(myinfo); + basilisks_init(myinfo); iguana_commandline(myinfo,arg); #ifdef __APPLE__ iguana_appletests(myinfo); @@ -1366,3 +1338,765 @@ void iguana_main(void *arg) iguana_launchdaemons(myinfo); } +void *SuperNET_deciphercalc(void **ptrp,int32_t *msglenp,bits256 privkey,bits256 srcpubkey,uint8_t *cipher,int32_t cipherlen,uint8_t *buf,int32_t bufsize) +{ + uint8_t *origptr,*nonce,*message; void *retptr; + if ( bits256_nonz(privkey) == 0 ) + privkey = GENESIS_PRIVKEY; + *ptrp = 0; + if ( cipherlen > bufsize ) + { + message = calloc(1,cipherlen); + *ptrp = (void *)message; + } + else message = buf; + origptr = cipher; + if ( bits256_nonz(srcpubkey) == 0 ) + { + memcpy(srcpubkey.bytes,cipher,sizeof(srcpubkey)); + char str[65]; printf("use attached pubkey.(%s)\n",bits256_str(str,srcpubkey)); + cipher += sizeof(srcpubkey); + cipherlen -= sizeof(srcpubkey); + } + nonce = cipher; + cipher += crypto_box_NONCEBYTES, cipherlen -= crypto_box_NONCEBYTES; + *msglenp = cipherlen - crypto_box_ZEROBYTES; + if ( (retptr= _SuperNET_decipher(nonce,cipher,message,cipherlen,srcpubkey,privkey)) == 0 ) + { + *msglenp = -1; + free(*ptrp); + } + return(retptr); +} + +uint8_t *SuperNET_ciphercalc(void **ptrp,int32_t *cipherlenp,bits256 *privkeyp,bits256 *destpubkeyp,uint8_t *data,int32_t datalen,uint8_t *space2,int32_t space2size) +{ + bits256 mypubkey; uint8_t *buf,*nonce,*cipher,*origptr,space[8192]; int32_t onetimeflag=0,allocsize; + *ptrp = 0; + allocsize = (datalen + crypto_box_NONCEBYTES + crypto_box_ZEROBYTES); + if ( bits256_nonz(*destpubkeyp) == 0 || memcmp(destpubkeyp->bytes,GENESIS_PUBKEY.bytes,sizeof(*destpubkeyp)) == 0 ) + { + *destpubkeyp = GENESIS_PUBKEY; + onetimeflag = 2; // prevent any possible leakage of privkey by encrypting to known destpub + } + if ( bits256_nonz(*privkeyp) == 0 ) + onetimeflag = 1; + if ( onetimeflag != 0 ) + { + crypto_box_keypair(mypubkey.bytes,privkeyp->bytes); + allocsize += sizeof(bits256); + } + if ( allocsize > sizeof(space) ) + buf = calloc(1,allocsize); + else buf = space; + if ( allocsize+sizeof(struct iguana_msghdr) > space2size ) + { + cipher = calloc(1,allocsize + sizeof(struct iguana_msghdr)); + *ptrp = (void *)cipher; + } else cipher = space2; + cipher = &cipher[sizeof(struct iguana_msghdr)]; + origptr = nonce = cipher; + if ( onetimeflag != 0 ) + { + memcpy(cipher,mypubkey.bytes,sizeof(mypubkey)); + nonce = &cipher[sizeof(mypubkey)]; + } + OS_randombytes(nonce,crypto_box_NONCEBYTES); + cipher = &nonce[crypto_box_NONCEBYTES]; + _SuperNET_cipher(nonce,cipher,(void *)data,datalen,*destpubkeyp,*privkeyp,buf); + if ( buf != space ) + free(buf); + *cipherlenp = allocsize; + return(origptr); +} + +cJSON *SuperNET_rosettajson(bits256 privkey,int32_t showprivs) +{ + uint8_t rmd160[20],pub[33]; uint64_t nxt64bits; bits256 pubkey; + char str2[41],wifbuf[64],addr[64],str[128]; cJSON *retjson; + pubkey = acct777_pubkey(privkey); + nxt64bits = acct777_nxt64bits(pubkey); + retjson = cJSON_CreateObject(); + jaddbits256(retjson,"pubkey",pubkey); + RS_encode(str,nxt64bits); + jaddstr(retjson,"RS",str); + jadd64bits(retjson,"NXT",nxt64bits); + bitcoin_pubkey33(0,pub,privkey); + init_hexbytes_noT(str,pub,33); + jaddstr(retjson,"btcpubkey",str); + calc_OP_HASH160(str2,rmd160,str); + jaddstr(retjson,"rmd160",str2); + if ( bitcoin_address(addr,0,pub,33) != 0 ) + { + jaddstr(retjson,"BTC",addr); + if ( showprivs != 0 ) + { + bitcoin_priv2wif(wifbuf,privkey,128); + jaddstr(retjson,"BTCwif",wifbuf); + } + } + if ( bitcoin_address(addr,60,pub,33) != 0 ) + { + jaddstr(retjson,"BTCD",addr); + if ( showprivs != 0 ) + { + bitcoin_priv2wif(wifbuf,privkey,188); + jaddstr(retjson,"BTCDwif",wifbuf); + } + } + if ( showprivs != 0 ) + jaddbits256(retjson,"privkey",privkey); + return(retjson); +} + +cJSON *SuperNET_peerarray(struct iguana_info *coin,int32_t max,int32_t supernetflag) +{ + int32_t i,r,j,n = 0; struct iguana_peer *addr; cJSON *array = cJSON_CreateArray(); + r = rand(); + for (j=0; jpeers->active[i]; + if ( addr->usock >= 0 && supernetflag == (addr->supernet != 0) ) + { + jaddistr(array,addr->ipaddr); + if ( ++n >= max ) + break; + } + } + if ( n == 0 ) + { + free_json(array); + return(0); + } + return(array); +} + +int32_t SuperNET_coinpeers(struct iguana_info *coin,cJSON *SNjson,cJSON *rawjson,int32_t max) +{ + cJSON *array,*item; + if ( (array= SuperNET_peerarray(coin,max,1)) != 0 ) + { + max -= cJSON_GetArraySize(array); + item = cJSON_CreateObject(); + jaddstr(item,"coin",coin->symbol); + jadd(item,"peers",array); + jaddi(SNjson,item); + } + if ( max > 0 && (array= SuperNET_peerarray(coin,max,0)) != 0 ) + { + max -= cJSON_GetArraySize(array); + item = cJSON_CreateObject(); + jaddstr(item,"coin",coin->symbol); + jadd(item,"peers",array); + jaddi(rawjson,item); + } + return(max); +} + +void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag) +{ + uint64_t ipbits; struct iguana_peer *addr; + ipbits = calc_ipbits(ipaddr); + printf("got %s remotepeer.(%s) supernet.%d\n",symbol,ipaddr,supernetflag); + if ( supernetflag != 0 && (uint32_t)myinfo->myaddr.selfipbits != (uint32_t)ipbits ) + { + if ( (addr= iguana_peerslot(coin,ipbits,0)) != 0 ) + { + printf("launch startconnection to supernet peer.(%s)\n",ipaddr); + iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); + return; + } + } + iguana_possible_peer(coin,ipaddr); +} + +void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int32_t supernetflag) +{ + int32_t i,j,m; cJSON *coinarray,*item; char *symbol,*ipaddr; struct iguana_info *ptr; + if ( array != 0 && n > 0 ) + { + for (i=0; ichain->pubtype,rmdbuf,20); + bitcoin_address(p2shaddr,coin->chain->p2shtype,rmdbuf,20); + jaddstr(retjson,"result","success"); + jaddstr(retjson,"address",coinaddr); + jaddstr(retjson,"p2sh",p2shaddr); + } + return(jprint(retjson,1)); +} + +HASH_AND_INT(SuperNET,priv2pub,privkey,addrtype) +{ + cJSON *retjson; bits256 pub; uint8_t pubkey[33]; char coinaddr[64],pubkeystr[67]; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + retjson = cJSON_CreateObject(); + crypto_box_priv2pub(pub.bytes,privkey.bytes); + jaddbits256(retjson,"curve25519",pub); + pub = bitcoin_pubkey33(myinfo->ctx,pubkey,privkey); + init_hexbytes_noT(pubkeystr,pubkey,33); + jaddstr(retjson,"secp256k1",pubkeystr); + bitcoin_address(coinaddr,addrtype,pubkey,33); + jaddstr(retjson,"result",coinaddr); + return(jprint(retjson,1)); +} + +ZERO_ARGS(SuperNET,keypair) +{ + cJSON *retjson; bits256 pubkey,privkey; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + retjson = cJSON_CreateObject(); + crypto_box_keypair(pubkey.bytes,privkey.bytes); + jaddstr(retjson,"result","generated keypair"); + jaddbits256(retjson,"privkey",privkey); + jaddbits256(retjson,"pubkey",pubkey); + return(jprint(retjson,1)); +} + +TWOHASHES_AND_STRING(SuperNET,decipher,privkey,srcpubkey,cipherstr) +{ + int32_t cipherlen=0,msglen; char *retstr; cJSON *retjson; void *ptr = 0; uint8_t *cipher,*message,space[8192]; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + if ( cipherstr != 0 ) + cipherlen = (int32_t)strlen(cipherstr) >> 1; + if ( cipherlen < crypto_box_NONCEBYTES ) + return(clonestr("{\"error\":\"cipher is too short\"}")); + cipher = calloc(1,cipherlen); + decode_hex(cipher,cipherlen,cipherstr); + if ( (message= SuperNET_deciphercalc(&ptr,&msglen,privkey,srcpubkey,cipher,cipherlen,space,sizeof(space))) != 0 ) + { + message[msglen] = 0; + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","deciphered message"); + jaddstr(retjson,"message",(char *)message); + retstr = jprint(retjson,1); + if ( ptr != 0 ) + free(ptr); + } else retstr = clonestr("{\"error\":\"couldnt decipher message\"}"); + return(retstr); +} + +TWOHASHES_AND_STRING(SuperNET,cipher,privkey,destpubkey,message) +{ + cJSON *retjson; char *retstr,*hexstr,space[8129]; uint8_t space2[8129]; + uint8_t *cipher; int32_t cipherlen,onetimeflag; bits256 origprivkey; void *ptr = 0; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + if ( (cipher= SuperNET_ciphercalc(&ptr,&cipherlen,&privkey,&destpubkey,(uint8_t *)message,(int32_t)strlen(message)+1,space2,sizeof(space2))) != 0 ) + { + if ( cipherlen > sizeof(space)/2 ) + hexstr = calloc(1,(cipherlen<<1)+1); + else hexstr = (void *)space; + init_hexbytes_noT(hexstr,cipher,cipherlen); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",hexstr); + onetimeflag = memcmp(origprivkey.bytes,privkey.bytes,sizeof(privkey)); + if ( onetimeflag != 0 ) + { + //jaddbits256(retjson,"onetime_privkey",privkey); + jaddbits256(retjson,"onetime_pubkey",destpubkey); + if ( onetimeflag == 2 ) + jaddstr(retjson,"warning","onetime keypair was used to broadcast"); + } + retstr = jprint(retjson,1); + if ( hexstr != (void *)space ) + free(hexstr); + if ( ptr != 0 ) + free(ptr); + return(retstr); + } + printf("error encrypting message.(%s)\n",message); + return(clonestr("{\"error\":\"cant encrypt message\"}")); +} + +bits256 SuperNET_pindecipher(IGUANA_ARGS,char *pin,char *privcipher) +{ + cJSON *testjson; char *mstr,*cstr; bits256 privkey,pinpriv,pinpub; + conv_NXTpassword(pinpriv.bytes,pinpub.bytes,(uint8_t *)pin,(int32_t)strlen(pin)); + privkey = GENESIS_PRIVKEY; + if ( (cstr= SuperNET_decipher(IGUANA_CALLARGS,pinpriv,pinpub,privcipher)) != 0 ) + { + if ( (testjson= cJSON_Parse(cstr)) != 0 ) + { + if ( (mstr= jstr(testjson,"message")) != 0 && strlen(mstr) == sizeof(bits256)*2 ) + { + decode_hex(privkey.bytes,sizeof(privkey),mstr); + } else printf("error cant find message privcipher\n"); + free_json(testjson); + } else printf("Error decipher.(%s)\n",cstr); + free(cstr); + } else printf("null return from deciphering privcipher\n"); + return(privkey); +} + +THREE_STRINGS(SuperNET,rosetta,passphrase,pin,showprivkey) +{ + uint8_t flag = 0; uint64_t nxt64bits; bits256 check,privkey,pubkey,pinpriv,pinpub; + char str[128],privcipher[512],*privcipherstr,*cstr; cJSON *retjson; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + nxt64bits = conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); + if ( showprivkey != 0 && strcmp(showprivkey,"yes") == 0 ) + flag = 1; + privcipher[0] = 0; + conv_NXTpassword(pinpriv.bytes,pinpub.bytes,(uint8_t *)pin,(int32_t)strlen(pin)); + if ( (cstr= SuperNET_cipher(IGUANA_CALLARGS,pinpriv,pinpub,bits256_str(str,privkey))) != 0 ) + { + if ( (retjson= cJSON_Parse(cstr)) != 0 ) + { + if ( (privcipherstr= jstr(retjson,"result")) != 0 ) + strcpy(privcipher,privcipherstr); + free_json(retjson); + } else printf("error parsing cipher retstr.(%s)\n",cstr); + free(cstr); + } else printf("error SuperNET_cipher null return\n"); + retjson = SuperNET_rosettajson(privkey,flag); + jaddstr(retjson,"privcipher",privcipher); + check = SuperNET_pindecipher(IGUANA_CALLARGS,pin,privcipher); + if ( memcmp(check.bytes,privkey.bytes,sizeof(check)) != 0 ) + { + jaddbits256(retjson,"deciphered",check); + jaddstr(retjson,"error","cant recreate privkey from (pin + privcipher)"); + } + else if ( flag != 0 ) + jaddbits256(retjson,"deciphered",check); + if ( jobj(retjson,"error") == 0 ) + jaddstr(retjson,"result","use pin and privcipher to access wallet"); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,broadcastcipher,message) +{ + bits256 zero; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + memset(zero.bytes,0,sizeof(zero)); + return(SuperNET_cipher(IGUANA_CALLARGS,zero,zero,message)); +} + +STRING_ARG(SuperNET,broadcastdecipher,message) +{ + bits256 zero; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + memset(zero.bytes,0,sizeof(zero)); + return(SuperNET_decipher(IGUANA_CALLARGS,zero,zero,message)); +} + +HASH_AND_STRING(SuperNET,multicastcipher,pubkey,message) +{ + bits256 zero; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + memset(zero.bytes,0,sizeof(zero)); + return(SuperNET_cipher(IGUANA_CALLARGS,zero,pubkey,message)); +} + +HASH_AND_STRING(SuperNET,multicastdecipher,privkey,cipherstr) +{ + bits256 zero; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + memset(zero.bytes,0,sizeof(zero)); + return(SuperNET_decipher(IGUANA_CALLARGS,privkey,zero,cipherstr)); +} + +ZERO_ARGS(SuperNET,stop) +{ + if ( remoteaddr == 0 || strncmp(remoteaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 ) + { + iguana_exit(); + return(clonestr("{\"result\":\"exit started\"}")); + } else return(clonestr("{\"error\":\"cant do a remote stop of this node\"}")); +} + +TWO_ARRAYS(SuperNET,mypeers,supernet,rawpeers) +{ + SuperNET_parsepeers(myinfo,supernet,cJSON_GetArraySize(supernet),1); + SuperNET_parsepeers(myinfo,rawpeers,cJSON_GetArraySize(rawpeers),0); + return(clonestr("{\"result\":\"peers parsed\"}")); +} + +STRING_ARG(SuperNET,getpeers,activecoin) +{ + int32_t max = 64; struct iguana_info *tmp; cJSON *SNjson,*rawjson,*retjson = cJSON_CreateObject(); + SNjson = cJSON_CreateArray(); + rawjson = cJSON_CreateArray(); + if ( coin != 0 ) + max = SuperNET_coinpeers(coin,SNjson,rawjson,max); + else + { + //portable_mutex_lock(&Allcoins_mutex); + HASH_ITER(hh,myinfo->allcoins,coin,tmp) + { + max = SuperNET_coinpeers(coin,SNjson,rawjson,max); + } + //portable_mutex_unlock(&Allcoins_mutex); + } + if ( max != 64 ) + { + jaddstr(retjson,"agent","SuperNET"); + jaddstr(retjson,"method","mypeers"); + jadd(retjson,"supernet",SNjson); + jadd(retjson,"rawpeers",rawjson); + } + else + { + jaddstr(retjson,"error","no peers"); + free_json(SNjson); + free_json(rawjson); + } + return(jprint(retjson,1)); +} + +/*TWOSTRINGS_AND_TWOHASHES_AND_TWOINTS(SuperNET,DHT,hexmsg,destip,categoryhash,subhash,maxdelay,broadcast) + { + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"cant remote DHT\"}")); + else if ( hexmsg == 0 || is_hexstr(hexmsg,(int32_t)strlen(hexmsg)) <= 0 ) + return(clonestr("{\"error\":\"hexmsg missing or not in hex\"}")); + return(SuperNET_DHTencode(myinfo,destip,categoryhash,subhash,hexmsg,maxdelay,broadcast,juint(json,"plaintext")!=0)); + }*/ + +HASH_AND_STRING(SuperNET,saveconf,wallethash,confjsonstr) +{ + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + return(clonestr("{\"result\":\"saveconf here\"}")); +} + +HASH_ARRAY_STRING(SuperNET,layer,mypriv,otherpubs,str) +{ + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + return(clonestr("{\"result\":\"layer encrypt here\"}")); +} + +/*TWO_STRINGS(SuperNET,categoryhashes,category,subcategory) +{ + bits256 categoryhash,subhash; cJSON *retjson = cJSON_CreateObject(); + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + jaddstr(retjson,"result","category hashes calculated"); + jaddbits256(retjson,"categoryhash",categoryhash); + jaddbits256(retjson,"subhash",subhash); + return(jprint(retjson,1)); +} + +TWO_STRINGS(SuperNET,subscribe,category,subcategory) +{ + bits256 categoryhash,subhash; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + if ( category_subscribe(myinfo,categoryhash,subhash) != 0 ) + return(clonestr("{\"result\":\"subscribed\"}")); + else return(clonestr("{\"error\":\"couldnt subscribe\"}")); +} + +TWO_STRINGS(SuperNET,gethexmsg,category,subcategory) +{ + bits256 categoryhash,subhash; struct category_msg *m; char *hexstr; cJSON *retjson; struct private_chain *cat; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + if ( (m= category_gethexmsg(myinfo,&cat,categoryhash,subhash)) != 0 ) + { + hexstr = calloc(1,m->len*2+1); + init_hexbytes_noT(hexstr,m->msg,m->len); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",hexstr); + free(hexstr); + return(jprint(retjson,1)); + } else return(clonestr("{\"result\":\"no message\"}")); +} + +THREE_STRINGS(SuperNET,posthexmsg,category,subcategory,hexmsg) +{ + bits256 categoryhash,subhash; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + category_posthexmsg(myinfo,categoryhash,subhash,hexmsg,tai_now(),remoteaddr); + return(clonestr("{\"result\":\"posted message\"}")); +} + +THREE_STRINGS(SuperNET,announce,category,subcategory,message) +{ + bits256 categoryhash,subhash; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + return(SuperNET_categorymulticast(myinfo,0,categoryhash,subhash,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext"),json,remoteaddr)); +} + +THREE_STRINGS(SuperNET,survey,category,subcategory,message) +{ + bits256 categoryhash,subhash; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + categoryhash = calc_categoryhashes(&subhash,category,subcategory); + return(SuperNET_categorymulticast(myinfo,1,categoryhash,subhash,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext"),json,remoteaddr)); +}*/ + +STRING_ARG(SuperNET,wif2priv,wif) +{ + bits256 privkey; char str[65]; uint8_t privkeytype; cJSON *retjson = cJSON_CreateObject(); + if ( bitcoin_wif2priv(&privkeytype,&privkey,wif) == sizeof(privkey) ) + { + jaddstr(retjson,"result","success"); + jaddstr(retjson,"privkey",bits256_str(str,privkey)); + jaddnum(retjson,"type",privkeytype); + } else jaddstr(retjson,"error","couldnt convert wif"); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,priv2wif,priv) +{ + bits256 privkey; char wifstr[65]; uint8_t wiftype; cJSON *retjson = cJSON_CreateObject(); + if ( is_hexstr(priv,0) == sizeof(bits256)*2 ) + { + wiftype = coin != 0 ? coin->chain->wiftype : 0x80; + decode_hex(privkey.bytes,sizeof(privkey),priv); + if ( bitcoin_priv2wif(wifstr,privkey,wiftype) > 0 ) + { + jaddstr(retjson,"result","success"); + jaddstr(retjson,"privkey",priv); + jaddnum(retjson,"type",wiftype); + jaddstr(retjson,"wif",wifstr); + } else jaddstr(retjson,"error","couldnt convert privkey"); + } else jaddstr(retjson,"error","non 32 byte hex privkey"); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,myipaddr,ipaddr) +{ + cJSON *retjson = cJSON_CreateObject(); + if ( myinfo->ipaddr[0] == 0 ) + { + if ( is_ipaddr(ipaddr) != 0 ) + strcpy(myinfo->ipaddr,ipaddr); + } + jaddstr(retjson,"result",myinfo->ipaddr); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,setmyipaddr,ipaddr) +{ + cJSON *retjson = cJSON_CreateObject(); + if ( is_ipaddr(ipaddr) != 0 ) + { + strcpy(myinfo->ipaddr,ipaddr); + jaddstr(retjson,"result",myinfo->ipaddr); + } else jaddstr(retjson,"error","illegal ipaddr"); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,utime2utc,utime) +{ + uint32_t utc = 0; cJSON *retjson = cJSON_CreateObject(); + utc = OS_conv_utime(utime); + char str[65]; printf("utime.%s -> %u -> %s\n",utime,utc,utc_str(str,utc)); + jaddnum(retjson,"result",utc); + return(jprint(retjson,1)); +} + +INT_ARG(SuperNET,utc2utime,utc) +{ + char str[65]; cJSON *retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",utc_str(str,utc)); + return(jprint(retjson,1)); +} + +ZERO_ARGS(SuperNET,logout) +{ + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + iguana_walletlock(myinfo,coin); + return(clonestr("{\"result\":\"logged out\"}")); +} + +ZERO_ARGS(SuperNET,activehandle) +{ + cJSON *retjson; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + retjson = SuperNET_rosettajson(myinfo->persistent_priv,0); + jaddstr(retjson,"result","success"); + jaddstr(retjson,"handle",myinfo->handle); + jaddbits256(retjson,"persistent",myinfo->myaddr.persistent); + if ( myinfo->expiration != 0 ) + { + jaddstr(retjson,"status","unlocked"); + jaddnum(retjson,"duration",myinfo->expiration - time(NULL)); + } else jaddstr(retjson,"status","locked"); + SuperNET_MYINFOadd(myinfo); + return(jprint(retjson,1)); +} + +struct supernet_info *SuperNET_accountfind(cJSON *json) +{ + int32_t num; char *decryptstr; struct supernet_info M,*myinfo; struct iguana_info *coin = 0; + char *password,*permanentfile,*passphrase,*remoteaddr,*perspriv; + myinfo = 0; + if ( (password= jstr(json,"password")) == 0 ) + password = ""; + if ( (permanentfile= jstr(json,"permanentfile")) == 0 ) + permanentfile = ""; + if ( (passphrase= jstr(json,"passphrase")) == 0 ) + passphrase = ""; + remoteaddr = jstr(json,"remoteaddr"); + if ( (passphrase == 0 || passphrase[0] == 0) && (decryptstr= SuperNET_decryptjson(IGUANA_CALLARGS,password,permanentfile)) != 0 ) + { + if ( (json= cJSON_Parse(decryptstr)) != 0 ) + { + memset(&M,0,sizeof(M)); + if ( (perspriv= jstr(json,"persistent_priv")) != 0 && strlen(perspriv) == sizeof(bits256)*2 ) + { + M.persistent_priv = bits256_conv(perspriv); + SuperNET_setkeys(&M,0,0,0); + if ( (myinfo = SuperNET_MYINFOfind(&num,M.myaddr.persistent)) != 0 ) + { + //printf("found account.(%s) %s %llu\n",myinfo!=0?myinfo->handle:"",M.myaddr.NXTADDR,(long long)M.myaddr.nxt64bits); + return(myinfo); + } + } + else if ( (passphrase= jstr(json,"result")) != 0 || (passphrase= jstr(json,"passphrase")) != 0 ) + { + SuperNET_setkeys(&M,passphrase,(int32_t)strlen(passphrase),1); + if ( (myinfo= SuperNET_MYINFOfind(&num,M.myaddr.persistent)) != 0 ) + { + //printf("found account.(%s) %s %llu\n",myinfo!=0?myinfo->handle:"",M.myaddr.NXTADDR,(long long)M.myaddr.nxt64bits); + return(myinfo); + } + } else printf("no passphrase in (%s)\n",jprint(json,0)); + free_json(json); + } else printf("cant parse.(%s)\n",decryptstr); + free(decryptstr); + } + return(SuperNET_MYINFO(0)); +} + +FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase) +{ + char *str,*decryptstr = 0; cJSON *argjson,*item,*walletitem; + if ( remoteaddr != 0 ) + return(clonestr("{\"error\":\"no remote\"}")); + if ( handle != 0 && handle[0] != 0 ) + safecopy(myinfo->handle,handle,sizeof(myinfo->handle)); + else memset(myinfo->handle,0,sizeof(myinfo->handle)); + if ( password == 0 || password[0] == 0 ) + password = passphrase; + /*if ( password != 0 && password[0] != 0 ) + safecopy(myinfo->secret,password,sizeof(myinfo->secret)); + else if ( passphrase != 0 && passphrase[0] != 0 ) + safecopy(myinfo->secret,passphrase,sizeof(myinfo->secret));*/ + if ( permanentfile != 0 ) + safecopy(myinfo->permanentfile,permanentfile,sizeof(myinfo->permanentfile)); + if ( (decryptstr= SuperNET_decryptjson(IGUANA_CALLARGS,password,myinfo->permanentfile)) != 0 ) + { + if ( (argjson= cJSON_Parse(decryptstr)) != 0 ) + { + if ( jobj(argjson,"error") == 0 ) + { + //printf("decrypted.(%s) exp.%u pass.(%s)\n",decryptstr,myinfo->expiration,password); + if ( myinfo->decryptstr != 0 ) + free(myinfo->decryptstr); + myinfo->decryptstr = decryptstr; + if ( (passphrase= jstr(argjson,"passphrase")) != 0 ) + { + SuperNET_setkeys(myinfo,passphrase,(int32_t)strlen(passphrase),1); + free_json(argjson); + myinfo->expiration = (uint32_t)(time(NULL) + 3600); + return(SuperNET_activehandle(IGUANA_CALLARGS)); + } + else + { + free_json(argjson); + return(clonestr("{\"error\":\"cant find passphrase in decrypted json\"}")); + } + } else free_json(argjson); + } + else + { + free(decryptstr); + return(clonestr("{\"error\":\"cant parse decrypted json\"}")); + } + } + if ( passphrase != 0 && passphrase[0] != 0 ) + { + SuperNET_setkeys(myinfo,passphrase,(int32_t)strlen(passphrase),1); + if ( myinfo->decryptstr != 0 && (argjson= cJSON_Parse(myinfo->decryptstr)) != 0 ) + { + if ( jobj(argjson,"passphrase") != 0 ) + jdelete(argjson,"passphrase"); + if ( jobj(argjson,"error") != 0 ) + jdelete(argjson,"error"); + } + else + { + char rmd160str[41],str[65]; uint8_t rmd160[20]; + item = cJSON_CreateObject(); + calc_rmd160_sha256(rmd160,myinfo->persistent_pubkey33,33); + init_hexbytes_noT(rmd160str,rmd160,20); + jaddstr(item,rmd160str,bits256_str(str,myinfo->persistent_priv)); + walletitem = cJSON_CreateObject(); + jadd(walletitem,"default",item); + argjson = cJSON_CreateObject(); + jadd(argjson,"wallet",walletitem); + myinfo->dirty = (uint32_t)time(NULL); + } + jaddstr(argjson,"passphrase",passphrase); + if ( (str= SuperNET_encryptjson(myinfo,coin,argjson,remoteaddr,password,myinfo->permanentfile,"")) != 0 ) + free(str); + myinfo->expiration = (uint32_t)(time(NULL) + 3600); + return(SuperNET_activehandle(IGUANA_CALLARGS)); + } else return(clonestr("{\"error\":\"need passphrase\"}")); + printf("logged into (%s) %s %s\n",myinfo->myaddr.NXTADDR,myinfo->myaddr.BTC,myinfo->myaddr.BTCD); + return(SuperNET_activehandle(IGUANA_CALLARGS)); +} + +#include "../includes/iguana_apiundefs.h" diff --git a/iguana/pangea_api.c b/iguana/pangea_api.c index 7f108f136..3329fd45f 100755 --- a/iguana/pangea_api.c +++ b/iguana/pangea_api.c @@ -183,8 +183,8 @@ struct table_info *pangea_tablealloc(struct table_info *tp,int32_t N) struct table_info *pangea_table(struct supernet_info *myinfo,bits256 tablehash,int32_t N) { - struct table_info *tp; char str[65]; - if ( (tp= private_chain(myinfo->pangea_category,tablehash)) == 0 && N > 0 ) + /*struct table_info *tp; char str[65]; + if ( (tp= gecko_chain(myinfo->pangea_category,tablehash)) == 0 && N > 0 ) { tp = pangea_tablealloc(0,N); memset(tp,0,sizeof(*tp)); @@ -197,11 +197,12 @@ struct table_info *pangea_table(struct supernet_info *myinfo,bits256 tablehash,i if ( tp != 0 ) { category_subscribe(SuperNET_MYINFO(0),myinfo->pangea_category,tablehash); - if ( private_chainset(myinfo->pangea_category,tablehash,tp) == 0 ) + if ( gecko_chainset(myinfo->pangea_category,tablehash,tp) == 0 ) printf("error: couldnt set table.(%s)\n",bits256_str(str,tablehash)), tp = 0; //else tp->G.allocsize = allocsize; } - return(tp); + return(tp);*/ + return(0); } struct player_info *pangea_playerfind(struct supernet_info *myinfo,struct table_info *tp) @@ -219,7 +220,7 @@ struct player_info *pangea_playerfind(struct supernet_info *myinfo,struct table_ char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct pangea_msghdr *pm,cJSON *json,char *cmdstr,char *ipaddr) { - cJSON *argjson; char *reqstr,hexstr[8192]; uint64_t nxt64bits; struct table_info *tp; int32_t i,datalen; + /*cJSON *argjson; char *reqstr,hexstr[8192]; uint64_t nxt64bits; struct table_info *tp; int32_t i,datalen; category_subscribe(myinfo,myinfo->pangea_category,GENESIS_PUBKEY); category_subscribe(myinfo,myinfo->pangea_category,tablehash); argjson = json != 0 ? jduplicate(json) : cJSON_CreateObject(); @@ -266,12 +267,13 @@ char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct p { printf("cant msgcreate\n"); return(clonestr("{\"error\":\"couldnt create pangea message\"}")); - } + }*/ + return(0); } void pangea_sendcmd(struct supernet_info *myinfo,struct table_info *tp,char *cmdstr,int32_t destplayer,uint8_t *data,int32_t datalen,int32_t cardi,int32_t turni) { - struct player_info *p; struct pangea_msghdr *pm; char *str,*hexstr; int32_t plaintext,loopback = 0; + /*struct player_info *p; struct pangea_msghdr *pm; char *str,*hexstr; int32_t plaintext,loopback = 0; pm = calloc(1,sizeof(*pm) + datalen);//(void *)tp->space; memset(pm,0,sizeof(*pm)); strncpy(pm->cmd,cmdstr,8); @@ -304,7 +306,7 @@ void pangea_sendcmd(struct supernet_info *myinfo,struct table_info *tp,char *cmd } free(hexstr); } - free(pm); + free(pm);*/ } void pangea_tablejoin(struct supernet_info *myinfo,struct table_info *tp,uint8_t *data,int32_t datalen,uint64_t signer64bits,uint32_t sigtimestamp,bits256 sigtablehash) @@ -451,7 +453,7 @@ void pangea_addfunds(PANGEA_HANDARGS) printf("got remote addfunds\n"); } -char *pangea_hexmsg(struct supernet_info *myinfo,struct private_chain *cat,void *data,int32_t len,char *remoteaddr) +char *pangea_hexmsg(struct supernet_info *myinfo,struct gecko_chain *cat,void *data,int32_t len,char *remoteaddr) { static struct { char *cmdstr; void (*func)(PANGEA_HANDARGS); uint64_t cmdbits; } tablecmds[] = { @@ -511,7 +513,8 @@ char *pangea_hexmsg(struct supernet_info *myinfo,struct private_chain *cat,void allocsize = pangea_allocsize(tp,9,0); if ( tp->G.allocsize < allocsize ) tp = pangea_tablealloc(tp,9); - private_chainset(tp->G.gamehash,tp->G.tablehash,tp); + printf("deprecated usage of chainset\n"); + //gecko_chainset(tp->G.gamehash,tp->G.tablehash,tp); if ( strcmp(tablecmds[i].cmdstr,"newhand") == 0 ) { tp->G.numactive = pm->turni; @@ -538,7 +541,7 @@ char *pangea_hexmsg(struct supernet_info *myinfo,struct private_chain *cat,void void pangea_update(struct supernet_info *myinfo) { - struct pangea_msghdr *pm; struct category_msg *m; char remoteaddr[64],*str; struct private_chain *cat = 0; + /*struct pangea_msghdr *pm; struct category_msg *m; char remoteaddr[64],*str; struct gecko_chain *cat = 0; while ( (m= category_gethexmsg(myinfo,&cat,myinfo->pangea_category,GENESIS_PUBKEY)) != 0 ) { pm = (struct pangea_msghdr *)m->msg; @@ -548,7 +551,7 @@ void pangea_update(struct supernet_info *myinfo) if ( (str= pangea_hexmsg(myinfo,cat,pm,m->len,remoteaddr)) != 0 ) free(str); free(m); - } + }*/ } /* char *_pangea_status(struct supernet_info *myinfo,bits256 tablehash,cJSON *json) @@ -865,7 +868,8 @@ HASH_ARG(pangea,start,tablehash) if ( tp->G.allocsize < allocsize ) { tp = pangea_tablealloc(tp,9); - private_chainset(tp->G.gamehash,tp->G.tablehash,tp); + printf("deprecated usage of chainset\n"); + //gecko_chainset(tp->G.gamehash,tp->G.tablehash,tp); } if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits ) pangea_newdeck(myinfo,tp); diff --git a/iguana/pangea_hand.c b/iguana/pangea_hand.c index 117a07e0c..2d2d8728e 100755 --- a/iguana/pangea_hand.c +++ b/iguana/pangea_hand.c @@ -418,7 +418,7 @@ int32_t pangea_queueprocess(struct supernet_info *myinfo,struct table_info *tp) void pangea_queues(struct supernet_info *myinfo) { - struct private_chain *cat,*subchain,*tmp; //struct table_info *tp; + struct gecko_chain *cat,*subchain,*tmp; //struct table_info *tp; pangea_update(myinfo); if ( (cat= category_find(calc_categoryhashes(0,"pangea",0),GENESIS_PUBKEY)) != 0 ) { diff --git a/iguana/pangea_json.c b/iguana/pangea_json.c index eff9ed726..c325c4a69 100755 --- a/iguana/pangea_json.c +++ b/iguana/pangea_json.c @@ -107,7 +107,7 @@ int32_t pangea_opentable(struct game_info *gp) cJSON *pangea_lobbyjson(struct supernet_info *myinfo) { - struct private_chain *cat,*subchain,*tmp; cJSON *array,*retjson; //struct table_info *tp; + struct gecko_chain *cat,*subchain,*tmp; cJSON *array,*retjson; //struct table_info *tp; retjson = cJSON_CreateObject(); array = cJSON_CreateArray(); if ( (cat= category_find(calc_categoryhashes(0,"pangea",0),GENESIS_PUBKEY)) != 0 ) diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index be06ee032..9e9aa9d86 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -136,7 +136,7 @@ HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly) return(jprint(iguana_blockjson(coin,block,1),1)); else { - if ( (len= iguana_peerblockrequest(coin,coin->blockspace,sizeof(coin->blockspace),0,blockhash,0)) > 0 ) + if ( (len= iguana_peerblockrequest(coin,coin->blockspace,coin->blockspacesize,0,blockhash,0)) > 0 ) { datastr = malloc(len*2 + 1); init_hexbytes_noT(datastr,coin->blockspace,len); diff --git a/iguana/swaps/iguana_BTCswap.c b/iguana/swaps/iguana_BTCswap.c index c2207f739..a0a4d93dd 100755 --- a/iguana/swaps/iguana_BTCswap.c +++ b/iguana/swaps/iguana_BTCswap.c @@ -170,7 +170,7 @@ void iguana_addinputs(struct iguana_info *coin,struct bitcoin_spend *spend,cJSON struct bitcoin_statetx *instantdex_signtx(char *str,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 iguana_waccount *wacct; struct bitcoin_statetx *tx=0; uint8_t pubkey33[33]; char coinaddr[64],wifstr[64]; char *rawtx=0,*signedtx,*retstr; bits256 signedtxid; uint32_t basilisktag; int32_t flag,completed; cJSON *valsobj,*vins=0,*retjson=0,*privkey,*addresses; + struct iguana_waddress *waddr; struct iguana_waccount *wacct; struct bitcoin_statetx *tx=0; char coinaddr[64],wifstr[64]; char *rawtx=0,*signedtx,*retstr; bits256 signedtxid; uint32_t basilisktag; int32_t flag,completed; cJSON *valsobj,*vins=0,*retjson=0,*privkey,*addresses; if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 ) { printf("no change addr error\n"); @@ -180,10 +180,10 @@ struct bitcoin_statetx *instantdex_signtx(char *str,struct supernet_info *myinfo addresses = cJSON_CreateArray(); if ( coin->changeaddr[0] == 0 ) bitcoin_address(coin->changeaddr,coin->chain->pubtype,waddr->rmd160,20); - bitcoin_pubkey33(myinfo->ctx,pubkey33,myinfo->persistent_priv); - bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33); + //bitcoin_pubkey33(myinfo->ctx,pubkey33,myinfo->persistent_priv); + bitcoin_address(coinaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33); //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 ) + if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) { bitcoin_priv2wif(wifstr,waddr->privkey,coin->chain->wiftype); jaddistr(privkey,waddr->wifstr); diff --git a/includes/curve25519.h b/includes/curve25519.h index 5553262bb..cff0e0e02 100755 --- a/includes/curve25519.h +++ b/includes/curve25519.h @@ -78,4 +78,10 @@ uint64_t acct777_signtx(struct acct777_sig *sig,bits256 privkey,uint32_t timesta 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); +#include "../includes/tweetnacl.h" +int32_t _SuperNET_cipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 destpub,bits256 srcpriv,uint8_t *buf); +uint8_t *_SuperNET_decipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 srcpub,bits256 mypriv); +void *SuperNET_deciphercalc(void **ptrp,int32_t *msglenp,bits256 privkey,bits256 srcpubkey,uint8_t *cipher,int32_t cipherlen,uint8_t *buf,int32_t bufsize); +uint8_t *SuperNET_ciphercalc(void **ptrp,int32_t *cipherlenp,bits256 *privkeyp,bits256 *destpubkeyp,uint8_t *data,int32_t datalen,uint8_t *space2,int32_t space2size); + #endif diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index f640d2c30..ff0e1a2f8 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -18,14 +18,15 @@ INT_ARRAY_STRING(basilisk,balances,basilisktag,vals,activecoin); INT_ARRAY_STRING(basilisk,rawtx,basilisktag,vals,activecoin); INT_ARRAY_STRING(basilisk,value,basilisktag,vals,activecoin); INT_AND_ARRAY(basilisk,result,basilisktag,vals); +HASH_ARRAY_STRING(basilisk,geckogenesis,pubkey,vals,hexstr); -HASH_ARRAY_STRING(basilisk,newprivatechain,pubkey,vals,hexstr); +HASH_ARRAY_STRING(basilisk,newgeckochain,pubkey,vals,hexstr); HASH_ARRAY_STRING(basilisk,addrelay,pubkey,vals,hexstr); HASH_ARRAY_STRING(basilisk,dispatch,pubkey,vals,hexstr); HASH_ARRAY_STRING(basilisk,publish,pubkey,vals,hexstr); HASH_ARRAY_STRING(basilisk,subscribe,pubkey,vals,hexstr); -HASH_ARRAY_STRING(basilisk,privatetx,pubkey,vals,hexstr); -HASH_ARRAY_STRING(basilisk,privateblock,pubkey,vals,hexstr); +HASH_ARRAY_STRING(basilisk,geckotx,pubkey,vals,hexstr); +HASH_ARRAY_STRING(basilisk,geckoblock,pubkey,vals,hexstr); HASH_ARRAY_STRING(basilisk,forward,pubkey,vals,hexstr); HASH_ARRAY_STRING(basilisk,mailbox,pubkey,vals,hexstr); @@ -219,12 +220,12 @@ STRING_ARG(SuperNET,broadcastdecipher,message); HASH_AND_STRING(SuperNET,multicastcipher,pubkey,message); HASH_AND_STRING(SuperNET,multicastdecipher,privkey,cipherstr); -TWO_STRINGS(SuperNET,subscribe,category,subcategory); +/*TWO_STRINGS(SuperNET,subscribe,category,subcategory); TWO_STRINGS(SuperNET,gethexmsg,category,subcategory); THREE_STRINGS(SuperNET,posthexmsg,category,subcategory,hexmsg); THREE_STRINGS(SuperNET,announce,category,subcategory,message); THREE_STRINGS(SuperNET,survey,category,subcategory,message); -TWO_STRINGS(SuperNET,categoryhashes,category,subcategory); +TWO_STRINGS(SuperNET,categoryhashes,category,subcategory);*/ STRING_AND_TWOINTS(mouse,image,name,x,y); STRING_AND_TWOINTS(mouse,change,name,x,y); diff --git a/includes/iguana_defines.h b/includes/iguana_defines.h new file mode 100755 index 000000000..c680fc737 --- /dev/null +++ b/includes/iguana_defines.h @@ -0,0 +1,193 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef H_IGUANADEFINES_H +#define H_IGUANADEFINES_H + +#define SPARSECOUNT(x) ((x) << 1) + +#define IGUANA_MAXSCRIPTSIZE 10001 +#define IGUANA_SERIALIZE_SPENDVECTORGEN +//#define IGUANA_DISABLEPEERS +#define _IGUANA_MAXSTUCKTIME 10 +#ifdef __PNACL__ +#define IGUANA_MAXITERATIONS 77 +#else +#define IGUANA_MAXITERATIONS 10000 +#endif +#define IGUANA_DEFAULTLAG 30 + +#define IGUANA_MAXHEIGHT (1 << 30) +#define IGUANA_MAXCOINS 64 +#define IGUANA_MAXDELAY_MILLIS (3600 * 1000 * 24) +#define IGUANA_DEFAULT_POLLTIMEOUT 10 + +#define IGUANA_EXCHANGEIDLE 10 +#define IGUANS_JSMILLIS 100 + +#define IGUANA_WIDTH 1024 +#define IGUANA_HEIGHT 200 + +#define IGUANA_HEADPERCENTAGE 0. +#define IGUANA_TAILPERCENTAGE 1.0 +#define IGUANA_MAXPENDHDRS 1 +#define IGUANA_MAXPENDINGREQUESTS 8 +#define IGUANA_PENDINGREQUESTS 500 +#define IGUANA_MINPENDBUNDLES 4 +#define IGUANA_MAXPENDBUNDLES 64 +#ifdef __APPLE__ +#define IGUANA_RPCPORT 7778 +#else +#define IGUANA_RPCPORT 7778 +#endif +#define IGUANA_MAXRAMCHAINSIZE ((uint64_t)1024L * 1024L * 1024L * 16) + +#define IGUANA_MAPHASHTABLES 1 +#define IGUANA_DEFAULTRAM 4 +#define IGUANA_MAXRECVCACHE ((int64_t)1024L * 1024 * 1024L) +#define IGUANA_MAXBUNDLES (50000000 / 500) + +#define IGUANA_MINPEERS 24 +#define IGUANA_LOG2MAXPEERS 10 +#define IGUANA_LOG2PACKETSIZE 21 +#define IGUANA_LOG2PEERFILESIZE 23 + +#define IGUANA_MAXPEERS (1 << IGUANA_LOG2MAXPEERS) +#define IGUANA_MAXPACKETSIZE (1 << IGUANA_LOG2PACKETSIZE) +#define IGUANA_PEERFILESIZE (1 << IGUANA_LOG2PEERFILESIZE) +struct iguana_txdatabits { uint64_t addrind:IGUANA_LOG2MAXPEERS,filecount:10,fpos:IGUANA_LOG2PEERFILESIZE,datalen:IGUANA_LOG2PACKETSIZE,isdir:1; }; + +#define IGUANA_MAXFILEITEMS 8192 +#define IGUANA_RECENTPEER (3600 * 24 * 7) + +#define IGUANA_PERMTHREAD 0 +#define IGUANA_CONNTHREAD 1 +#define IGUANA_SENDTHREAD 2 +#define IGUANA_RECVTHREAD 3 +#define IGUANA_HELPERTHREAD 4 +#define IGUANA_EXCHANGETHREAD 5 + +#define IGUANA_DEDICATED_THREADS +#ifdef IGUANA_DEDICATED_THREADS +#define IGUANA_MAXCONNTHREADS 128 +#define IGUANA_MAXSENDTHREADS (IGUANA_MAXPEERS>>2) +#define IGUANA_MAXRECVTHREADS (IGUANA_MAXPEERS>>2) +#else +#define IGUANA_MAXCONNTHREADS 16 +#define IGUANA_MAXSENDTHREADS 16 +#define IGUANA_MAXRECVTHREADS 16 +#endif + +#define IGUANA_SUBDIRDIVISOR 28000 +#define NTARGETSPACING 60 + +#define IGUANA_PROTOCOL_BITCOIN 'b' +#define IGUANA_PROTOCOL_NXT 'n' +#define IGUANA_PROTOCOL_ETHER 'e' +#define IGUANA_PROTOCOL_LISK 'l' +#define IGUANA_PROTOCOL_WAVES 'w' +#define IGUANA_PROTOCOL_IOTA 'i' + +#ifdef __PNACL +void PNACL_message(const char* format, ...); +#endif + +extern int32_t IGUANA_NUMHELPERS; + +#ifdef __PNACL +#define printf PNACL_message +#define MS_ASYNC 1 /* Sync memory asynchronously. */ +#define MS_SYNC 4 /* Synchronous memory sync. */ +#else +#define PNACL_message printf +#endif + +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0x4000 // Do not generate SIGPIPE +#endif + +#define BIP0031_VERSION 60000 +#define CADDR_TIME_VERSION 31402 +#define MIN_PROTO_VERSION 209 +#define MAX_BLOCK_SIZE 1000000 +#define COINBASE_MATURITY 100 + +#define _IGUANA_HDRSCOUNT 2000 +#define _IGUANA_BLOCKHASHES 500 +#define IGUANA_MAXBUNDLESIZE _IGUANA_HDRSCOUNT + +#define NODE_NETWORK (1 << 0) +#define NODE_GETUTXO (1 << 1) +#define NODE_BLOOM (1 << 2) + +#define PROTOCOL_VERSION 70002 +#define INIT_PROTO_VERSION 209 // initial proto version, to be increased after version/verack negotiation +#define GETHEADERS_VERSION 31800 // In this version, 'getheaders' was introduced. +#define MIN_PEER_PROTO_VERSION GETHEADERS_VERSION // disconnect from peers older than this proto version +// nTime field added to CAddress, starting with this version, if possible, avoid requesting addresses nodes older than this +#define CADDR_TIME_VERSION 31402 +// only request blocks from nodes outside this range of versions +#define NOBLKS_VERSION_START 32000 +#define NOBLKS_VERSION_END 32400 + +#define BIP0031_VERSION 60000 // BIP 0031, pong message, is enabled for all versions AFTER this one +#define MEMPOOL_GD_VERSION 60002 // "mempool" command, enhanced "getdata" behavior starts with this version +#define NO_BLOOM_VERSION 70011 // "filter*" disabled without NODE_BLOOM after and including this version +#define PROTOCOL_HEADERS_VERSION 70012 + +#define MSG_TX 1 +#define MSG_BLOCK 2 +#define MSG_FILTERED_BLOCK 3 +#define MSG_QUOTE 253 +#define MSG_BUNDLE 254 +#define MSG_BUNDLE_HEADERS 255 + +#define IGUANA_MAXLOCATORS 64 +#define IGUANA_MAXINV 50000 + +#define IGUANA_VOLATILE 1 +#define IGUANA_ITEMIND_DATA 2 +#define IGUANA_MAPPED_ITEM 4 +#define IGUANA_SHA256 0x80 +#define IGUANA_ALLOC_MULT 1.1 +#define IGUANA_ALLOC_INCR 1000 + +#define IGUANA_JSONTIMEOUT 10000 + +#define IGUANA_MAPRECVDATA 1 +#define IGUANA_MAPTXIDITEMS 2 +#define IGUANA_MAPPKITEMS 4 +#define IGUANA_MAPBLOCKITEMS 8 +#define IGUANA_MAPPEERITEMS 16 + +#define IGUANA_PEER_ELIGIBLE 1 +#define IGUANA_PEER_CONNECTING 2 +#define IGUANA_PEER_READY 3 +#define IGUANA_PEER_KILLED 4 + +#define IGUANA_NORMAL_TXVERSION 1 +#define IGUANA_LOCKTIME_TXVERSION 4 + +#define IGUANA_SEARCHBUNDLE 1 +#define IGUANA_SEARCHNOLAST (IGUANA_SEARCHBUNDLE | 2) +#define IGUANA_SEARCHPREV 4 +#define IGUANA_SEARCHNEXT 8 +#define IGUANA_SEARCHALL (IGUANA_SEARCHBUNDLE | IGUANA_SEARCHPREV | IGUANA_SEARCHNEXT) + +#define SUPERNET_MAXEXCHANGES 64 +#define SUPERNET_APIVERSION 0 + +#endif + diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h new file mode 100755 index 000000000..f778e50a0 --- /dev/null +++ b/includes/iguana_funcs.h @@ -0,0 +1,508 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef H_IGUANAFUNCS_H +#define H_IGUANAFUNCS_H +// peers +int32_t iguana_verifypeer(struct iguana_info *coin,void *key,void *value,int32_t itemind,int32_t itemsize); +int32_t iguana_peermetrics(struct supernet_info *myinfo,struct iguana_info *coin); +void iguana_peersloop(void *arg); +int32_t iguana_queue_send(struct iguana_peer *addr,int32_t delay,uint8_t *serialized,char *cmd,int32_t len); +uint32_t iguana_rwiAddrind(struct iguana_info *coin,int32_t rwflag,struct iguana_iAddr *iA,uint32_t ind); +void iguana_connections(void *arg); +uint32_t iguana_possible_peer(struct iguana_info *coin,char *ip_port); +//int32_t iguana_set_iAddrheight(struct iguana_info *coin,uint32_t ipbits,int32_t height); +//struct iguana_peer *iguana_choosepeer(struct iguana_info *coin); +void iguana_initpeer(struct iguana_info *coin,struct iguana_peer *addr,uint64_t ipbits); +void iguana_startconnection(void *arg); +void iguana_shutdownpeers(struct iguana_info *coin,int32_t forceflag); +void iguana_acceptloop(void *args); +void iguana_recvloop(void *args); +int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *serialized,int32_t len); +uint32_t iguana_updatemetrics(struct supernet_info *myinfo,struct iguana_info *coin); +void *iguana_peeralloc(struct iguana_info *coin,struct iguana_peer *addr,int32_t datalen); +int64_t iguana_peerfree(struct iguana_info *coin,struct iguana_peer *addr,void *ptr,int32_t datalen); +int64_t iguana_peerallocated(struct iguana_info *coin,struct iguana_peer *addr); + +// serdes +int32_t iguana_rwmem(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_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp); +int32_t iguana_rwblock(char *symbol,uint8_t zcash,uint8_t auxpow,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 maxlen); +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(uint8_t zcash,uint8_t auxpow,struct iguana_block *dest,struct iguana_msgblock *msg,bits256 hash2,int32_t height); +//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); + +// send message +int32_t iguana_validatehdr(char *symbol,struct iguana_msghdr *H); +int32_t iguana_sethdr(struct iguana_msghdr *H,const uint8_t netmagic[4],char *command,uint8_t *data,int32_t datalen); +int32_t iguana_send_version(struct iguana_info *coin,struct iguana_peer *addr,uint64_t myservices); +int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struct iguana_txblock *txblock,int32_t *lenp,uint8_t *data,int32_t datalen); +int32_t iguana_gethdrs(struct iguana_info *coin,uint8_t *serialized,char *cmd,char *hashstr); +int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,bits256 *hashes,int32_t n); +void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgblock *msg,struct iguana_block *src,int32_t cleartxn_count); +int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs); +int32_t iguana_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin); + +// ramchain +int64_t iguana_verifyaccount(struct iguana_info *coin,struct iguana_account *acct,uint32_t pkind); +int32_t iguana_initramchain(struct iguana_info *coin,int32_t initialheight,int32_t mapflags,int32_t fullverify); +void iguana_syncramchain(struct iguana_info *coin); +//int32_t iguana_validateramchain(struct iguana_info *coin,int64_t *netp,uint64_t *creditsp,uint64_t *debitsp,int32_t height,struct iguana_block *block,int32_t hwmheight,struct iguana_prevdep *lp); +int32_t iguana_calcrmd160(struct iguana_info *coin,char *asmstr,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence); +uint32_t iguana_updatescript(struct iguana_info *coin,uint32_t blocknum,uint32_t txidind,uint32_t spendind,uint32_t unspentind,uint64_t value,uint8_t *script,int32_t scriptlen,uint32_t sequence); +void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *txdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t datalen); +int32_t iguana_parseblock(struct iguana_info *coin,struct iguana_block *block,struct iguana_msgtx *tx,int32_t numtx); +uint32_t iguana_txidind(struct iguana_info *coin,uint32_t *firstvoutp,uint32_t *firstvinp,bits256 txid); +bits256 iguana_txidstr(struct iguana_info *coin,uint32_t *firstvoutp,uint32_t *firstvinp,char *txidstr,uint32_t txidind); +int32_t iguana_updateramchain(struct iguana_info *coin); +//void iguana_emittxarray(struct iguana_info *coin,FILE *fp,struct iguana_bundle *bundle,struct iguana_block *block,struct iguana_msgtx *txarray,int32_t numtx); + +// blockchain +int32_t iguana_needhdrs(struct iguana_info *coin); +struct iguana_chain *iguana_chainfind(char *name,cJSON *argjson,int32_t createflag); +int32_t iguana_chainextend(struct iguana_info *coin,struct iguana_block *newblock); +uint64_t iguana_miningreward(struct iguana_info *coin,uint32_t blocknum); + +// tx +int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin); +void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *txids,int32_t n); +void iguana_gotquotesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *quotes,int32_t n); +void iguana_gotunconfirmedM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msgtx *tx,uint8_t *data,int32_t datalen); +void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *blockhashes,int32_t n); + +// blocks +bits256 iguana_blockhash(struct iguana_info *coin,int32_t height); +#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_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,int32_t targetspacing,int32_t targettimespan); + +uint32_t iguana_syncs(struct iguana_info *coin); +void iguana_gotdata(struct iguana_info *coin,struct iguana_peer *addr,int32_t height); +//int64_t iguana_getbalance(struct iguana_info *coin,uint64_t *creditsp,uint64_t *debitsp,int32_t *nump,uint32_t *unspents,long max,struct iguana_pkhash *P,uint32_t pkind); +int32_t iguana_queueblock(struct iguana_info *coin,int32_t height,bits256 hash2,int32_t priority); +int32_t iguana_updatewaiting(struct iguana_info *coin,int32_t starti,int32_t max); + +// recvbits +int32_t iguana_recvinit(struct iguana_info *coin,int32_t initialheight); +int32_t ramcoder_decompress(uint8_t *data,int32_t maxlen,uint8_t *bits,uint32_t numbits,bits256 seed); +int32_t ramcoder_compress(uint8_t *bits,int32_t maxlen,uint8_t *data,int32_t datalen,bits256 seed); +uint64_t hconv_bitlen(uint64_t bitlen); +struct iguana_block *iguana_blockptr(char *debugstr,struct iguana_info *coin,int32_t height); +int32_t iguana_processrecv(struct supernet_info *myinfo,struct iguana_info *coin); // single threaded +//void iguana_recvalloc(struct iguana_info *coin,int32_t numitems); +void iguana_coins(void *arg); +int32_t iguana_savehdrs(struct iguana_info *coin); + +// hdrs +struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bundleip,int32_t bundleheight,bits256 bundlehash2,bits256 allhash,int32_t issueflag); +struct iguana_block *iguana_updatehdrs(struct iguana_info *coin,int32_t *newhwmp,struct iguana_block *block,bits256 prevhash2,bits256 hash2); +void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp); +void iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_zblock *zblocks,int32_t n); +void iguana_emittxdata(struct iguana_info *coin,struct iguana_bundle *bp); +int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr); +int32_t iguana_avail(struct iguana_info *coin,int32_t height,int32_t n); +int32_t iguana_updatebundles(struct iguana_info *coin); +void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag); +void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson); +void iguana_coinargs(char *symbol,int64_t *maxrecvcachep,int32_t *minconfirmsp,int32_t *maxpeersp,int32_t *initialheightp,uint64_t *servicesp,int32_t *maxrequestsp,int32_t *maxbundlesp,cJSON *json); +struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,int64_t maxrecvcache,uint64_t services,int32_t initialheight,int32_t maphash,int32_t minconfirms,int32_t maxrequests,int32_t maxbundles,cJSON *json); + +// init +struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialheight,int32_t mapflags); +void iguana_callcoinstart(struct iguana_info *coin); +void iguana_initcoin(struct iguana_info *coin,cJSON *argjson); +void iguana_coinloop(void *arg); + +// utils +double PoW_from_compact(uint32_t nBits,uint8_t unitval); +void calc_rmd160(char *hexstr,uint8_t buf[20],uint8_t *msg,int32_t len); +void calc_OP_HASH160(char *hexstr,uint8_t hash160[20],char *msg); +double dxblend(double *destp,double val,double decay); + +// json +int32_t iguana_processjsonQ(struct iguana_info *coin); // reentrant, can be called during any idletime +char *iguana_JSON(char *,uint16_t port); +char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen,int32_t compressed); + +char *mbstr(char *str,double); +int init_hexbytes_noT(char *hexbytes,unsigned char *message,long len); +int32_t decode_hex(unsigned char *bytes,int32_t n,char *hex); +char hexbyte(int32_t c); +char *clonestr(char *str); +long _stripwhite(char *buf,int accept); +int32_t myatoi(char *str,int32_t range); +int32_t safecopy(char *dest,char *src,long len); +void escape_code(char *escaped,char *str); +int32_t is_zeroes(char *str); +int64_t conv_floatstr(char *numstr); +int32_t has_backslash(char *str); + +struct iguana_thread *iguana_launch(struct iguana_info *coin,char *name,iguana_func funcp,void *arg,uint8_t type); +int32_t iguana_numthreads(struct iguana_info *coin,int32_t mask); +void iguana_terminator(void *arg); + +int32_t is_hexstr(char *str,int32_t n); +void iguana_initQ(queue_t *Q,char *name); +void iguana_emitQ(struct iguana_info *coin,struct iguana_bundle *bp); +void iguana_txdataQ(struct iguana_info *coin,struct iguana_peer *addr,FILE *fp,long fpos,int32_t datalen); +void iguana_helper(void *arg); + +struct iguana_helper { struct queueitem DL; void *coin,*addr,*bp,*nextbp,*fp; long fpos; int32_t allocsize,type,hdrsi,bundlei,datalen,timelimit; uint32_t starttime; }; +int32_t iguana_helpertask(FILE *fp,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_helper *ptr); +void iguana_flushQ(struct iguana_info *coin,struct iguana_peer *addr); +//struct iguana_txdatabits iguana_peerfilePT(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2,struct iguana_txdatabits txdatabits,int32_t recvlen); +struct iguana_txdatabits iguana_calctxidbits(uint32_t addrind,uint32_t filecount,uint32_t fpos,uint32_t datalen); +int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,uint32_t starttime); // helper thread +int32_t iguana_bundlemergeHT(char *fname,struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,struct iguana_bundle *nextbp,uint32_t starttime); // helper thread + +void iguana_peerfilename(struct iguana_info *coin,char *fname,uint32_t addrind,uint32_t filecount); + +struct iguana_txblock *iguana_ramchainptrs(struct iguana_txid **Tptrp,struct iguana_unspent20 **Uptrp,struct iguana_spend256 **Sptrp,struct iguana_pkhash **Pptrp,bits256 **externalTptrp,struct OS_memspace *mem,struct iguana_txblock *origtxdata); + +int32_t iguana_ramchainsave(struct iguana_info *coin,struct iguana_ramchain *ramchain); +int32_t iguana_ramchainfree(struct iguana_info *coin,struct OS_memspace *mem,struct iguana_ramchain *ramchain); +struct iguana_ramchain *iguana_ramchainmergeHT(struct iguana_info *coin,struct OS_memspace *mem,struct iguana_ramchain *ramchains[],int32_t n,struct iguana_bundle *bp); +void iguana_ramchainmerge(struct iguana_info *coin); + +int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t priority); +void iguana_blockcopy(uint8_t zcash,uint8_t auxpow,struct iguana_info *coin,struct iguana_block *block,struct iguana_block *origblock); +int32_t iguana_rpctest(struct iguana_info *coin); +extern queue_t helperQ; +extern const char *Hardcoded_coins[][3]; +void iguana_main(void *arg); + +int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,char *fname,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t numblocks,int32_t dispflag); +struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundleip,char *fname,struct OS_memspace *mem,uint32_t ipbits,bits256 hash2); +int32_t iguana_peerfile_exists(struct iguana_info *coin,struct iguana_peer *addr,char *dirname,char *fname,bits256 hash2,bits256 prevhash2,int32_t numblocks); +struct iguana_ramchain *iguana_ramchainset(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_txblock *txdata); +void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA); +long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,int32_t txn_count,uint8_t *data,int32_t recvlen); +int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blockp,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2); +struct iguana_block *iguana_bundleblockadd(struct iguana_info *coin,struct iguana_bundle **bpp,int32_t *bundleip,struct iguana_block *origblock); +int32_t iguana_chainextend(struct iguana_info *coin,struct iguana_block *newblock); +int32_t iguana_blockvalidate(struct iguana_info *coin,int32_t *validp,struct iguana_block *block,int32_t dispflag); +char *iguana_bundledisp(struct iguana_info *coin,struct iguana_bundle *prevbp,struct iguana_bundle *bp,struct iguana_bundle *nextbp,int32_t m); +struct iguana_bundle *iguana_bundlefind(struct iguana_info *coin,struct iguana_bundle **bpp,int32_t *bundleip,bits256 hash2); +//int32_t iguana_chainheight(struct iguana_info *coin,struct iguana_block *origblock); +bits256 *iguana_blockhashptr(struct iguana_info *coin,int32_t height); +int32_t iguana_hash2set(struct iguana_info *coin,char *debugstr,struct iguana_bundle *bp,int32_t bundlei,bits256 newhash2); +struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_block *newblock); +int32_t iguana_hashfree(struct iguana_kvitem *hashtable,int32_t freeitem); +int32_t iguana_processbundlesQ(struct iguana_info *coin,int32_t *newhwmp); // single threaded +int32_t iguana_ramchainverifyPT(struct iguana_info *coin,struct iguana_ramchain *ramchain); +void *map_file(char *fname,long *filesizep,int32_t enablewrite); +void iguana_rpcloop(void *args); +int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port); +void iguana_mergeQ(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_bundle *nextbp); + +#define bits256_nonz(a) (((a).ulongs[0] | (a).ulongs[1] | (a).ulongs[2] | (a).ulongs[3]) != 0) +//int32_t btc_addr2univ(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr); + +struct iguana_agent +{ + char name[32],hostname[64]; void *methods; uint16_t port; int32_t sock,nummethods; + bits256 pubkey,privkey; + char *(*parsefunc)(struct iguana_agent *agent,char *method,void *json,char *remoteaddr); +}; + +int32_t iguana_txbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts); +int32_t iguana_vinset(struct iguana_info *coin,uint8_t *scriptspace,int32_t height,struct iguana_msgvin *vin,struct iguana_txid *tx,int32_t i); +int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmstr,int32_t height,struct iguana_msgvout *vout,struct iguana_txid *tx,int32_t i); +//int32_t btc_convrmd160(char *coinaddr,uint8_t addrtype,uint8_t rmd160[20]); +struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_txid *tx,int32_t txidind); +int32_t iguana_txidreq(struct iguana_info *coin,char **retstrp,bits256 txid); +void iguana_bundleiclear(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei); +int32_t hcalc_bitsize(uint64_t x); +struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,struct iguana_txid *tx,bits256 txid,int32_t lasthdrsi); +int32_t iguana_scriptgen(struct iguana_info *coin,int32_t *Mp,int32_t *nump,char *coinaddr,uint8_t *script,char *asmstr,uint8_t rmd160[20],uint8_t type,const struct vin_info *vp,int32_t txi); +int32_t iguana_ramchain_spendtxid(struct iguana_info *coin,uint32_t *unspentindp,bits256 *txidp,struct iguana_txid *T,int32_t numtxids,bits256 *X,int32_t numexternaltxids,struct iguana_spend *s); +void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr); +struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int32_t forceflag); +void iguana_dedicatedglue(void *arg); +void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag); +void SuperNET_yourip(struct supernet_info *myinfo,char *yourip); +void iguana_peerkill(struct iguana_info *coin); +int32_t blockhash_sha256(uint8_t *blockhashp,uint8_t *serialized,int32_t len); +void iguana_nameset(char name[64],char *symbol,cJSON *json); + +char *busdata_sync(uint32_t *noncep,char *jsonstr,char *broadcastmode,char *destNXTaddr); +void peggy(); +int32_t opreturns_init(uint32_t blocknum,uint32_t blocktimestamp,char *path); +struct iguana_info *iguana_coinfind(char *symbol); +struct iguana_info *iguana_coinadd(char *symbol,char *nane,cJSON *json); +struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int32_t extraflag); +int32_t iguana_sendblockreq(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe); +int32_t iguana_send_supernet(struct iguana_peer *addr,char *jsonstr,int32_t delay); + +struct iguana_waccount *iguana_waccountfind(struct supernet_info *myinfo,struct iguana_info *coin,char *account); +struct iguana_waddress *iguana_waccountadd(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount **wacctp,char *walletaccount,char *coinaddr); +struct iguana_waddress *iguana_waccountswitch(struct supernet_info *myinfo,struct iguana_info *coin,char *account,char *coinaddr,char *redeemScript); +struct iguana_waddress *iguana_waddresscalc(struct supernet_info *myinfo,uint8_t pubval,uint8_t wiftype,struct iguana_waddress *addr,bits256 privkey); +struct iguana_waddress *iguana_waddressfind(struct supernet_info *myinfo,struct iguana_waccount *wacct,char *coinaddr); +char *iguana_coinjson(struct iguana_info *coin,char *method,cJSON *json); +cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly); +//int32_t btc_priv2wif(char *wifstr,uint8_t privkey[32],uint8_t addrtype); +//int32_t btc_pub2rmd(uint8_t rmd160[20],uint8_t pubkey[33]); +int32_t iguana_launchcoin(struct supernet_info *myinfo,char *symbol,cJSON *json); +int32_t iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1); +int32_t iguana_jsonQ(); +int32_t is_bitcoinrpc(struct supernet_info *myinfo,char *method,char *remoteaddr); +char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr,uint16_t port); +cJSON *iguana_pubkeyjson(struct iguana_info *coin,char *pubkeystr); +void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit); +int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,int32_t timelimit,int32_t lag); +void ramcoder_test(void *data,int64_t len); +void iguana_exit(); +int32_t iguana_pendingaccept(struct iguana_info *coin); +char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t tag,int32_t maxmillis,char *remoteaddr,uint16_t port); +void iguana_iAkill(struct iguana_info *coin,struct iguana_peer *addr,int32_t markflag); +cJSON *SuperNET_bits2json(uint8_t *serialized,int32_t datalen); +int32_t SuperNET_sendmsg(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,bits256 destpub,bits256 mypriv,bits256 mypub,uint8_t *msg,int32_t len,uint8_t *data,int32_t delaymillis); +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_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype); +bits256 iguana_chaingenesis(char *symbol,uint8_t zcash,uint8_t auxpow,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); +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_rawtxbytes(struct iguana_info *coin,cJSON *json,struct iguana_msgtx *msgtx); +int32_t iguana_send_VPNversion(struct iguana_info *coin,struct iguana_peer *addr,uint64_t myservices); +void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sleepflag); +int32_t iguana_rwvout(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvout *msg); +int32_t iguana_rwvin(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvin *msg); +int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins); +int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts,int32_t validatesigs); +cJSON *bitcoin_txtest(struct iguana_info *coin,char *rawtxstr,bits256 txid); +cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag); +int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct iguana_msgblock *msg); +//int32_t iguana_sig(uint8_t *sig,int32_t maxsize,uint8_t *data,int32_t datalen,bits256 privkey); +//int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,bits256 pubkey); +//int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,uint8_t *pubkey); +void calc_rmd160_sha256(uint8_t rmd160[20],uint8_t *data,int32_t datalen); +int32_t bitcoin_checklocktimeverify(uint8_t *script,int32_t n,uint32_t locktime); +struct bitcoin_spend *iguana_spendset(struct supernet_info *myinfo,struct iguana_info *coin,int64_t amount,int64_t txfee,cJSON *addresses,int32_t minconf); +cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes,uint8_t *extrapace,int32_t extralen,uint8_t *serialized); +cJSON *iguana_signtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,char **signedtxp,struct bitcoin_spend *spend,cJSON *txobj,cJSON *vins); +void iguana_addscript(struct iguana_info *coin,cJSON *dest,uint8_t *script,int32_t scriptlen,char *fieldname); +bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain); + +cJSON *bitcoin_txcreate(int32_t isPoS,int64_t locktime,uint32_t txversion); +cJSON *bitcoin_txoutput(cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t satoshis); +cJSON *bitcoin_txinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys); + +int32_t bitcoin_changescript(struct iguana_info *coin,uint8_t *changescript,int32_t n,uint64_t *changep,char *changeaddr,uint64_t inputsatoshis,uint64_t satoshis,uint64_t txfee); +//cJSON *bitcoin_addinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys); +int32_t bitcoin_verifytx(struct iguana_info *coin,bits256 *signedtxidp,char **signedtx,char *rawtxstr,struct vin_info *V,int32_t numinputs); +int32_t bitcoin_verify(void *ctx,uint8_t *sig,int32_t siglen,bits256 txhash2,uint8_t *pubkey,int32_t plen); +char *bitcoin_json2hex(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,cJSON *txjson,struct vin_info *V); +int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr); +char *issue_startForging(struct supernet_info *myinfo,char *secret); +struct bitcoin_unspent *iguana_unspentsget(struct supernet_info *myinfo,struct iguana_info *coin,char **retstrp,double *balancep,int32_t *numunspentsp,double minconfirms,char *address); +void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson); +int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,int64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp,int32_t maxunspents); +long iguana_spentsfile(struct iguana_info *coin,int32_t n); +uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp,cJSON *array,int32_t firsti); +int64_t iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp); +uint8_t *iguana_walletrmds(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp); +char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi); +uint32_t iguana_sparseaddpk(uint8_t *bits,int32_t width,uint32_t tablesize,uint8_t rmd160[20],struct iguana_pkhash *P,uint32_t pkind,struct iguana_ramchain *ramchain); +int32_t iguana_vinscriptparse(struct iguana_info *coin,struct vin_info *vp,uint32_t *sigsizep,uint32_t *pubkeysizep,uint32_t *p2shsizep,uint32_t *suffixp,uint8_t *vinscript,int32_t scriptlen); +void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len); +int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp); +int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain,int32_t starti,int32_t numblocks,int32_t convertflag,int32_t iterate); +int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t startheight,int32_t endheight,int32_t startemit); +int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag); +void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp); +struct iguana_bloominds iguana_calcbloom(bits256 hash2); +int32_t iguana_bloomfind(struct iguana_info *coin,struct iguana_bloom16 *bloom,int32_t incr,struct iguana_bloominds bit); +struct iguana_bloominds iguana_bloomset(struct iguana_info *coin,struct iguana_bloom16 *bloom,int32_t incr,struct iguana_bloominds bit); +int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp); +//void iguana_balancesQ(struct iguana_info *coin,struct iguana_bundle *bp); +int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi); +int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int32_t starti,int32_t max); +int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight); +int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe); +int32_t iguana_blockreq(struct iguana_info *coin,int32_t height,int32_t priority); +int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t lag); +int32_t iguana_ramchain_prefetch(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t txonly); +int32_t iguana_realtime_update(struct iguana_info *coin); +int32_t iguana_volatilesmap(struct iguana_info *coin,struct iguana_ramchain *ramchain); +void iguana_volatilespurge(struct iguana_info *coin,struct iguana_ramchain *ramchain); +int32_t iguana_volatilesinit(struct iguana_info *coin); +void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle); +int64_t iguana_ramchainopen(char *fname,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,int32_t bundleheight,bits256 hash2); +int32_t iguana_ramchain_free(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t deleteflag); +void iguana_blocksetcounters(struct iguana_info *coin,struct iguana_block *block,struct iguana_ramchain * ramchain); +int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int16_t bundlei); +void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,struct iguana_bundle *bp,int32_t bundlei); +int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_ramchain *mapchain,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block,void *ptr,long filesize); +void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp); +void iguana_RTramchainfree(struct iguana_info *coin,struct iguana_bundle *bp); +void iguana_coinpurge(struct iguana_info *coin); +int32_t iguana_setmaxbundles(struct iguana_info *coin); +void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp); +uint32_t iguana_sparseaddtx(uint8_t *bits,int32_t width,uint32_t tablesize,bits256 txid,struct iguana_txid *T,uint32_t txidind,struct iguana_ramchain *ramchain); +void iguana_launchpeer(struct iguana_info *coin,char *ipaddr); +//void iguana_spendvectorsQ(struct iguana_info *coin,struct iguana_bundle *bp); +int8_t iguana_blockstatus(struct iguana_info *coin,struct iguana_block *block); +int32_t iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,int32_t slotid,uint64_t ipbits); +void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,struct iguana_bundle *bp,int32_t i,int32_t deletefile); +int32_t iguana_reqblocks(struct iguana_info *coin); +void iguana_walletlock(struct supernet_info *myinfo,struct iguana_info *coin); +int32_t _SuperNET_encryptjson(char *destfname,char *passphrase,int32_t passsize,char *fname2fa,int32_t fnamesize,cJSON *argjson); +int32_t bitcoin_pubkeylen(const uint8_t *pubkey); +struct iguana_block *iguana_bundleblock(struct iguana_info *coin,bits256 *hash2p,struct iguana_bundle *bp,int32_t i); +void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *R,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block); +int32_t iguana_bundlehashadd(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block); +int32_t iguana_convert(struct iguana_info *coin,int32_t helperid,struct iguana_bundle *bp,int32_t RTflag,int32_t starti); +int32_t iguana_bundleissuemissing(struct iguana_info *coin,struct iguana_bundle *bp,int32_t priority,double mult); +FILE *myfopen(char *fname,char *mode); +int32_t myfclose(FILE *fp); +int32_t iguana_walkchain(struct iguana_info *coin,int32_t skipflag); +struct iguana_block *iguana_fastlink(struct iguana_info *coin,int32_t hwmheight); +int32_t iguana_balancenormal(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight); +int32_t iguana_spendvectorsaves(struct iguana_info *coin); +int32_t iguana_convertfinished(struct iguana_info *coin); +int32_t iguana_emitfinished(struct iguana_info *coin,int32_t queueincomplete); +int32_t iguana_utxofinished(struct iguana_info *coin); +int32_t iguana_balancefinished(struct iguana_info *coin); +int32_t iguana_alloctxbits(struct iguana_info *coin,struct iguana_ramchain *ramchain); +void iguana_allocvolatile(struct iguana_info *coin,struct iguana_ramchain *ramchain); +int32_t iguana_rwaddr(int32_t rwflag,uint8_t *serialized,struct iguana_msgaddress *addr,int32_t protover); +struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_block **blockp,int32_t *bundleip,struct iguana_block *origblock); +struct iguana_waddress *iguana_waddresscreate(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,char *coinaddr,char *redeemScript); + +int32_t iguana_peerhdrrequest(struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_peer *addr,bits256 hash2); +int32_t iguana_peeraddrrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max); +int32_t iguana_peerdatarequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max); +int32_t iguana_peergetrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *data,int32_t recvlen,int32_t getblock); +int32_t iguana_bundlefname(struct iguana_info *coin,struct iguana_bundle *bp,char *fname); +int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfiles); +int32_t iguana_voutsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid); +int32_t iguana_vinsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid); +bits256 iguana_merkle(bits256 *tree,int32_t txn_count); +int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag); +int32_t iguana_blast(struct iguana_info *coin,struct iguana_peer *addr); +int32_t iguana_validated(struct iguana_info *coin); +void iguana_volatilesalloc(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t copyflag); +int32_t iguana_send_ping(struct iguana_info *coin,struct iguana_peer *addr); +int32_t iguana_process_msgrequestQ(struct supernet_info *myinfo,struct iguana_info *coin); +uint32_t iguana_fastfindinit(struct iguana_info *coin); +int32_t iguana_unspentindfind(struct iguana_info *coin,char *coinaddr,uint8_t *spendscript,int32_t *scriptlenp,uint64_t *valuep,int32_t *heightp,bits256 txid,int32_t vout,int32_t lasthdrsi); +int32_t iguana_addressvalidate(struct iguana_info *coin,uint8_t *addrtypep,char *address); +int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256 privkey,int32_t recoverflag); +bits256 iguana_str2priv(struct supernet_info *myinfo,struct iguana_info *coin,char *str); +int32_t iguana_spentflag(struct iguana_info *coin,int64_t *RTspendp,int32_t *spentheightp,struct iguana_ramchain *ramchain,int16_t spent_hdrsi,uint32_t spent_unspentind,int32_t height,int32_t minconf,int32_t maxconf,uint64_t amount); +int32_t iguana_voutscript(struct iguana_info *coin,struct iguana_bundle *bp,uint8_t *scriptspace,char *asmstr,struct iguana_unspent *u,struct iguana_pkhash *p,int32_t txi); +cJSON *iguana_unspentjson(struct supernet_info *myinfo,struct iguana_info *coin,int32_t hdrsi,uint32_t unspentind,struct iguana_txid *T,struct iguana_unspent *up,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33); +int32_t bitcoin_standardspend(uint8_t *script,int32_t n,uint8_t rmd160[20]); +struct iguana_waddress *iguana_waddresssearch(struct supernet_info *myinfo,struct iguana_waccount **wacctp,char *coinaddr); +int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,cJSON *txids,cJSON *vouts,char *coinaddr,int32_t minconf); +cJSON *iguana_walletjson(struct supernet_info *myinfo); +int32_t iguana_payloadupdate(struct supernet_info *myinfo,struct iguana_info *coin,char *retstr,struct iguana_waddress *waddr,char *account); +int32_t bitcoin_MofNspendscript(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,const struct vin_info *vp); +cJSON *iguana_p2shjson(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *retjson,struct iguana_waddress *waddr); +char *setaccount(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waddress **waddrp,char *account,char *coinaddr,char *redeemScript); +char *iguana_APIrequest(struct iguana_info *coin,bits256 blockhash,bits256 txid,int32_t seconds); +int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxsize,struct vin_info *V,int32_t sighash); +int64_t iguana_fastfindcreate(struct iguana_info *coin); +int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr); +int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struct iguana_ramchain *spentchain,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight); +int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight); +int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,int64_t *unspents,int32_t max,int64_t required,int32_t minconf,cJSON *addresses); +int64_t iguana_unspentset(struct supernet_info *myinfo,struct iguana_info *coin); +int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 txid,int32_t lasthdrsi); +uint8_t iguana_addrtype(struct iguana_info *coin,uint8_t script_type); +struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,struct iguana_waddress *addwaddr,char *redeemScript); +cJSON *iguana_createvins(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *txobj,cJSON *vins); +bits256 bitcoin_pubkey33(void *ctx,uint8_t *data,bits256 privkey); +bits256 bitcoin_randkey(void *ctx); +int32_t bitcoin_recoververify(void *ctx,char *symbol,uint8_t *sig64,bits256 messagehash2,uint8_t *pubkey); +int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t script[IGUANA_MAXSCRIPTSIZE],cJSON *scriptobj,int32_t interpret,int64_t nLockTime,struct vin_info *V); +cJSON *iguana_spendasm(struct iguana_info *coin,uint8_t *spendscript,int32_t spendlen); +int64_t iguana_unspentavail(struct iguana_info *coin,uint64_t hdrsi_unspendind,int32_t minconf,int32_t maxconf); +struct iguana_utxo iguana_utxofind(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t spent_unspentind,int32_t *RTspendflagp,int32_t lockflag); +int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeys); +cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins); +char *iguana_inputaddress(struct iguana_info *coin,char *coinaddr,int16_t *spent_hdrsip,uint32_t *unspentindp,cJSON *vinobj); +struct iguana_waddress *iguana_getaccountaddress(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,char *coinaddr,char *account); +int32_t iguana_uvaltxid(struct supernet_info *myinfo,bits256 *txidp,struct iguana_info *coin,int16_t hdrsi,uint32_t unspentind); +struct instantdex_accept *instantdex_quotefind(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,bits256 encodedhash); +int32_t instantdex_quoterequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,struct iguana_peer *addr,bits256 encodedhash); +int32_t instantdex_peerhas_clear(struct iguana_info *coin,struct iguana_peer *addr); +int32_t instantdex_quotep2p(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,uint8_t *serialized,int32_t recvlen); +void instantdex_update(struct supernet_info *myinfo); +cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *account); +int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLockTime,struct vin_info *V,int32_t numvins); +int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_msgvin *vin,cJSON *vinobj,struct vin_info *V); +//int64_t iguana_availunspents(struct supernet_info *myinfo,uint64_t **unspentsp,int32_t *nump,struct iguana_info *coin,int32_t minconf,char *account,void *ptr,int32_t maxsize); +char *iguana_signunspents(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *txobj,uint64_t satoshis,char *changeaddr,uint64_t txfee,uint64_t *unspents,int32_t num); +bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx); +int32_t iguana_inv2packet(uint8_t *serialized,int32_t maxsize,int32_t type,bits256 *hashes,int32_t n); +int32_t instantdex_inv2data(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct exchange_info *exchange); +struct iguana_bundlereq *instantdex_recvquotes(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *encodedhash,int32_t n); +struct exchange_info *exchange_create(char *exchangestr,cJSON *argjson); +int32_t iguana_inv2poll(struct supernet_info *myinfo,struct iguana_info *coin); +struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,uint8_t *data,int32_t datalen); +void instantdex_FSMinit(); +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_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkey); +bits256 scrypt_blockhash(const void *input); +bits256 iguana_calcblockhash(char *symbol,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),uint8_t *serialized,int32_t len); +struct bitcoin_eventitem *instantdex_event(char *cmdstr,cJSON *argjson,cJSON *newjson,uint8_t *serdata,int32_t serdatalen); +void instantdex_eventfree(struct bitcoin_eventitem *ptr); +struct iguana_monitorinfo *iguana_txidmonitor(struct iguana_info *coin,bits256 txid); +struct iguana_monitorinfo *iguana_txidreport(struct iguana_info *coin,bits256 txid,struct iguana_peer *addr); +double iguana_txidstatus(struct iguana_info *coin,bits256 txid); +void basilisk_functions(struct iguana_info *coin,int32_t protocol); +char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *method,char *params); +char *bitcoin_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,int64_t satoshis,char *paymentscriptstr,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf,uint32_t locktime); +char *bitcoin_blockhashstr(char *coinstr,char *serverport,char *userpass,int32_t height); +bits256 basilisk_blockhash(struct iguana_info *coin,bits256 prevhash2); +void calc_scrypthash(uint32_t *hash,void *data); +int32_t iguana_rwvarstr(int32_t rwflag,uint8_t *serialized,int32_t maxlen,char *endianedp); +bits256 bitcoin_sharedsecret(void *ctx,bits256 privkey,uint8_t *pubkey,int32_t plen); +int32_t iguana_blockhdrsize(char *symbol,uint8_t zcash,uint8_t auxpow);//,uint8_t *serialized,int32_t maxlen); +int32_t iguana_blockROsize(uint8_t zcash); +void *iguana_blockzcopyRO(uint8_t zcash,struct iguana_blockRO *dest,int32_t desti,struct iguana_blockRO *src,int32_t srci); +void iguana_blockzcopy(uint8_t zcash,struct iguana_block *dest,struct iguana_block *src); +int32_t iguana_blocksizecheck(char *debugstr,uint8_t zcash,struct iguana_block *block); +void basilisk_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis,char *mineraddr); +int32_t bitcoin_pubkeyspend(uint8_t *script,int32_t n,uint8_t pubkey[66]); +int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *virt,char *blockstr); +struct supernet_info *SuperNET_MYINFO(char *passphrase); +bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory); +struct gecko_chain *category_find(bits256 categoryhash,bits256 subhash); +void *category_subscribe(struct supernet_info *myinfo,bits256 category,bits256 keyhash); +char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); +char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr,uint16_t port); +struct supernet_info *SuperNET_accountfind(cJSON *json); +cJSON *SuperNET_rosettajson(bits256 privkey,int32_t showprivs); +double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *sortbuf,int32_t max,double *totalvolp,char *base,char *rel,double basevolume,cJSON *argjson); +char *SuperNET_keysinit(struct supernet_info *myinfo,char *argjsonstr); +char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,cJSON *json,char *remoteaddr); +char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr); +void SuperNET_setkeys(struct supernet_info *myinfo,void *pass,int32_t passlen,int32_t dosha256); + +#include "../includes/iguana_api.h" + + +#endif + diff --git a/includes/iguana_globals.h b/includes/iguana_globals.h new file mode 100755 index 000000000..a0abbfc25 --- /dev/null +++ b/includes/iguana_globals.h @@ -0,0 +1,79 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef H_IGUANAGLOBALS_H +#define H_IGUANAGLOBALS_H + +#ifdef ACTIVELY_DECLARE +#define CONDEXTERN +int32_t PANGEA_MAXTHREADS = 1,MAX_DEPTH = 100; +char *Iguana_validcommands[] = +{ + "inv2", "getdata2", "ConnectTo", + "version", "verack", "getaddr", "addr", "inv", "getdata", "notfound", "getblocks", "getheaders", "headers", "tx", "block", "mempool", "ping", "pong", + "reject", "filterload", "filteradd", "filterclear", "merkleblock", "alert", "" +}; + +#ifdef __PNACL__ +char GLOBAL_TMPDIR[512] = "/DB/tmp"; +char GLOBAL_DBDIR[512] = "/DB"; +char GLOBAL_GENESISDIR[512] = "/genesis"; +char GLOBAL_HELPDIR[512] = "/DB/help"; +char GLOBAL_VALIDATEDIR[512] = "/DB/purgeable"; +char GLOBAL_CONFSDIR[512] = "/DB/confs"; +int32_t IGUANA_NUMHELPERS = 1; +#else +char GLOBAL_TMPDIR[512] = "tmp"; +char GLOBAL_HELPDIR[512] = "help"; +char GLOBAL_DBDIR[512] = "DB"; +char GLOBAL_GENESISDIR[512] = "genesis"; +char GLOBAL_VALIDATEDIR[512] = "DB/purgeable"; +char GLOBAL_CONFSDIR[512] = "confs"; +#ifdef __linux +int32_t IGUANA_NUMHELPERS = 8; +#else +int32_t IGUANA_NUMHELPERS = 4; +#endif +#endif + +#else +#define CONDEXTERN extern +#endif + +// ALL globals must be here! +CONDEXTERN char *Iguana_validcommands[]; +CONDEXTERN int32_t Showmode,Autofold,PANGEA_MAXTHREADS; + +CONDEXTERN struct gecko_chain *Categories; +CONDEXTERN struct iguana_info *Allcoins; +CONDEXTERN char Userhome[512]; +CONDEXTERN int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel,IGUANA_BIGENDIAN; +CONDEXTERN uint32_t prices777_NXTBLOCK; +CONDEXTERN queue_t helperQ,jsonQ,finishedQ,bundlesQ,emitQ; +CONDEXTERN struct supernet_info MYINFO,**MYINFOS; +CONDEXTERN int32_t MAIN_initflag,MAX_DEPTH; +CONDEXTERN int32_t HDRnet,netBLOCKS; +CONDEXTERN cJSON *API_json; + +CONDEXTERN char GLOBAL_TMPDIR[512]; +CONDEXTERN char GLOBAL_DBDIR[512]; +CONDEXTERN char GLOBAL_GENESISDIR[512]; +CONDEXTERN char GLOBAL_HELPDIR[512]; +CONDEXTERN char GLOBAL_VALIDATEDIR[512]; +CONDEXTERN char GLOBAL_CONFSDIR[512]; +CONDEXTERN int32_t IGUANA_NUMHELPERS; + +#endif + diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h new file mode 100755 index 000000000..e364372b1 --- /dev/null +++ b/includes/iguana_structs.h @@ -0,0 +1,474 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef H_IGUANASTRUCTS_H +#define H_IGUANASTRUCTS_H + + +struct iguana_thread +{ + struct queueitem DL; + pthread_t handle; + struct iguana_info *coin; + char name[16]; + uint8_t type; + iguana_func funcp; + void *arg; +}; + +struct iguana_blockreq { struct queueitem DL; bits256 hash2,*blockhashes; struct iguana_bundle *bp; int32_t n,height,bundlei; }; + +struct iguana_peermsgrequest { struct queueitem DL; struct iguana_peer *addr; bits256 hash2; int32_t type; }; + +struct iguana_chain +{ + //const int32_t chain_id; + char name[32],symbol[8],messagemagic[64]; + uint8_t pubtype,p2shtype,wiftype,netmagic[4]; + char *genesis_hash,*genesis_hex; // hex string + uint16_t portp2p,rpcport; + uint8_t isPoS,unitval; + uint64_t rewards[512][2]; + uint8_t genesis_hashdata[32],minconfirms; + uint16_t bundlesize,hasheaders; + char gethdrsmsg[16]; + uint64_t txfee,minoutput,dust; + blockhashfunc hashalgo; + char userhome[512],serverport[128],userpass[1024]; + char use_addmultisig,do_opreturn; + int32_t estblocktime,protover; + bits256 genesishash2,PoWtarget,PoStargets[16]; int32_t numPoStargets,PoSheights[16]; + uint8_t zcash,auxpow,alertpubkey[65]; + uint16_t targetspacing,targettimespan; uint32_t nBits,normal_txversion,locktime_txversion; +}; + +struct iguana_msgaddress { uint32_t nTime; uint64_t nServices; uint8_t ip[16]; uint16_t port; } __attribute__((packed)); + +struct iguana_msgversion +{ + uint32_t nVersion; + uint64_t nServices; + int64_t nTime; + struct iguana_msgaddress addrTo,addrFrom; + uint64_t nonce; + char strSubVer[80]; + uint32_t nStartingHeight; + uint8_t relayflag; +} __attribute__((packed)); + +struct iguana_msgalert // warning, many varints/variable length fields, struct is 1:1 +{ + int32_t version; + int64_t relayuntil,expiration; + int32_t ID,cancel; + uint32_t numcancellist; + int32_t minver,maxver; + uint32_t setsubvervar; char subver[1024]; + int32_t priority; + char comment[1024],statusbar[1024],reserved[1024]; + uint8_t siglen,sig[74]; + uint32_t list[64]; +}; + +struct iguana_VPNversion +{ + uint32_t nVersion; + uint64_t nServices; + int64_t nTime; + struct iguana_msgaddress addrTo,addrFrom; + uint64_t nonce; + char strSubVer[80]; + uint32_t nStartingHeight; + uint32_t iVer,v_Network_id; uint16_t wPort; uint8_t bIsGui; uint16_t wCtPort,wPrPort; +} __attribute__((packed)); + +struct iguana_msgblockhdr +{ + uint32_t version; + bits256 prev_block,merkle_root; + uint32_t timestamp,bits,nonce; +} __attribute__((packed)); + +#define ZKSNARK_PROOF_SIZE 584 +#define ZCASH_SOLUTION_ELEMENTS 32 + +struct iguana_msgblockhdr_zcash +{ + bits256 bignonce; + uint8_t numelements; + uint32_t solution[ZCASH_SOLUTION_ELEMENTS]; + //bits256 reserved; // only here if auxpow is set +} __attribute__((packed)); + +struct iguana_msgmerkle +{ + uint32_t branch_length; + bits256 branch_hash[4096]; + uint32_t branch_side_mask; +} __attribute__((packed)); + +struct iguana_msgblock +{ + struct iguana_msgblockhdr H; // double hashed for blockhash + struct iguana_msgblockhdr_zcash zH; + uint32_t txn_count; +} __attribute__((packed)); + +struct iguana_msgvin { bits256 prev_hash; uint8_t *vinscript,*spendscript,*redeemscript; uint32_t prev_vout,sequence; uint16_t scriptlen,p2shlen,suffixlen,spendlen; } __attribute__((packed)); + +struct iguana_msgvout { uint64_t value; uint32_t pk_scriptlen; uint8_t *pk_script; } __attribute__((packed)); + +struct iguana_msgtx +{ + uint32_t version,tx_in,tx_out,lock_time; + struct iguana_msgvin *vins; + struct iguana_msgvout *vouts; + bits256 txid; + int32_t allocsize,timestamp; +} __attribute__((packed)); + +struct iguana_msgjoinsplit +{ + uint64_t vpub_old,vpub_new; + bits256 anchor,nullifiers[2],commitments[2],ephemeralkey; + uint8_t ciphertexts[2][217]; + bits256 randomseed,vmacs[2]; + uint8_t zkproof[ZKSNARK_PROOF_SIZE-1]; +} __attribute__((packed)); + +struct iguana_packet { struct queueitem DL; struct iguana_peer *addr; struct tai embargo; int32_t datalen,getdatablock; uint8_t serialized[]; }; + +struct msgcounts { uint32_t version,verack,getaddr,addr,inv,getdata,notfound,getblocks,getheaders,headers,tx,block,mempool,ping,pong,reject,filterload,filteradd,filterclear,merkleblock,alert; }; + +struct iguana_fileitem { bits256 hash2; struct iguana_txdatabits txdatabits; }; + +struct iguana_kvitem { UT_hash_handle hh; uint8_t keyvalue[]; };// __attribute__((packed)); + +struct iguana_iAddr +{ + UT_hash_handle hh; uint64_t ipbits; + uint32_t lastkilled,lastconnect; + int32_t status,height,numkilled,numconnects; +}; + +struct iguana_cacheptr { struct queueitem DL; int32_t allocsize,recvlen; uint8_t *data; }; + +// iguana blocks +struct iguana_blockRO +{ + bits256 hash2,prev_block,merkle_root; + uint32_t timestamp,nonce,bits,version; + uint32_t firsttxidind,firstvin,firstvout,firstpkind,firstexternalind,recvlen:24,tbd:8; + uint16_t txn_count,numvouts,numvins,allocsize; +} __attribute__((packed)); + +struct iguana_zcashRO { bits256 bignonce; uint32_t solution[ZCASH_SOLUTION_ELEMENTS]; } __attribute__((packed)); + +struct iguana_zblockRO +{ + struct iguana_blockRO RO; + struct iguana_zcashRO zRO; +} __attribute__((packed)); + +#define iguana_blockfields double PoW; \ +int32_t height,fpos; uint32_t fpipbits,issued,lag:20,peerid:12; \ +uint16_t hdrsi:15,mainchain:1,bundlei:11,valid:1,queued:1,txvalid:1,newtx:1,processed:1; \ +UT_hash_handle hh; struct iguana_bundlereq *req; \ +struct iguana_blockRO RO + +struct iguana_block +{ + iguana_blockfields; + struct iguana_zcashRO zRO[]; +} __attribute__((packed)); + +struct iguana_zblock // mu +{ + iguana_blockfields; + struct iguana_zcashRO zRO; +} __attribute__((packed)); + +#define IGUANA_LHASH_BLOCKS 0 +#define IGUANA_LHASH_TXIDS 1 // +#define IGUANA_LHASH_UNSPENTS 2 // +#define IGUANA_LHASH_SPENDS 3 // +#define IGUANA_LHASH_PKHASHES 4 // +#define IGUANA_LHASH_ACCOUNTS 5 // +#define IGUANA_LHASH_EXTERNALS 6 // +#define IGUANA_LHASH_KSPACE 7 // +#define IGUANA_LHASH_TXBITS 8 // +#define IGUANA_LHASH_PKBITS 9 // +#define IGUANA_NUMLHASHES (IGUANA_LHASH_PKBITS + 1) + +struct iguana_counts +{ + uint32_t firsttxidind,firstunspentind,firstspendind,firstpkind; + uint64_t credits,debits; + struct iguana_block block; +} __attribute__((packed)); + +struct iguana_blocks +{ + char coin[8]; + struct iguanakv *db; + struct iguana_block *hash; //struct iguana_blockRO *RO; int32_t maxbits; + int32_t maxblocks,initblocks,hashblocks,pending,issuedblocks,recvblocks,emitblocks,parsedblocks,dirty; + struct iguana_zblock hwmchain,prev,prev2; +}; + +struct iguana_ledger +{ + struct iguana_counts snapshot; + //struct iguana_account accounts[]; +} __attribute__((packed)); + +// ramchain temp file structures +struct iguana_unspent20 { uint64_t value; uint32_t scriptpos,txidind:28,type:4; uint16_t scriptlen,fileid; uint8_t rmd160[20]; } __attribute__((packed)); +struct iguana_spend256 { bits256 prevhash2; uint64_t scriptpos:48,vinscriptlen:16; uint32_t sequenceid; int16_t prevout; uint16_t spendind,fileid; } __attribute__((packed)); + +// permanent readonly structs +struct iguana_txid { bits256 txid; uint32_t txidind:29,firstvout:28,firstvin:28,bundlei:11,locktime,version,timestamp,extraoffset; uint16_t numvouts,numvins; } __attribute__((packed)); + +struct iguana_unspent { uint64_t value; uint32_t txidind,pkind,prevunspentind,scriptpos; uint16_t scriptlen,hdrsi; uint16_t fileid:11,type:5; int16_t vout; } __attribute__((packed)); + +struct iguana_spend { uint64_t scriptpos:48,scriptlen:16; uint32_t spendtxidind,sequenceid; int16_t prevout; uint16_t fileid:15,external:1; } __attribute__((packed)); // numsigs:4,numpubkeys:4,p2sh:1,sighash:4 + +struct iguana_pkhash { uint8_t rmd160[20]; uint32_t pkind; } __attribute__((packed)); //firstunspentind,pubkeyoffset + +// dynamic +struct iguana_account { int64_t total; uint32_t lastunspentind; } __attribute__((packed)); +struct iguana_utxo { uint32_t fromheight:31,lockedflag:1,prevunspentind:31,spentflag:1; } __attribute__((packed)); +struct iguana_hhaccount { UT_hash_handle hh; uint64_t pval; struct iguana_account a; } __attribute__((packed)); +struct iguana_hhutxo { UT_hash_handle hh; uint64_t uval; struct iguana_utxo u; } __attribute__((packed)); + +// GLOBAL one zero to non-zero write (unless reorg) +struct iguana_spendvector { uint64_t value; uint32_t pkind,unspentind; int32_t fromheight; uint16_t hdrsi:15,tmpflag:1; } __attribute__((packed)); // unspentind +//struct iguana_pkextra { uint32_t firstspendind; } __attribute__((packed)); // pkind + +struct iguana_txblock +{ + uint32_t numtxids,numunspents,numspends,extralen,recvlen; + // following set during second pass (still in peer context) + uint32_t numpkinds,numexternaltxids,datalen,pkoffset; + uint8_t space[256]; // order: extra[], T, U, S, P, external txids + struct iguana_zblock zblock; +}; + +#define RAMCHAIN_PTR(rdata,offset) ((void *)(long)((long)(rdata) + (long)(rdata)->offset)) +struct iguana_ramchaindata +{ + bits256 sha256; + bits256 lhashes[IGUANA_NUMLHASHES],firsthash2,prevhash2; + int64_t allocsize,Boffset,Toffset,Uoffset,Soffset,Poffset,Aoffset,Xoffset,TXoffset,PKoffset,Koffset; + int32_t numblocks,height,firsti,hdrsi,txsparsebits,pksparsebits; + uint32_t numtxids,numunspents,numspends,numpkinds,numexternaltxids,numtxsparse,numpksparse,scriptspace,stackspace; + uint8_t rdata[]; +}; + +struct iguana_ramchain_hdr +{ + uint32_t txidind,unspentind,spendind,scriptoffset,stacksize; uint16_t hdrsi,bundlei:15,ROflag:1; + struct iguana_ramchaindata *data; +}; + +struct iguana_ramchain +{ + struct iguana_ramchain_hdr H; bits256 lasthash2; uint64_t datasize,allocatedA2,allocatedU2; + uint32_t numblocks:31,expanded:1,pkind,externalind,height,numXspends; + long sparseadds,sparsesearches,sparseadditers,sparsesearchiters,sparsehits,sparsemax; + struct iguana_kvitem *txids,*pkhashes; + struct OS_memspace *hashmem; long filesize,sigsfilesize,debitsfilesize,lastspendsfilesize; + void *fileptr,*sigsfileptr,*Xspendptr,*debitsfileptr,*lastspendsfileptr; + char from_ro,from_roX,from_roA,from_roU; + struct iguana_account *A,*A2,*creditsA; struct iguana_spendvector *Xspendinds; + struct iguana_utxo *Uextras; uint8_t *txbits; struct iguana_txid *cacheT; + //int16_t permutation[IGUANA_MAXBUNDLES]; + //struct iguana_Uextra *U2,*roU2; struct iguana_pkextra *P2,*roP2; +}; + +struct iguana_peer +{ + struct queueitem DL; + queue_t sendQ; + bits256 iphash,pubkey,persistent; uint32_t lastpersist; uint8_t netmagic[4]; + struct iguana_msgaddress A; + char ipaddr[64],lastcommand[16],coinname[64],symbol[64]; + uint64_t pingnonce,totalsent,totalrecv,ipbits; double pingtime,sendmillis,pingsum,getdatamillis; + uint32_t lastcontact,sendtime,ready,startsend,startrecv,pending,lastgotaddr,lastblockrecv,pendtime,lastflush,lastpoll,myipbits,persistent_peer,protover; + int32_t supernet,basilisk,dead,addrind,usock,lastheight,relayflag,numpackets,numpings,ipv6,height,rank,pendhdrs,pendblocks,recvhdrs,lastlefti,validpub,othervalid,dirty[2],laggard,headerserror; + double recvblocks,recvtotal; + int64_t allocated,freed; + bits256 RThashes[IGUANA_MAXBUNDLESIZE]; int32_t numRThashes; + struct msgcounts msgcounts; + struct OS_memspace RAWMEM,TXDATA,HASHMEM; + struct iguana_ramchain ramchain; + struct iguana_fileitem *filehash2; int32_t numfilehash2,maxfilehash2; + //struct iguana_bundle *bp; + FILE *voutsfp,*vinsfp; + uint8_t *blockspace;//[IGUANA_MAXPACKETSIZE + 8192]; +#ifdef IGUANA_PEERALLOC + struct OS_memspace *SEROUT[128]; +#endif +}; + +struct iguana_peers +{ + bits256 lastrequest; + struct iguana_peer active[IGUANA_MAXPEERS+1],*ranked[IGUANA_MAXPEERS+1],*localaddr; + struct iguana_thread *peersloop,*recvloop; pthread_t *acceptloop; + double topmetrics[IGUANA_MAXPEERS+1],avemetric; + long vinptrs[IGUANA_MAXPEERS+1][2],voutptrs[IGUANA_MAXPEERS+1][2]; + uint32_t numranked,mostreceived,shuttingdown,lastpeer,lastmetrics,numconnected; + int32_t numfiles; +}; + +struct iguana_bloom16 { uint8_t hash2bits[65536 / 8]; }; +struct iguana_bloominds { uint16_t inds[8]; }; + +struct iguana_bundle +{ + struct queueitem DL; struct iguana_info *coin; struct iguana_bundle *nextbp; + struct iguana_bloom16 bloom; int64_t totaldurations,duplicatedurations; int32_t durationscount,duplicatescount; + uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime,queued,startutxo,utxofinish,balancefinish,validated,lastspeculative,dirty,nexttime,currenttime,lastprefetch,lastRT,missingstime,unsticktime,converted; + int32_t numhashes,numrecv,numsaved,numcached,generrs,currentflag,origmissings,numissued,Xvalid; + int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents,numspec,isRT; + double avetime,threshold,metric; uint64_t datasize,estsize; + struct iguana_block *blocks[IGUANA_MAXBUNDLESIZE]; + uint8_t *speculativecache[IGUANA_MAXBUNDLESIZE],haveblock[IGUANA_MAXBUNDLESIZE/3+1]; + uint32_t issued[IGUANA_MAXBUNDLESIZE]; + bits256 prevbundlehash2,hashes[IGUANA_MAXBUNDLESIZE+1],nextbundlehash2,allhash,*speculative,validatehash; + struct iguana_ramchain ramchain; uint8_t red,green,blue; + struct iguana_spendvector *tmpspends; int32_t numtmpspends; +}; + +struct iguana_bundlereq +{ + struct queueitem DL; struct iguana_info *coin; int32_t type; + struct iguana_peer *addr; struct iguana_zblock *blocks; bits256 *hashes,txid; + struct iguana_txdatabits txdatabits; + struct iguana_msghdr H; + int32_t allocsize,datalen,n,recvlen,numtx; uint32_t ipbits; + struct iguana_zblock zblock; + uint8_t copyflag,serializeddata[]; +}; + +struct iguana_bitmap { int32_t width,height,amplitude; char name[52]; uint8_t data[IGUANA_WIDTH*IGUANA_HEIGHT*3]; }; + +struct iguana_waddress { UT_hash_handle hh; uint64_t balance,*unspents; uint32_t maxunspents,numunspents; uint16_t scriptlen; uint8_t rmd160[20],pubkey[33],wiftype,addrtype; bits256 privkey; char symbol[8],coinaddr[36],wifstr[54]; uint8_t redeemScript[]; }; +struct iguana_waccount { UT_hash_handle hh; char account[128]; struct iguana_waddress *waddr,*current; }; +struct iguana_wallet { UT_hash_handle hh; struct iguana_waccount *wacct; }; + +struct scriptinfo { UT_hash_handle hh; uint32_t fpos; uint16_t scriptlen; uint8_t script[]; }; +struct hhbits256 { UT_hash_handle hh; bits256 txid; int32_t height; uint16_t firstvout; }; + +struct iguana_monitorinfo { bits256 txid; int32_t numreported; uint8_t peerbits[IGUANA_MAXPEERS >> 3]; }; + + +struct iguana_info +{ + UT_hash_handle hh; + char name[64],symbol[64],protocol,statusstr[512],scriptsfname[2][512]; + struct iguana_peers *peers; struct iguana_peer internaladdr; + basilisk_func basilisk_rawtx,basilisk_balances,basilisk_value; + basilisk_metricfunc basilisk_rawtxmetric,basilisk_balancesmetric,basilisk_valuemetric; + + uint32_t fastfind; FILE *fastfps[0x100]; uint8_t *fast[0x100]; int32_t *fasttables[0x100]; long fastsizes[0x100]; + uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime; + int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,PREFETCHLAG,estsize,activebundles; + int32_t MAXPEERS,MAXPENDINGREQUESTS,MAXBUNDLES,MAXSTUCKTIME,active,closestbundle,numemitted,lastsweep,numemit,startutc,newramchain,numcached,cachefreed,helperdepth,startPEND,endPEND,enableCACHE,RELAYNODE,VALIDATENODE,origbalanceswritten,balanceswritten,RTheight,RTdatabad; + bits256 balancehash,allbundles; + uint32_t lastsync,parsetime,numiAddrs,lastpossible,bundlescount,savedblocks,backlog,spendvectorsaved,laststats,lastinv2,symbolcrc; char VALIDATEDIR[512]; + int32_t longestchain,badlongestchain,longestchain_strange,RTramchain_busy,emitbusy,stuckiters,virtualchain; + struct tai starttime; double startmillis; + struct iguana_chain *chain; + struct iguana_iAddr *iAddrs; + void *ctx; + struct iguana_bitmap *screen; + struct OS_memspace TXMEM,MEM,MEMB[IGUANA_MAXBUNDLESIZE]; + queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,cacheQ,recvQ,msgrequestQ; + double parsemillis,avetime; uint32_t Launched[8],Terminated[8]; + portable_mutex_t peers_mutex,blocks_mutex; + char changeaddr[64]; + struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending; + struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem; bits256 RThash1; + int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle,numsaved,pendbalances,numverified,blockdepth; + uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,firstRTgenesis,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime,RThdrstime,nextchecked; + double bandwidth,maxbandwidth,backstopmillis; bits256 backstophash2; int64_t spaceused; + int32_t initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids,allhashes,balanceflush; bits256 reqtxids[64]; + void *launched,*started,*rpcloop; + uint64_t bloomsearches,bloomhits,bloomfalse,collisions,txfee_perkb,txfee; + uint8_t *blockspace; int32_t blockspacesize; struct OS_memspace blockMEM; + bits256 APIblockhash,APItxid; char *APIblockstr; + struct iguana_hhutxo *utxotable; struct iguana_hhaccount *accountstable; char lastdispstr[2048]; + double txidfind_totalmillis,txidfind_num,spendtxid_totalmillis,spendtxid_num; + struct iguana_monitorinfo monitoring[256]; + struct gecko_sequences SEQ; + struct iguana_blocks blocks; +}; + +struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; }; + +struct vin_info +{ + struct iguana_msgvin vin; uint64_t amount; cJSON *extras; bits256 sigtxid; + int32_t M,N,validmask,spendlen,type,p2shlen,suffixlen,numpubkeys,numsigs,height,hashtype; + uint32_t sequence,unspentind; struct vin_signer signers[16]; char coinaddr[65]; + uint8_t rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE],p2shscript[IGUANA_MAXSCRIPTSIZE]; +}; + +struct bitcoin_unspent +{ + bits256 txid,privkeys[16]; uint64_t value; int32_t vout,spendlen,p2shlen,numpubkeys; uint32_t sequence; + uint8_t addrtype,rmd160[20],pubkeys[16][65],spendscript[IGUANA_MAXSCRIPTSIZE],p2shscript[IGUANA_MAXSCRIPTSIZE]; +}; + +struct bitcoin_spend +{ + char changeaddr[64]; uint8_t change160[20]; + int32_t numinputs; + int64_t txfee,input_satoshis,satoshis,change; + struct bitcoin_unspent inputs[]; +}; + +struct exchange_quote { uint64_t satoshis,orderid,offerNXT,exchangebits; double price,volume; uint32_t timestamp,val; }; + +struct supernet_address +{ + bits256 pubkey,iphash,persistent; + uint32_t selfipbits,myipbits; int32_t confirmed,totalconfirmed; uint64_t nxt64bits; + char NXTADDR[32],BTC[64],BTCD[64]; +}; + +struct supernet_info +{ + struct supernet_address myaddr; + bits256 persistent_priv,privkey; + uint8_t persistent_pubkey33[33]; + char ipaddr[64],NXTAPIURL[512],secret[4096],rpcsymbol[64],handle[1024],permanentfile[1024]; + char *decryptstr; + int32_t maxdelay,IAMRELAY,publicRPC; + uint32_t expiration,dirty; + uint16_t argport,rpcport; + struct basilisk_info basilisks; + struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges; + struct iguana_waccount *wallet; + struct iguana_info *allcoins; int32_t allcoins_being_added,allcoins_numvirts; portable_mutex_t allcoins_mutex; + void *ctx; + + // compatibility + bits256 pangea_category,instantdex_category; +}; +#endif + diff --git a/includes/iguana_types.h b/includes/iguana_types.h new file mode 100755 index 000000000..baf36306e --- /dev/null +++ b/includes/iguana_types.h @@ -0,0 +1,26 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef H_IGUANATYPES_H +#define H_IGUANATYPES_H + + +typedef void (*iguana_func)(void *); +typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t len); +typedef void *(*basilisk_func)(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *vals); +typedef double (*basilisk_metricfunc)(struct supernet_info *myinfo,struct basilisk_item *ptr,char *result); + +#endif +