jl777
7 years ago
185 changed files with 24892 additions and 1097 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
@ -0,0 +1,2 @@ |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"COQUI.conf\",\"path\":\"${HOME#"/"}/.komodo/COQUI\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":0,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"COQUI\",\"name\":\"COQUI\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"dd5ce076\",\"p2p\":14275,\"rpc\":14276,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -1 +1 @@ |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"MESH.conf\",\"path\":\"${HOME#"/"}/.komodo/MESH\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"MESH\",\"name\":\"MESH\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"c28227c2\",\"p2p\":11940,\"rpc\":11941,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"MESH.conf\",\"path\":\"${HOME#"/"}/.komodo/MESH\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"MESH\",\"name\":\"MESH\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"4d6bbfb6\",\"p2p\":8399,\"rpc\":8400,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -1 +1 @@ |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"WLC.conf\",\"path\":\"${HOME#"/"}/.komodo/WLC\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"WLC\",\"name\":\"WLC\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"7ec1c253\",\"p2p\":15431,\"rpc\":15432,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"WLC.conf\",\"path\":\"${HOME#"/"}/.komodo/WLC\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"WLC\",\"name\":\"WLC\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"7ec1c253\",\"p2p\":12166,\"rpc\":12167,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -0,0 +1,2 @@ |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"bitcoin.conf\",\"path\":\"/${HOME#"/"}/Library/Application\ Support/Bitcoin\",\"prefetchlag\":-1,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":64,\"endpend\":64,\"services\":0,\"maxpeers\":512,\"RELAY\":-1,\"VALIDATE\":0,\"portp2p\":8333,\"minconfirms\":1}" |
|||
|
@ -0,0 +1 @@ |
|||
curl --url "http://127.0.0.1:7776" --data "{\"conf\":\"COQUI.conf\",\"path\":\"${HOME#"/"}/.komodo/COQUI\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"COQUI\",\"name\":\"COQUI\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"fa05f107\",\"p2p\":14275,\"rpc\":14276,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
@ -1,4 +1,4 @@ |
|||
#!/bin/bash |
|||
|
|||
curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":68,\"endpend\":68,\"services\":129,\"maxpeers\":256,\"newcoin\":\"LTC\",\"name\":\"Litecoin\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"fbc0b6db\",\"p2p\":9333,\"rpc\":9332,\"pubval\":48,\"p2shval\":5,\"wifval\":176,\"txfee_satoshis\":\"100000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2\",\"genesis\":{\"version\":1,\"timestamp\":1317972665,\"nBits\":\"1e0ffff0\",\"nonce\":2084524493,\"merkle_root\":\"97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9\"},\"alertpubkey\":\"040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9\",\"protover\":70002}" |
|||
curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":68,\"endpend\":68,\"services\":129,\"maxpeers\":256,\"newcoin\":\"LTC\",\"name\":\"Litecoin\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"fbc0b6db\",\"p2p\":9333,\"rpc\":9332,\"pubval\":48,\"p2shval\":5,\"wifval\":176,\"txfee_satoshis\":\"100000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2\",\"genesis\":{\"version\":1,\"timestamp\":1317972665,\"nBits\":\"1e0ffff0\",\"nonce\":2084524493,\"merkle_root\":\"97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9\"},\"alertpubkey\":\"040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9\",\"protover\":70002}" |
|||
|
|||
|
@ -0,0 +1,4 @@ |
|||
~/komodo/src/komodod -ac_name=JUMBLR -ac_supply=999999 -addnode=78.47.196.146 & |
|||
|
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"JUMBLR.conf\",\"path\":\"${HOME#"/"}/.komodo/JUMBLR\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"JUMBLR\",\"name\":\"JUMBLR\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"7223759e\",\"p2p\":15105,\"rpc\":15106,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -0,0 +1,3 @@ |
|||
/Applications/komodoOSX.app/Contents/komodod -ac_name=JUMBLR -ac_supply=999999 -addnode=78.47.196.146 & |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"JUMBLR.conf\",\"path\":\"/${HOME#"/"}/Library/Application\ Support/Komodo/JUMBLR\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"JUMBLR\",\"name\":\"JUMBLR\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"7223759e\",\"p2p\":15105,\"rpc\":15106,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -0,0 +1,2 @@ |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"komodo.conf\",\"path\":\"/${HOME#"/"}/Library/Application\ Support/Komodo\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":8,\"endpend\":8,\"services\":0,\"maxpeers\":32,\"newcoin\":\"KMD\",\"name\":\"Komodo\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"f9eee48d\",\"p2p\":7770,\"rpc\":7771,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0}" |
|||
|
@ -0,0 +1,4 @@ |
|||
#!/bin/bash |
|||
|
|||
curl --url "http://127.0.0.1:7776" --data "{\"conf\":\"litecoin.conf\",\"path\":\"${HOME#"/"}/.litecoin\",\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":68,\"endpend\":68,\"services\":129,\"maxpeers\":256,\"newcoin\":\"LTC\",\"name\":\"Litecoin\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"fbc0b6db\",\"p2p\":9333,\"rpc\":9332,\"pubval\":48,\"p2shval\":5,\"wifval\":176,\"txfee_satoshis\":\"100000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2\",\"genesis\":{\"version\":1,\"timestamp\":1317972665,\"nBits\":\"1e0ffff0\",\"nonce\":2084524493,\"merkle_root\":\"97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9\"},\"alertpubkey\":\"040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9\",\"protover\":70002}" |
|||
|
@ -1 +1 @@ |
|||
curl --url "http://127.0.0.1:7776" --data "{\"conf\":\"MESH.conf\",\"path\":\"${HOME#"/"}/.komodo/MESH\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"MESH\",\"name\":\"MESH\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"c28227c2\",\"p2p\":11940,\"rpc\":11941,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
curl --url "http://127.0.0.1:7776" --data "{\"conf\":\"MESH.conf\",\"path\":\"${HOME#"/"}/.komodo/MESH\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"MESH\",\"name\":\"MESH\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"4d6bbfb6\",\"p2p\":9454,\"rpc\":9455,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -0,0 +1,3 @@ |
|||
~/komodo/src/komodod -ac_name=REVS -ac_supply=1300000 -addnode=78.47.196.146 & |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"REVS.conf\",\"path\":\"${HOME#"/"}/.komodo/REVS\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"REVS\",\"name\":\"REVS\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"905c3498\",\"p2p\":10195,\"rpc\":10196,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -0,0 +1,3 @@ |
|||
/Applications/komodoOSX.app/Contents/komodod -ac_name=REVS -ac_supply=1300000 -addnode=78.47.196.146 & |
|||
curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"REVS.conf\",\"path\":\"/${HOME#"/"}/Library/Application\ Support/Komodo/REVS\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"REVS\",\"name\":\"REVS\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"905c3498\",\"p2p\":10195,\"rpc\":10196,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -1 +1 @@ |
|||
curl --url "http://127.0.0.1:7776" --data "{\"conf\":\"WLC.conf\",\"path\":\"${HOME#"/"}/.komodo/WLC\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"WLC\",\"name\":\"WLC\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"7ec1c253\",\"p2p\":15431,\"rpc\":15432,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
curl --url "http://127.0.0.1:7776" --data "{\"conf\":\"WLC.conf\",\"path\":\"${HOME#"/"}/.komodo/WLC\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"WLC\",\"name\":\"WLC\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"7ec1c253\",\"p2p\":12166,\"rpc\":12167,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" |
|||
|
@ -0,0 +1,957 @@ |
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// DEXstats.h
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
#ifndef DEXstats_h |
|||
#define DEXstats_h |
|||
|
|||
#define LEFTMARGIN 40 |
|||
#define MAX_SPLINES 1024 |
|||
#define MAX_LOOKAHEAD 7 |
|||
|
|||
struct stats_spline { char name[64]; int32_t splineid,lasti,basenum,num,firstx,dispincr,spline32[MAX_SPLINES][4]; uint32_t utc32[MAX_SPLINES]; int64_t spline64[MAX_SPLINES][4]; double dSplines[MAX_SPLINES][4],pricevals[MAX_SPLINES+MAX_LOOKAHEAD],lastutc,lastval,aveslopeabs; }; |
|||
|
|||
#define _extrapolate_Spline(Splines,gap) ((double)(Splines)[0] + ((gap) * ((double)(Splines)[1] + ((gap) * ((double)(Splines)[2] + ((gap) * (double)(Splines)[3])))))) |
|||
#define _extrapolate_Slope(Splines,gap) ((double)(Splines)[1] + ((gap) * ((double)(Splines)[2] + ((gap) * (double)(Splines)[3])))) |
|||
|
|||
#define dto64(x) ((int64_t)((x) * (double)SATOSHIDEN * SATOSHIDEN)) |
|||
#define dto32(x) ((int32_t)((x) * (double)SATOSHIDEN)) |
|||
#define i64tod(x) ((double)(x) / ((double)SATOSHIDEN * SATOSHIDEN)) |
|||
#define i32tod(x) ((double)(x) / (double)SATOSHIDEN) |
|||
#define _extrapolate_spline64(spline64,gap) ((double)i64tod((spline64)[0]) + ((gap) * ((double)i64tod(.001*.001*(spline64)[1]) + ((gap) * ((double)i64tod(.001*.001*.001*.001*(spline64)[2]) + ((gap) * (double)i64tod(.001*.001*.001*.001*.001*.001*(spline64)[3]))))))) |
|||
#define _extrapolate_spline32(spline32,gap) ((double)i32tod((spline32)[0]) + ((gap) * ((double)i32tod(.001*.001*(spline32)[1]) + ((gap) * ((double)i32tod(.001*.001*.001*.001*(spline32)[2]) + ((gap) * (double)i32tod(.001*.001*.001*.001*.001*.001*(spline32)[3]))))))) |
|||
|
|||
uint32_t forex_colors[16]; |
|||
double Display_scale = 0.25; |
|||
|
|||
struct DEXstats_disp { double pricesum,volumesum; }; |
|||
|
|||
struct DEXstats_pricepoint |
|||
{ |
|||
double price,volume; |
|||
uint32_t height; |
|||
uint16_t seconds; |
|||
int8_t hour,dir; |
|||
}; |
|||
|
|||
struct DEXstats_pairinfo |
|||
{ |
|||
char dest[16]; |
|||
int32_t numprices; |
|||
struct DEXstats_pricepoint *prices; |
|||
}; |
|||
|
|||
struct DEXstats_datenuminfo |
|||
{ |
|||
int32_t numpairs,datenum; |
|||
struct DEXstats_pairinfo *pairs; |
|||
}; |
|||
|
|||
struct DEXstats_priceinfo |
|||
{ |
|||
char symbol[16]; |
|||
int32_t firstdatenum,numdates; |
|||
struct DEXstats_datenuminfo *dates; |
|||
} Prices[1024]; |
|||
int32_t Num_priceinfos; |
|||
|
|||
void stats_pricepoint(int32_t dir,struct DEXstats_pricepoint *ptr,uint8_t hour,uint16_t seconds,int32_t height,double volume,double price) |
|||
{ |
|||
ptr->price = price; |
|||
ptr->volume = volume; |
|||
ptr->height = height; |
|||
ptr->hour = hour; |
|||
ptr->dir = dir; |
|||
ptr->seconds = seconds; |
|||
} |
|||
|
|||
void stats_pairupdate(int32_t dir,struct DEXstats_datenuminfo *date,char *symbol,char *dest,int32_t datenum,int32_t hour,int32_t seconds,int32_t height,double volume,double price) |
|||
{ |
|||
int32_t i; struct DEXstats_pairinfo *pair = 0; |
|||
if ( date->datenum != datenum || seconds < 0 || seconds >= 3600 || hour < 0 || hour >= 24 ) |
|||
{ |
|||
printf("date->datenum %d != %d? hour.%d seconds.%d\n",date->datenum,datenum,hour,seconds); |
|||
return; |
|||
} |
|||
//printf("%d numpairs.%d %p %p\n",date->datenum,date->numpairs,date,date->pairs);
|
|||
for (i=0; i<date->numpairs; i++) |
|||
if ( strcmp(dest,date->pairs[i].dest) == 0 ) |
|||
{ |
|||
pair = &date->pairs[i]; |
|||
break; |
|||
} |
|||
if ( date->pairs == 0 || i == date->numpairs ) |
|||
{ |
|||
date->pairs = realloc(date->pairs,sizeof(*date->pairs) * (date->numpairs + 1)); |
|||
pair = &date->pairs[date->numpairs++]; |
|||
memset(pair,0,sizeof(*pair)); |
|||
strcpy(pair->dest,dest); |
|||
printf("%d new pair.%d (%s) -> dest.(%s)\n",date->datenum,date->numpairs,symbol,dest); |
|||
} |
|||
pair->prices = realloc(pair->prices,sizeof(*pair->prices) * (pair->numprices+1)); |
|||
stats_pricepoint(dir,&pair->prices[pair->numprices++],hour,seconds,height,volume,price); |
|||
//printf("(%s/%s).%d numprices.%d h.%d s.%-4d %.8f %.6f\n",symbol,dest,date->datenum,pair->numprices,hour,seconds,price,volume);
|
|||
} |
|||
|
|||
void stats_datenumupdate(int32_t dir,struct DEXstats_priceinfo *pp,int32_t datenum,int32_t hour,int32_t seconds,int32_t height,double volume,char *dest,double price) |
|||
{ |
|||
int32_t offset,i,n; struct DEXstats_datenuminfo *date; |
|||
if ( (offset= datenum - pp->firstdatenum) < 0 ) |
|||
{ |
|||
printf("illegal datenum.%d for %s when 1st.%d\n",datenum,pp->symbol,pp->firstdatenum); |
|||
return; |
|||
} |
|||
if ( offset == 0 || offset > pp->numdates ) |
|||
{ |
|||
pp->dates = realloc(pp->dates,sizeof(*pp->dates) * (offset+1)); |
|||
n = (offset - pp->numdates); |
|||
printf("allocate %s.[%d to %d]\n",pp->symbol,pp->numdates,pp->numdates+n); |
|||
for (i=0; i<=n; i++) |
|||
{ |
|||
date = &pp->dates[pp->numdates + i]; |
|||
if ( date->datenum != pp->firstdatenum + pp->numdates + i ) |
|||
{ |
|||
memset(date,0,sizeof(*date)); |
|||
date->datenum = pp->firstdatenum + pp->numdates + i; |
|||
} |
|||
} |
|||
pp->numdates = offset; |
|||
} |
|||
stats_pairupdate(dir,&pp->dates[offset],pp->symbol,dest,datenum,hour,seconds,height,volume,price); |
|||
} |
|||
|
|||
struct DEXstats_priceinfo *stats_priceinfo(char *symbol,int32_t datenum) |
|||
{ |
|||
int32_t i; struct DEXstats_priceinfo *pp = 0; |
|||
if ( Num_priceinfos >= sizeof(Prices)/sizeof(*Prices) ) |
|||
return(0); |
|||
for (i=0; i<Num_priceinfos; i++) |
|||
if ( strcmp(Prices[i].symbol,symbol) == 0 ) |
|||
{ |
|||
pp = &Prices[i]; |
|||
break; |
|||
} |
|||
if ( i == Num_priceinfos ) |
|||
{ |
|||
pp = &Prices[Num_priceinfos++]; |
|||
strcpy(pp->symbol,symbol); |
|||
pp->firstdatenum = datenum; |
|||
} |
|||
return(pp); |
|||
} |
|||
|
|||
void stats_LPpubkeyupdate(char *LPpubkey,uint32_t timestamp) |
|||
{ |
|||
printf("LP.(%s) t.%u\n",LPpubkey,timestamp); |
|||
} |
|||
|
|||
void stats_priceupdate(int32_t datenum,int32_t hour,int32_t seconds,uint32_t timestamp,int32_t height,char *key,char *LPpubkey,cJSON *tradejson) |
|||
{ |
|||
int32_t dir = 0; uint64_t srcamount,destamount; char *source,*dest; double price; struct DEXstats_priceinfo *pp; |
|||
if ( LPpubkey != 0 ) |
|||
stats_LPpubkeyupdate(LPpubkey,timestamp); |
|||
if ( tradejson != 0 ) |
|||
{ |
|||
source = jstr(jitem(tradejson,0),0); |
|||
srcamount = SATOSHIDEN * jdouble(jitem(tradejson,1),0); |
|||
dest = jstr(jitem(tradejson,2),0); |
|||
destamount = SATOSHIDEN * jdouble(jitem(tradejson,3),0); |
|||
if ( srcamount != 0 && destamount != 0 ) |
|||
{ |
|||
price = (double)destamount / srcamount; |
|||
if ( key != 0 ) |
|||
{ |
|||
dir = 1; |
|||
if ( (pp= stats_priceinfo(source,datenum)) != 0 ) |
|||
stats_datenumupdate(-1,pp,datenum,hour,seconds,height,dstr(srcamount),dest,price); |
|||
if ( (pp= stats_priceinfo(dest,datenum)) != 0 ) |
|||
stats_datenumupdate(1,pp,datenum,hour,seconds,height,dstr(destamount),source,1. / price); |
|||
} |
|||
else if ( (pp= stats_priceinfo(source,datenum)) != 0 ) |
|||
stats_datenumupdate(0,pp,datenum,hour,seconds,height,dstr(srcamount),dest,price); |
|||
} else price = 0.; |
|||
if ( dir != 0 ) |
|||
printf("dir.%-2d %d.%02d.%04d ht.%-4d %s (%s %12.8f) -> (%s %12.8f) %16.8f %16.8f\n",dir,datenum,hour,seconds,height,key!=0?key:"",source,dstr(srcamount),dest,dstr(destamount),price,1./price); |
|||
} |
|||
} |
|||
|
|||
double _pairaved(double valA,double valB) |
|||
{ |
|||
if ( valA != 0. && valB != 0. ) |
|||
return((valA + valB) / 2.); |
|||
else if ( valA != 0. ) return(valA); |
|||
else return(valB); |
|||
} |
|||
|
|||
double calc_loganswer(double pastlogprice,double futurelogprice) |
|||
{ |
|||
if ( fabs(pastlogprice) < .0000001 || fabs(futurelogprice) < .0000001 ) |
|||
return(0); |
|||
return(10000. * (exp(futurelogprice - pastlogprice)-1.)); |
|||
} |
|||
|
|||
double _pairdiff(register double valA,register double valB) |
|||
{ |
|||
if ( valA != 0. && valB != 0. ) |
|||
return((valA - valB)); |
|||
else return(0.); |
|||
} |
|||
|
|||
double balanced_ave(double buf[],int32_t i,int32_t width) |
|||
{ |
|||
register int32_t nonz,j; register double sum,price; |
|||
nonz = 0; |
|||
sum = 0.0; |
|||
for (j=-width; j<=width; j++) |
|||
{ |
|||
price = buf[i + j]; |
|||
if ( price != 0.0 ) |
|||
{ |
|||
sum += price; |
|||
nonz++; |
|||
} |
|||
} |
|||
if ( nonz != 0 ) |
|||
sum /= nonz; |
|||
return(sum); |
|||
} |
|||
|
|||
void buf_trioave(double dest[],double src[],int32_t n) |
|||
{ |
|||
register int32_t i,j,width = 3; |
|||
for (i=0; i<128; i++) |
|||
src[i] = 0; |
|||
//for (i=n-width-1; i>width; i--)
|
|||
// dest[i] = balanced_ave(src,i,width);
|
|||
//for (i=width; i>0; i--)
|
|||
// dest[i] = balanced_ave(src,i,i);
|
|||
for (i=1; i<width; i++) |
|||
dest[i] = balanced_ave(src,i,i); |
|||
for (i=width; i<1024-width; i++) |
|||
dest[i] = balanced_ave(src,i,width); |
|||
dest[0] = _pairaved(dest[0],dest[1] - _pairdiff(dest[2],dest[1])); |
|||
j = width-1; |
|||
for (i=1024-width; i<1023; i++,j--) |
|||
dest[i] = balanced_ave(src,i,j); |
|||
if ( dest[1021] != 0. && dest[1021] != 0. ) |
|||
dest[1023] = ((2.0 * dest[1022]) - dest[1021]); |
|||
else dest[1023] = 0.; |
|||
} |
|||
|
|||
void smooth1024(double dest[],double src[],int32_t smoothiters) |
|||
{ |
|||
double smoothbufA[1024],smoothbufB[1024]; int32_t i; |
|||
buf_trioave(smoothbufA,src,1024); |
|||
for (i=0; i<smoothiters; i++) |
|||
{ |
|||
buf_trioave(smoothbufB,smoothbufA,1024); |
|||
buf_trioave(smoothbufA,smoothbufB,1024); |
|||
} |
|||
buf_trioave(dest,smoothbufA,1024); |
|||
} |
|||
|
|||
float _calc_pricey(register double price,register double weekave) |
|||
{ |
|||
if ( price != 0. && weekave != 0. ) |
|||
return(0.1 * calc_loganswer(weekave,price)); |
|||
else return(0.f); |
|||
} |
|||
|
|||
float pixelwt(register int32_t color) |
|||
{ |
|||
return(((float)((color>>16)&0x0ff) + (float)((color>>8)&0x0ff) + (float)((color>>0)&0x0ff))/0x300); |
|||
} |
|||
|
|||
int32_t pixel_ratios(uint32_t red,uint32_t green,uint32_t blue) |
|||
{ |
|||
float max; |
|||
/*if ( red > green )
|
|||
max = red; |
|||
else |
|||
max = green; |
|||
if ( blue > max ) |
|||
max = blue;*/ |
|||
max = (red + green + blue); |
|||
if ( max == 0. ) |
|||
return(0); |
|||
if ( max > 0xff ) |
|||
{ |
|||
red = (uint32_t)(((float)red / max) * 0xff); |
|||
green = (uint32_t)(((float)green / max) * 0xff); |
|||
blue = (uint32_t)(((float)blue / max) * 0xff); |
|||
} |
|||
|
|||
if ( red > 0xff ) |
|||
red = 0xff; |
|||
if ( green > 0xff ) |
|||
green = 0xff; |
|||
if ( blue > 0xff ) |
|||
blue = 0xff; |
|||
return((red << 16) | (green << 8) | blue); |
|||
} |
|||
|
|||
int32_t conv_yval_to_y(register float yval,register int32_t height) |
|||
{ |
|||
register int32_t y; |
|||
height = (height>>1) - 2; |
|||
y = (int32_t)-yval; |
|||
if ( y > height ) |
|||
y = height; |
|||
else if ( y < -height ) |
|||
y = -height; |
|||
|
|||
y += height; |
|||
if ( y < 0 ) |
|||
y = 0; |
|||
height <<= 1; |
|||
if ( y >= height-1 ) |
|||
y = height-1; |
|||
return(y); |
|||
} |
|||
|
|||
uint32_t scale_color(uint32_t color,float strength) |
|||
{ |
|||
int32_t red,green,blue; |
|||
if ( strength < 0. ) |
|||
strength = -strength; |
|||
red = (color>>16) & 0xff; |
|||
green = (color>>8) & 0xff; |
|||
blue = color & 0xff; |
|||
|
|||
red = (int32_t)((float)red * (strength/100.f)); |
|||
green = (int32_t)((float)green * (strength/100.f)); |
|||
blue = (int32_t)((float)blue * (strength/100.f)); |
|||
if ( red > 0xff ) |
|||
red = 0xff; |
|||
if ( green > 0xff ) |
|||
green = 0xff; |
|||
if ( blue > 0xff ) |
|||
blue = 0xff; |
|||
return((red<<16) | (green<<8) | blue); |
|||
} |
|||
|
|||
uint32_t pixel_blend(uint32_t pixel,uint32_t color)//,int32_t groupsize)
|
|||
{ |
|||
int32_t red,green,blue,sum,n,n2,groupsize = 1; |
|||
float red2,green2,blue2,sum2; |
|||
if ( color == 0 ) |
|||
return(pixel); |
|||
if ( pixel == 0 ) |
|||
{ |
|||
return((1<<24) | scale_color(color,100.f/(float)groupsize)); |
|||
} |
|||
n = (pixel>>24) & 0xff; |
|||
if ( n == 0 ) |
|||
n = 1; |
|||
pixel &= 0xffffff; |
|||
red = (pixel>>16) & 0xff; |
|||
green = (pixel>>8) & 0xff; |
|||
blue = pixel & 0xff; |
|||
sum = red + green + blue; |
|||
|
|||
n2 = (color>>24) & 0xff; |
|||
if ( n2 == 0 ) |
|||
n2 = 1; |
|||
red2 = ((float)((color>>16) & 0xff)) / groupsize; |
|||
green2 = ((float)((color>>8) & 0xff)) / groupsize; |
|||
blue2 = ((float)(color & 0xff)) / groupsize; |
|||
sum2 = (red2 + green2 + blue2); |
|||
|
|||
//printf("gs %d (%d x %d,%d,%d: %d) + (%d x %.1f,%.1f,%.1f: %.1f) = ",groupsize,n,red,green,blue,sum,n2,red2,green2,blue2,sum2);
|
|||
red = (uint32_t)(((((((float)red / (float) sum) * n) + (((float)red2 / (float) sum2) * n2)) / (n+n2)) * ((sum+sum2)/2))); |
|||
green = (uint32_t)(((((((float)green / (float) sum) * n) + (((float)green2 / (float) sum2) * n2)) / (n+n2)) * ((sum+sum2)/2))); |
|||
blue = (uint32_t)(((((((float)blue / (float) sum) * n) + (((float)blue2 / (float) sum2) * n2)) / (n+n2)) * ((sum+sum2)/2))); |
|||
|
|||
n += n2; |
|||
if ( n > 0xff ) |
|||
n = 0xff; |
|||
///printf("%x (%d,%d,%d) ",color,red,green,blue);
|
|||
color = (n<<24) | pixel_ratios(red,green,blue);//pixel_overflow(&red,&green,&blue);
|
|||
|
|||
//printf("%x (%d,%d,%d)\n",color,(color>>16)&0xff,(color>>8)&0xff,color&0xff);
|
|||
return(color); |
|||
} |
|||
|
|||
void init_forex_colors(uint32_t *forex_colors) |
|||
{ |
|||
int32_t i; |
|||
forex_colors[0] = 0x00ff00; |
|||
forex_colors[1] = 0x0033ff; |
|||
forex_colors[2] = 0xff0000; |
|||
forex_colors[3] = 0x00ffff; |
|||
forex_colors[4] = 0xffff00; |
|||
forex_colors[5] = 0xff00ff; |
|||
forex_colors[6] = 0xffffff; |
|||
forex_colors[7] = 0xff8800; |
|||
forex_colors[8] = 0xff88ff; |
|||
for (i=9; i<16; i++) |
|||
forex_colors[i] = pixel_blend(forex_colors[i-8],0xffffff); |
|||
} |
|||
|
|||
int32_t is_primary_color(register uint32_t color) |
|||
{ |
|||
static uint32_t forex_colors[16]; |
|||
register int32_t i; |
|||
if ( forex_colors[0] == 0 ) |
|||
init_forex_colors(forex_colors); |
|||
for (i=0; i<8; i++) |
|||
if ( color == forex_colors[i] ) |
|||
return(1); |
|||
return(0); |
|||
} |
|||
|
|||
void disp_yval(register int32_t color,register float yval,register uint32_t *bitmap,register int32_t x,register int32_t rowwidth,register int32_t height) |
|||
{ |
|||
register int32_t y; |
|||
if ( forex_colors[0] == 0 ) |
|||
init_forex_colors(forex_colors); |
|||
x += LEFTMARGIN; |
|||
if ( x < 0 || x >= rowwidth ) |
|||
return; |
|||
//y = conv_yval_to_y(yval,height/Display_scale) * Display_scale;
|
|||
y = conv_yval_to_y(yval * Display_scale,height); |
|||
if ( 1 && is_primary_color(color) != 0 ) |
|||
{ |
|||
bitmap[y*rowwidth + x] = color; |
|||
//printf("(%d, %d) <- %x, ",x,y,color);
|
|||
return; |
|||
} |
|||
//if ( pixelwt(color) > pixelwt(bitmap[y*rowwidth + x]) )
|
|||
bitmap[y*rowwidth + x] = pixel_blend(bitmap[y*rowwidth + x],color); |
|||
return; |
|||
//if ( is_primary_color(color) != 0 || (is_primary_color(bitmap[y*rowwidth+x]) == 0 && pixelwt(color) > pixelwt(bitmap[y*rowwidth + x])) )
|
|||
// bitmap[y*rowwidth + x] = color;
|
|||
} |
|||
|
|||
void disp_yvalsum(register int32_t color,register float yval,register uint32_t *bitmap,register int32_t x,register int32_t rowwidth,register int32_t height) |
|||
{ |
|||
int32_t y,red,green,blue,dispcolor; |
|||
x += LEFTMARGIN; |
|||
if ( x < 0 || x >= rowwidth ) |
|||
return; |
|||
y = conv_yval_to_y(yval * Display_scale,height); |
|||
red = (color>>16) & 0xff; |
|||
green = (color>>8) & 0xff; |
|||
blue = color & 0xff; |
|||
dispcolor = bitmap[y*rowwidth + x]; |
|||
red += (dispcolor>>16) & 0xff; |
|||
green += (dispcolor>>8) & 0xff; |
|||
blue += dispcolor & 0xff; |
|||
bitmap[y*rowwidth + x] = pixel_ratios(red,green,blue); |
|||
} |
|||
|
|||
void disp_dot(register float radius,register int32_t color,register float yval,register uint32_t *bitmap,register int32_t x,register int32_t rowwidth,register int32_t height) |
|||
{ |
|||
register float i,j,sq,val; |
|||
if ( radius > 1 ) |
|||
{ |
|||
sq = radius * radius; |
|||
for (i=-radius; i<=radius; i++) |
|||
{ |
|||
for (j=-radius; j<=radius; j++) |
|||
{ |
|||
val = ((j*j + i*i) / sq); |
|||
if ( val <= 1. ) |
|||
{ |
|||
val = 1. - val; |
|||
disp_yval(scale_color(color,(100 * val * val * val * val)),yval+j,bitmap,x+i,rowwidth,height); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
else disp_yval(color,yval,bitmap,x,rowwidth,height); |
|||
} |
|||
|
|||
void horizline(int32_t calclogflag,int32_t rowwidth,int32_t height,uint32_t *bitmap,double rawprice,double ave) |
|||
{ |
|||
int32_t x; |
|||
double yval; |
|||
if ( calclogflag != 0 ) |
|||
yval = _calc_pricey(log(rawprice),log(ave)); |
|||
else yval = _calc_pricey(rawprice,ave); |
|||
for (x=0; x<rowwidth; x++) |
|||
disp_yval(0x888888,yval,bitmap,x,rowwidth,height); |
|||
} |
|||
|
|||
void rescale_floats(float *line,int32_t width,double scale) |
|||
{ |
|||
int32_t i; |
|||
for (i=0; i<width; i++) |
|||
line[i] *= scale; |
|||
} |
|||
|
|||
void rescale_doubles(double *line,int32_t width,double scale) |
|||
{ |
|||
int32_t i; |
|||
for (i=0; i<width; i++) |
|||
line[i] *= scale; |
|||
} |
|||
|
|||
double _output_line(int32_t calclogflag,double ave,double *output,double *buf,int32_t n,int32_t color,uint32_t *bitmap,int32_t rowwidth,int32_t height) |
|||
{ |
|||
int32_t x,nonz = 0; |
|||
double yval,val,aveabs = 0.; |
|||
if ( ave == 0. ) |
|||
return(0.); |
|||
if ( calclogflag != 0 ) |
|||
ave = log(ave); |
|||
for (x=0; x<n; x++) |
|||
{ |
|||
if ( (val= buf[x]) != 0. ) |
|||
{ |
|||
//if ( calclogflag != 0 )
|
|||
{ |
|||
val = log(buf[x]); |
|||
if ( ave != 1. ) |
|||
yval = _calc_pricey(val,ave); |
|||
else yval = val; |
|||
} //else yval = (val / ave) * height / 3;
|
|||
//printf("(%f -> %f) ",val,yval);
|
|||
if ( fabs(yval) > .0000000001 ) |
|||
{ |
|||
aveabs += fabs(yval); |
|||
nonz++; |
|||
if ( color != 0 ) |
|||
disp_yval(color,yval,bitmap,x,rowwidth,height); |
|||
} |
|||
} else yval = 0.; |
|||
output[x] = yval; |
|||
} |
|||
if ( nonz != 0 ) |
|||
aveabs /= nonz; |
|||
return(aveabs); |
|||
//
|
|||
//printf("ave %f rowwidth.%d\n",ave,rowwidth);
|
|||
} |
|||
|
|||
double stats_splineval(struct stats_spline *spline,uint32_t timestamp,int32_t lookahead) |
|||
{ |
|||
int32_t i,gap,ind = (spline->num - 1); |
|||
if ( timestamp >= spline->utc32[ind] ) |
|||
{ |
|||
gap = (timestamp - spline->utc32[ind]); |
|||
if ( gap < lookahead ) |
|||
return(_extrapolate_spline64(spline->spline64[ind],gap)); |
|||
else return(0.); |
|||
} |
|||
else if ( timestamp <= spline->utc32[0] ) |
|||
{ |
|||
gap = (spline->utc32[0] - timestamp); |
|||
if ( gap < lookahead ) |
|||
return(_extrapolate_spline64(spline->spline64[0],gap)); |
|||
else return(0.); |
|||
} |
|||
for (i=0; i<spline->num-1; i++) |
|||
{ |
|||
ind = (i + spline->lasti) % (spline->num - 1); |
|||
if ( timestamp >= spline->utc32[ind] && timestamp < spline->utc32[ind+1] ) |
|||
{ |
|||
spline->lasti = ind; |
|||
return(_extrapolate_spline64(spline->spline64[ind],timestamp - spline->utc32[ind])); |
|||
} |
|||
} |
|||
return(0.); |
|||
} |
|||
|
|||
double stats_calcspline(struct stats_spline *spline,double *outputs,double *slopes,int32_t dispwidth,uint32_t *utc32,double *splinevals,int32_t num) |
|||
{ |
|||
static double errsums[3]; static int errcount; |
|||
double c[MAX_SPLINES],f[MAX_SPLINES],dd[MAX_SPLINES],dl[MAX_SPLINES],du[MAX_SPLINES],gaps[MAX_SPLINES]; |
|||
int32_t n,i,lasti,x,numsplines,nonz; double vx,vy,vw,vz,gap,sum,xval,yval,abssum,lastval,lastxval,yval64,yval32,yval3; uint32_t gap32; |
|||
sum = lastxval = n = lasti = nonz = 0; |
|||
for (i=0; i<MAX_SPLINES&&i<num; i++) |
|||
{ |
|||
if ( (f[n]= splinevals[i]) != 0. && utc32[i] != 0 ) |
|||
{ |
|||
//printf("i%d.(%u %f) ",i,utc32[i],splinevals[i]);
|
|||
//printf("%f ",splinevals[i]);
|
|||
if ( n > 0 ) |
|||
{ |
|||
if ( (gaps[n-1]= utc32[i] - lastxval) < 0 ) |
|||
{ |
|||
printf("illegal gap %f to t%d\n",lastxval,utc32[i]); |
|||
return(0); |
|||
} |
|||
} |
|||
spline->utc32[n] = lastxval = utc32[i]; |
|||
n++; |
|||
} |
|||
} |
|||
if ( (numsplines= n) < 4 ) |
|||
return(0); |
|||
for (i=0; i<n-3; i++) |
|||
dl[i] = du[i] = gaps[i+1]; |
|||
for (i=0; i<n-2; i++) |
|||
{ |
|||
dd[i] = 2.0 * (gaps[i] + gaps[i+1]); |
|||
c[i] = (3.0 / (double)gaps[i+1]) * (f[i+2] - f[i+1]) - (3.0 / (double)gaps[i]) * (f[i+1] - f[i]); |
|||
} |
|||
//for (i=0; i<n; i++)
|
|||
// printf("%f ",f[i]);
|
|||
//printf("F2[%d]\n",n);
|
|||
dd[0] += (gaps[0] + (double)gaps[0]*gaps[0] / gaps[1]); |
|||
du[0] -= ((double)gaps[0]*gaps[0] / gaps[1]); |
|||
dd[n-3] += (gaps[n-2] + (double)gaps[n-2]*gaps[n-2] / gaps[n-3]); |
|||
dl[n-4] -= ((double)gaps[n-2]*gaps[n-2] / gaps[n-3]); |
|||
|
|||
//tridiagonal(n-2, dl, dd, du, c);
|
|||
for (i=0; i<n-1-2; i++) |
|||
{ |
|||
du[i] /= dd[i]; |
|||
dd[i+1] -= dl[i]*du[i]; |
|||
} |
|||
c[0] /= dd[0]; |
|||
for (i=1; i<n-2; i++) |
|||
c[i] = (c[i] - dl[i-1] * c[i-1]) / dd[i]; |
|||
for (i=n-2-4; i>=0; i--) |
|||
c[i] -= c[i+1] * du[i]; |
|||
//tridiagonal(n-2, dl, dd, du, c);
|
|||
|
|||
for (i=n-3; i>=0; i--) |
|||
c[i+1] = c[i]; |
|||
c[0] = (1.0 + (double)gaps[0] / gaps[1]) * c[1] - ((double)gaps[0] / gaps[1] * c[2]); |
|||
c[n-1] = (1.0 + (double)gaps[n-2] / gaps[n-3] ) * c[n-2] - ((double)gaps[n-2] / gaps[n-3] * c[n-3]); |
|||
//printf("c[n-1] %f, n-2 %f, n-3 %f\n",c[n-1],c[n-2],c[n-3]);
|
|||
abssum = nonz = lastval = 0; |
|||
outputs[spline->firstx] = f[0]; |
|||
spline->num = numsplines; |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
vx = f[i]; |
|||
vz = c[i]; |
|||
if ( i < n-1 ) |
|||
{ |
|||
gap = gaps[i]; |
|||
vy = ((f[i+1] - f[i]) / gap) - (gap * (c[i+1] + 2.*c[i]) / 3.); |
|||
vw = (c[i+1] - c[i]) / (3. * gap); |
|||
} |
|||
else |
|||
{ |
|||
vy = 0; |
|||
vw = 0; |
|||
} |
|||
//printf("%3d: t%u [%14.11f %14.11f %14.11f %14.11f] gap %f | %d\n",i,spline->utc32[i],(vx),vy*1000*1000,vz*1000*1000*1000*1000,vw*1000*1000*1000*1000*1000*1000,gap,conv_unixtime(&tmp,spline->utc32[i]));
|
|||
spline->dSplines[i][0] = vx, spline->dSplines[i][1] = vy, spline->dSplines[i][2] = vz, spline->dSplines[i][3] = vw; |
|||
spline->spline64[i][0] = dto64(vx), spline->spline64[i][1] = dto64(vy*1000*1000), spline->spline64[i][2] = dto64(vz*1000*1000*1000*1000), spline->spline64[i][3] = dto64(vw*1000*1000*1000*1000*1000*1000); |
|||
spline->spline32[i][0] = dto32(vx), spline->spline32[i][1] = dto32(vy*1000*1000), spline->spline32[i][2] = dto32(vz*1000*1000*1000*1000), spline->spline32[i][3] = dto32(vw*1000*1000*1000*1000*1000*1000); |
|||
gap32 = gap = spline->dispincr; |
|||
xval = spline->utc32[i] + gap; |
|||
lastval = vx; |
|||
while ( i < n-1 ) |
|||
{ |
|||
x = spline->firstx + ((xval - spline->utc32[0]) / spline->dispincr); |
|||
if ( x > dispwidth-1 ) x = dispwidth-1; |
|||
if ( x < 0 ) x = 0; |
|||
if ( (i < n-2 && gap > gaps[i] + spline->dispincr) ) |
|||
break; |
|||
if ( i == n-2 && xval > spline->utc32[n-1] + MAX_LOOKAHEAD*spline->dispincr ) |
|||
{ |
|||
//printf("x.%d dispwidth.%d xval %f > utc[n-1] %f + %f\n",x,dispwidth,xval,utc[n-1],MAX_LOOKAHEAD*incr);
|
|||
break; |
|||
} |
|||
if ( x >= 0 ) |
|||
{ |
|||
yval = _extrapolate_Spline(spline->dSplines[i],gap); |
|||
yval64 = _extrapolate_spline64(spline->spline64[i],gap32); |
|||
if ( (yval3 = stats_splineval(spline,gap32 + spline->utc32[i],MAX_LOOKAHEAD*spline->dispincr)) != 0 ) |
|||
{ |
|||
yval32 = _extrapolate_spline32(spline->spline32[i],gap32); |
|||
errsums[0] += fabs(yval - yval64), errsums[1] += fabs(yval - yval32), errsums[2] += fabs(yval - yval3), errcount++; |
|||
if ( fabs(yval - yval3) > SMALLVAL ) |
|||
printf("(%.10f vs %.10f %.10f %.10f [%.16f %.16f %.16f]) ",yval,yval64,yval32,yval3, errsums[0]/errcount,errsums[1]/errcount,errsums[2]/errcount); |
|||
} |
|||
if ( yval > 5000. ) yval = 5000.; |
|||
else if ( yval < -5000. ) yval = -5000.; |
|||
if ( isnan(yval) == 0 ) |
|||
{ |
|||
outputs[x] = yval; |
|||
spline->lastval = outputs[x], spline->lastutc = xval; |
|||
if ( 1 && fabs(lastval) > SMALLVAL ) |
|||
{ |
|||
if ( lastval != 0 && outputs[x] != 0 ) |
|||
{ |
|||
if ( slopes != 0 ) |
|||
slopes[x] = (outputs[x] - lastval), abssum += fabs(slopes[x]); |
|||
nonz++; |
|||
} |
|||
} |
|||
} |
|||
//else outputs[x] = 0.;
|
|||
//printf("x.%-4d %d %f %f %f i%-4d: gap %9.6f %9.6f last %9.6f slope %9.6f | %9.1f [%9.1f %9.6f %9.6f %9.6f %9.6f]\n",x,firstx,xval,utc[0],incr,i,gap,yval,lastval,slopes[x],xval,utc[i+1],dSplines[i][0],dSplines[i][1]*1000*1000,dSplines[i][2]*1000*1000*1000*1000,dSplines[i][3]*1000*1000*1000*1000*1000*1000);
|
|||
} |
|||
gap32 += spline->dispincr, gap += spline->dispincr, xval += spline->dispincr; |
|||
} |
|||
//double pred = (i>0) ? _extrapolate_Spline(dSplines[i-1],gaps[i-1]) : 0.;
|
|||
//printf("%2d: w%8.1f [gap %f -> %9.6f | %9.6f %9.6f %9.6f %9.6f %9.6f]\n",i,weekinds[i],gap,pred,f[i],dSplines[i].x,1000000*dSplines[i].y,1000000*1000000*dSplines[i].z,1000000*1000000*1000*dSplines[i].w);
|
|||
} |
|||
if ( nonz != 0 ) |
|||
abssum /= nonz; |
|||
spline->aveslopeabs = abssum; |
|||
return(lastval); |
|||
} |
|||
|
|||
int32_t stats_genspline(double output[2048],double slopes[2048],struct stats_spline *spline,int32_t splineid,char *name,uint32_t *utc32,double *splinevals,int32_t numsplines,double *refvals) |
|||
{ |
|||
int32_t i; double origvals[MAX_SPLINES]; |
|||
if ( numsplines > MAX_SPLINES ) |
|||
{ |
|||
printf("numsplines.%d > MAX_SPLINES.%d\n",numsplines,MAX_SPLINES); |
|||
return(-1); |
|||
} |
|||
memset(spline,0,sizeof(*spline)), memset(output,0,sizeof(*output)*2048), memset(slopes,0,sizeof(*slopes)*2048); |
|||
spline->dispincr = 3600, spline->basenum = splineid, strcpy(spline->name,name); |
|||
memcpy(origvals,splinevals,sizeof(*splinevals) * MAX_SPLINES); |
|||
spline->lastval = stats_calcspline(spline,output,slopes,2048,utc32,splinevals,numsplines); |
|||
if ( refvals != 0 ) |
|||
{ |
|||
for (i=0; i<spline->num; i++) |
|||
{ |
|||
if ( i < spline->num ) |
|||
{ |
|||
if ( 0 && refvals[i] != 0 && output[i * 24] != refvals[i] ) |
|||
printf("{%.8f != %.8f}.%d ",output[i * 24],refvals[i],i); |
|||
spline->pricevals[i] = output[i * 24]; |
|||
} |
|||
} |
|||
} |
|||
//printf("spline.%s num.%d\n",name,spline->num);
|
|||
return(spline->num); |
|||
} |
|||
|
|||
void output_line(int32_t calclogflag,double ave,double *buf,int32_t n,int32_t color,uint32_t *bitmap,int32_t rowwidth,int32_t height) |
|||
{ |
|||
double src[1024],dest[1024]; int32_t i; |
|||
memset(src,0,sizeof(src)); |
|||
memset(dest,0,sizeof(dest)); |
|||
if ( (1) ) |
|||
{ |
|||
for (i=0; i<1024; i++) |
|||
src[1023-i] = dest[1023-i] = buf[i]; |
|||
smooth1024(dest,src,3); |
|||
for (i=0; i<1024; i++) |
|||
src[1023-i] = dest[i]; |
|||
} |
|||
else |
|||
{ |
|||
for (i=0; i<1024; i++) |
|||
src[i] = buf[i]; |
|||
} |
|||
_output_line(calclogflag,ave,buf,src,1024,color,bitmap,rowwidth,height); |
|||
} |
|||
|
|||
void stats_updatedisp(struct DEXstats_disp *disp,double price,double volume) |
|||
{ |
|||
if ( price > SMALLVAL && volume > SMALLVAL ) |
|||
{ |
|||
disp->pricesum += (price * volume); |
|||
disp->volumesum += volume; |
|||
} |
|||
} |
|||
|
|||
void stats_dispprices(struct DEXstats_disp *prices,int32_t leftdatenum,int32_t numdates,struct DEXstats_datenuminfo *date,char *dest,int32_t current_daysecond) |
|||
{ |
|||
int32_t i,j,offset,datenum = date->datenum; struct DEXstats_pairinfo *pair; struct DEXstats_pricepoint *ptr; uint32_t timestamp,lefttimestamp,righttimestamp; |
|||
offset = datenum - leftdatenum; |
|||
lefttimestamp = OS_conv_datenum(leftdatenum,0,0,0); |
|||
righttimestamp = OS_conv_datenum(leftdatenum+numdates,0,0,0); |
|||
//printf("search dest.%s datenum.%d vs leftdatenum.%d numdates.%d offset.%d numpairs.%d\n",dest,datenum,leftdatenum,numdates,offset,date->numpairs);
|
|||
for (i=0; i<date->numpairs; i++) |
|||
{ |
|||
if ( strcmp(dest,date->pairs[i].dest) == 0 ) |
|||
{ |
|||
pair = &date->pairs[i]; |
|||
//printf("found dest.(%s) numprices.%d\n",dest,pair->numprices);
|
|||
for (j=0; j<pair->numprices; j++) |
|||
{ |
|||
ptr = &pair->prices[j]; |
|||
timestamp = OS_conv_datenum(date->datenum,ptr->hour,ptr->seconds/60,ptr->seconds%60); |
|||
timestamp += (24*3600 - current_daysecond); |
|||
offset = (timestamp - lefttimestamp) / (24*3600); |
|||
if ( offset >= 0 && offset < numdates ) |
|||
{ |
|||
//printf("found dest.(%s) numprices.%d offset.%d (%.8f %.6f)\n",dest,pair->numprices,offset,ptr->price,ptr->volume);
|
|||
stats_updatedisp(&prices[offset],ptr->price,ptr->volume); |
|||
} |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
#include "../../crypto777/jpeg/jinclude.h" |
|||
#include "../../crypto777/jpeg/jpeglib.h" |
|||
#include "../../crypto777/jpeg/jerror.h" |
|||
|
|||
void gen_jpegfile(char *fname,int32_t quality,uint8_t *bitmap,int32_t width,int32_t height) |
|||
{ |
|||
struct jpeg_compress_struct cinfo; |
|||
struct jpeg_error_mgr jerr; |
|||
FILE * outfile; /* target file */ |
|||
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ |
|||
int row_stride; /* physical row width in image buffer */ |
|||
cinfo.err = jpeg_std_error(&jerr); |
|||
jpeg_create_compress(&cinfo); |
|||
if ( (outfile= fopen(fname,"wb")) == NULL) |
|||
{ |
|||
fprintf(stderr, "can't open %s\n", fname); |
|||
return; |
|||
} |
|||
jpeg_stdio_dest(&cinfo, outfile); |
|||
cinfo.image_width = width; /* image width and height, in pixels */ |
|||
cinfo.image_height = height; |
|||
cinfo.input_components = 3; /* # of color components per pixel */ |
|||
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ |
|||
jpeg_set_defaults(&cinfo); |
|||
jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); |
|||
jpeg_start_compress(&cinfo, TRUE); |
|||
row_stride = width * 3; /* JSAMPLEs per row in image_buffer */ |
|||
while (cinfo.next_scanline < cinfo.image_height) |
|||
{ |
|||
row_pointer[0] = &bitmap[cinfo.next_scanline * row_stride]; |
|||
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1); |
|||
} |
|||
jpeg_finish_compress(&cinfo); |
|||
fclose(outfile); |
|||
jpeg_destroy_compress(&cinfo); |
|||
} |
|||
|
|||
char *stats_prices(char *symbol,char *dest,struct DEXstats_disp *prices,int32_t leftdatenum,int32_t numdates) |
|||
{ |
|||
int32_t i,j,n; struct DEXstats_priceinfo *pp; uint32_t *utc32,tmp,timestamp,lefttimestamp,righttimestamp; double *splinevals,total; char fname[1024]; cJSON *retjson,*array,*item; |
|||
timestamp = (uint32_t)time(NULL); |
|||
if ( Num_priceinfos >= sizeof(Prices)/sizeof(*Prices) ) |
|||
return(0); |
|||
lefttimestamp = OS_conv_datenum(leftdatenum-1,0,0,0); |
|||
righttimestamp = OS_conv_datenum(leftdatenum+numdates,0,0,0); |
|||
for (i=0; i<Num_priceinfos; i++) |
|||
if ( strcmp(Prices[i].symbol,symbol) == 0 ) |
|||
{ |
|||
pp = &Prices[i]; |
|||
for (j=0; j<=pp->numdates; j++) |
|||
{ |
|||
timestamp = OS_conv_datenum(pp->firstdatenum+j,0,0,0); |
|||
if ( timestamp < lefttimestamp ) // can speed up by calculating offset 0
|
|||
{ |
|||
//printf("skip (%s) datenums %d %d %d\n",symbol,datenum,pp->firstdatenum,pp->firstdatenum+pp->numdates);
|
|||
continue; |
|||
} |
|||
stats_dispprices(prices,leftdatenum,numdates,&pp->dates[j],dest,timestamp % (3600*24)); |
|||
} |
|||
break; |
|||
} |
|||
tmp = OS_conv_datenum(leftdatenum,0,0,0); |
|||
utc32 = calloc(sizeof(*utc32),numdates); |
|||
splinevals = calloc(sizeof(*splinevals),numdates); |
|||
for (total=i=n=0; i<numdates; i++,tmp+=24*3600) |
|||
{ |
|||
if ( prices[i].volumesum != 0. ) |
|||
{ |
|||
total += prices[i].volumesum; |
|||
splinevals[n] = (prices[i].pricesum / prices[i].volumesum); |
|||
utc32[n] = tmp; |
|||
//printf("offset.%d splineval %.8f t%u n.%d\n",i,splinevals[n],tmp,n);
|
|||
n++; |
|||
} |
|||
} |
|||
retjson = cJSON_CreateObject(); |
|||
jaddstr(retjson,"source",symbol); |
|||
jaddstr(retjson,"dest",dest); |
|||
jaddnum(retjson,"totalvolume",total); |
|||
jaddnum(retjson,"start",leftdatenum); |
|||
jaddnum(retjson,"numdates",numdates); |
|||
if ( n > 3 ) |
|||
{ |
|||
double output[2048],slopes[2048],sum = 0.; struct stats_spline spline; int32_t splineid = 0; |
|||
memset(&spline,0,sizeof(spline)); |
|||
stats_genspline(output,slopes,&spline,splineid,"spline",utc32,splinevals,n,0); |
|||
array = cJSON_CreateArray(); |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = cJSON_CreateArray(); |
|||
jaddinum(item,utc32[i]); |
|||
jaddinum(item,splinevals[i]); |
|||
jaddi(array,item); |
|||
} |
|||
jadd(retjson,"splinevals",array); |
|||
array = cJSON_CreateArray(); |
|||
for (i=0; i<2048; i++) |
|||
{ |
|||
if ( output[i] == 0. ) |
|||
break; |
|||
jaddinum(array,output[i]); |
|||
sum += output[i]; |
|||
} |
|||
if ( i != 2048 ) |
|||
i++; |
|||
sum /= i; |
|||
uint32_t val,height = 400,*bitmap = calloc(sizeof(*bitmap),height * numdates*24); |
|||
uint8_t red,green,blue,*tmpptr,*bytemap = calloc(sizeof(*bytemap),3 * height * numdates*24); |
|||
horizline(1,numdates*24,height,bitmap,sum,sum); |
|||
output_line(1,sum,output,i,0x00ff00,bitmap,numdates*24,height); |
|||
tmpptr = bytemap; |
|||
for (j=0; j<height*numdates*24; j++) |
|||
{ |
|||
val = bitmap[j]; |
|||
red = val & 0xff; |
|||
green = (val >> 8) & 0xff; |
|||
blue = (val >> 16) & 0xff; |
|||
*tmpptr++ = red; |
|||
*tmpptr++ = green; |
|||
*tmpptr++ = blue; |
|||
} |
|||
sprintf(fname,"%s/bitmaps/%s_%s.jpg",STATS_DESTDIR,symbol,dest), OS_portable_path(fname); |
|||
gen_jpegfile(fname,100,bytemap,numdates*24,height); |
|||
free(bitmap), free(bytemap); |
|||
jaddstr(retjson,"bitmap",fname); |
|||
jadd(retjson,"hourly",array); |
|||
jaddnum(retjson,"average",sum); |
|||
} |
|||
free(utc32); |
|||
free(splinevals); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
|
|||
#ifndef FROM_MARKETMAKER |
|||
char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port) |
|||
{ |
|||
char *method,*agent,*retstr,*source,*dest; struct tai T; uint32_t endtimestamp; struct DEXstats_disp prices[365]; int32_t leftdatenum,seconds,numdates; |
|||
if ( (method= jstr(argjson,"method")) == 0 ) |
|||
return(clonestr("{\"error\":\"need method in request\"}")); |
|||
if ( (agent= jstr(argjson,"agent")) == 0 ) |
|||
agent = "stats"; |
|||
if ( strcmp(method,"bitmap") == 0 ) |
|||
{ |
|||
if ( (endtimestamp= juint(argjson,"endtimestamp")) == 0 ) |
|||
endtimestamp = (uint32_t)time(NULL); |
|||
if ( (source= jstr(argjson,"source")) == 0 ) |
|||
source = "KMD"; |
|||
if ( (dest= jstr(argjson,"dest")) == 0 ) |
|||
dest = "USD"; |
|||
if ( (numdates= jint(argjson,"numdates")) <= 0 || numdates > 1024/24 ) |
|||
numdates = 1024/24; |
|||
leftdatenum = OS_conv_unixtime(&T,&seconds,endtimestamp - numdates*24*3600); |
|||
printf("(%s/%s) endtimestamp.%u: leftdatenum.%d\n",source,dest,endtimestamp,leftdatenum); |
|||
memset(prices,0,sizeof(prices)); |
|||
if ( (retstr= stats_prices(source,dest,prices,leftdatenum,numdates+1)) != 0 ) |
|||
return(retstr); |
|||
} |
|||
return(clonestr(jprint(argjson,0))); |
|||
} |
|||
#endif |
|||
|
|||
#endif /* DEXstats_h */ |
File diff suppressed because it is too large
@ -0,0 +1,381 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_coins.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
char *portstrs[][3] = { { "BTC", "8332" }, { "KMD", "7771" } }; |
|||
|
|||
uint16_t LP_rpcport(char *symbol) |
|||
{ |
|||
int32_t i; |
|||
for (i=0; i<sizeof(portstrs)/sizeof(*portstrs); i++) |
|||
if ( strcmp(portstrs[i][0],symbol) == 0 ) |
|||
return(atoi(portstrs[i][1])); |
|||
return(0); |
|||
} |
|||
|
|||
uint16_t LP_busport(uint16_t rpcport) |
|||
{ |
|||
if ( rpcport == 8332 ) |
|||
return(8334); // BTC
|
|||
else if ( rpcport < (1 << 15) ) |
|||
return(65535 - rpcport); |
|||
else return(rpcport+1); |
|||
} |
|||
|
|||
char *parse_conf_line(char *line,char *field) |
|||
{ |
|||
line += strlen(field); |
|||
for (; *line!='='&&*line!=0; line++) |
|||
break; |
|||
if ( *line == 0 ) |
|||
return(0); |
|||
if ( *line == '=' ) |
|||
line++; |
|||
while ( line[strlen(line)-1] == '\r' || line[strlen(line)-1] == '\n' || line[strlen(line)-1] == ' ' ) |
|||
line[strlen(line)-1] = 0; |
|||
//printf("LINE.(%s)\n",line);
|
|||
_stripwhite(line,0); |
|||
return(clonestr(line)); |
|||
} |
|||
|
|||
void LP_userpassfp(char *symbol,char *username,char *password,FILE *fp) |
|||
{ |
|||
char *rpcuser,*rpcpassword,*str,line[8192]; |
|||
rpcuser = rpcpassword = 0; |
|||
username[0] = password[0] = 0; |
|||
while ( fgets(line,sizeof(line),fp) != 0 ) |
|||
{ |
|||
if ( line[0] == '#' ) |
|||
continue; |
|||
//printf("line.(%s) %p %p\n",line,strstr(line,(char *)"rpcuser"),strstr(line,(char *)"rpcpassword"));
|
|||
if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) |
|||
rpcuser = parse_conf_line(str,(char *)"rpcuser"); |
|||
else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) |
|||
rpcpassword = parse_conf_line(str,(char *)"rpcpassword"); |
|||
} |
|||
if ( rpcuser != 0 && rpcpassword != 0 ) |
|||
{ |
|||
strcpy(username,rpcuser); |
|||
strcpy(password,rpcpassword); |
|||
} |
|||
//printf("%s rpcuser.(%s) rpcpassword.(%s)\n",symbol,rpcuser,rpcpassword);
|
|||
if ( rpcuser != 0 ) |
|||
free(rpcuser); |
|||
if ( rpcpassword != 0 ) |
|||
free(rpcpassword); |
|||
} |
|||
|
|||
void LP_statefname(char *fname,char *symbol,char *assetname,char *str,char *name,char *confpath) |
|||
{ |
|||
if ( confpath != 0 && confpath[0] != 0 ) |
|||
{ |
|||
strcpy(fname,confpath); |
|||
return; |
|||
} |
|||
sprintf(fname,"%s",LP_getdatadir()); |
|||
#ifdef WIN32 |
|||
strcat(fname,"\\"); |
|||
#else |
|||
strcat(fname,"/"); |
|||
#endif |
|||
if ( strcmp(symbol,"BTC") == 0 ) |
|||
{ |
|||
#ifdef __APPLE__ |
|||
strcat(fname,"Bitcoin"); |
|||
#else |
|||
strcat(fname,".bitcoin"); |
|||
#endif |
|||
} |
|||
else if ( name != 0 ) |
|||
{ |
|||
char name2[64]; |
|||
#ifdef __APPLE__ |
|||
int32_t len; |
|||
strcpy(name2,name); |
|||
name2[0] = toupper(name2[0]); |
|||
len = (int32_t)strlen(name2); |
|||
if ( strcmp(&name2[len-4],"coin") == 0 ) |
|||
name2[len - 4] = 'C'; |
|||
#else |
|||
name2[0] = '.'; |
|||
strcpy(name2+1,name); |
|||
#endif |
|||
strcat(fname,name2); |
|||
} |
|||
else |
|||
{ |
|||
#ifdef __APPLE__ |
|||
strcat(fname,"Komodo"); |
|||
#else |
|||
strcat(fname,".komodo"); |
|||
#endif |
|||
if ( strcmp(symbol,"KMD") != 0 ) |
|||
{ |
|||
#ifdef WIN32 |
|||
strcat(fname,"\\"); |
|||
#else |
|||
strcat(fname,"/"); |
|||
#endif |
|||
strcat(fname,assetname); |
|||
} |
|||
} |
|||
#ifdef WIN32 |
|||
strcat(fname,"\\"); |
|||
#else |
|||
strcat(fname,"/"); |
|||
#endif |
|||
strcat(fname,str); |
|||
} |
|||
|
|||
int32_t LP_userpass(char *userpass,char *symbol,char *assetname,char *confroot,char *name,char *confpath) |
|||
{ |
|||
FILE *fp; char fname[512],username[512],password[512],confname[512]; |
|||
userpass[0] = 0; |
|||
sprintf(confname,"%s.conf",confroot); |
|||
if ( 0 ) |
|||
printf("%s (%s) %s confname.(%s) confroot.(%s)\n",symbol,assetname,name,confname,confroot); |
|||
#ifdef __APPLE__ |
|||
int32_t len; |
|||
confname[0] = toupper(confname[0]); |
|||
len = (int32_t)strlen(confname); |
|||
if ( strcmp(&confname[len-4],"coin") == 0 ) |
|||
confname[len - 4] = 'C'; |
|||
#endif |
|||
LP_statefname(fname,symbol,assetname,confname,name,confpath); |
|||
if ( (fp= fopen(fname,"rb")) != 0 ) |
|||
{ |
|||
LP_userpassfp(symbol,username,password,fp); |
|||
sprintf(userpass,"%s:%s",username,password); |
|||
fclose(fp); |
|||
if ( 0 ) |
|||
printf("LP_statefname.(%s) <- %s %s %s (%s) (%s)\n",fname,name,symbol,assetname,userpass,confpath); |
|||
return((int32_t)strlen(userpass)); |
|||
} else printf("cant open.(%s)\n",fname); |
|||
return(-1); |
|||
} |
|||
|
|||
cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) |
|||
{ |
|||
char wifstr[128]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject(); |
|||
jaddstr(item,"coin",coin->symbol); |
|||
if ( showwif != 0 ) |
|||
{ |
|||
bitcoin_priv2wif(coin->wiftaddr,wifstr,LP_mypriv25519,coin->wiftype); |
|||
bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,wifstr); |
|||
if ( bits256_cmp(LP_mypriv25519,checkkey) == 0 ) |
|||
jaddstr(item,"wif",wifstr); |
|||
else jaddstr(item,"wif","error creating wif"); |
|||
} |
|||
if ( coin->inactive != 0 ) |
|||
jaddstr(item,"status","inactive"); |
|||
else jaddstr(item,"status","active"); |
|||
if ( coin->isPoS != 0 ) |
|||
jaddstr(item,"type","PoS"); |
|||
jaddstr(item,"smartaddress",coin->smartaddr); |
|||
jaddstr(item,"rpc",coin->serverport); |
|||
jaddnum(item,"pubtype",coin->pubtype); |
|||
jaddnum(item,"p2shtype",coin->p2shtype); |
|||
jaddnum(item,"wiftype",coin->wiftype); |
|||
jaddnum(item,"txfee",coin->txfee); |
|||
return(item); |
|||
} |
|||
|
|||
cJSON *LP_coinsjson(int32_t showwif) |
|||
{ |
|||
struct iguana_info *coin,*tmp; cJSON *array = cJSON_CreateArray(); |
|||
HASH_ITER(hh,LP_coins,coin,tmp) |
|||
{ |
|||
jaddi(array,LP_coinjson(coin,showwif)); |
|||
} |
|||
return(array); |
|||
} |
|||
|
|||
char *LP_getcoin(char *symbol) |
|||
{ |
|||
int32_t numenabled,numdisabled; struct iguana_info *coin,*tmp; cJSON *item=0,*retjson; |
|||
numenabled = numdisabled = 0; |
|||
retjson = cJSON_CreateObject(); |
|||
HASH_ITER(hh,LP_coins,coin,tmp) |
|||
{ |
|||
if ( strcmp(symbol,coin->symbol) == 0 ) |
|||
item = LP_coinjson(coin,0); |
|||
if ( coin->inactive == 0 ) |
|||
numenabled++; |
|||
else numdisabled++; |
|||
} |
|||
jaddstr(retjson,"result","success"); |
|||
jaddnum(retjson,"enabled",numenabled); |
|||
jaddnum(retjson,"disabled",numdisabled); |
|||
if ( item == 0 ) |
|||
item = cJSON_CreateObject(); |
|||
jadd(retjson,"coin",item); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
|
|||
struct iguana_info *LP_coinsearch(char *symbol) |
|||
{ |
|||
struct iguana_info *coin; |
|||
portable_mutex_lock(&LP_coinmutex); |
|||
HASH_FIND(hh,LP_coins,symbol,strlen(symbol),coin); |
|||
portable_mutex_unlock(&LP_coinmutex); |
|||
return(coin); |
|||
} |
|||
|
|||
struct iguana_info *LP_coinadd(struct iguana_info *cdata) |
|||
{ |
|||
struct iguana_info *coin = calloc(1,sizeof(*coin)); |
|||
//printf("%s: (%s) (%s)\n",symbol,cdata.serverport,cdata.userpass);
|
|||
*coin = *cdata; |
|||
portable_mutex_init(&coin->txmutex); |
|||
portable_mutex_lock(&LP_coinmutex); |
|||
HASH_ADD_KEYPTR(hh,LP_coins,coin->symbol,strlen(coin->symbol),coin); |
|||
portable_mutex_unlock(&LP_coinmutex); |
|||
return(coin); |
|||
} |
|||
|
|||
int32_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *assetname,int32_t isPoS,uint16_t port,uint8_t pubtype,uint8_t p2shtype,uint8_t wiftype,uint64_t txfee,double estimatedrate,int32_t longestchain,uint8_t wiftaddr,uint8_t taddr,uint16_t busport,char *confpath) |
|||
{ |
|||
char *name2; |
|||
memset(coin,0,sizeof(*coin)); |
|||
safecopy(coin->symbol,symbol,sizeof(coin->symbol)); |
|||
sprintf(coin->serverport,"127.0.0.1:%u",port); |
|||
coin->isPoS = isPoS; |
|||
coin->taddr = taddr; |
|||
coin->wiftaddr = wiftaddr; |
|||
coin->longestchain = longestchain; |
|||
coin->txfee = txfee; |
|||
coin->pubtype = pubtype; |
|||
coin->p2shtype = p2shtype; |
|||
coin->wiftype = wiftype; |
|||
coin->inactive = (uint32_t)time(NULL); |
|||
coin->bussock = LP_coinbus(busport); |
|||
if ( strcmp(symbol,"KMD") == 0 || (assetname != 0 && assetname[0] != 0) ) |
|||
name2 = 0; |
|||
else name2 = name; |
|||
if ( strcmp(symbol,"XVG") == 0 || strcmp(symbol,"CLOAK") == 0 || strcmp(symbol,"PPC") == 0 || strcmp(symbol,"BCC") == 0 || strcmp(symbol,"ORB") == 0 ) |
|||
{ |
|||
coin->noimportprivkey_flag = 1; |
|||
printf("truncate importprivkey for %s\n",symbol); |
|||
} |
|||
return(LP_userpass(coin->userpass,symbol,assetname,name,name2,confpath)); |
|||
} |
|||
|
|||
int32_t LP_isdisabled(char *base,char *rel) |
|||
{ |
|||
struct iguana_info *coin; |
|||
if ( base != 0 && (coin= LP_coinsearch(base)) != 0 && coin->inactive != 0 ) |
|||
return(1); |
|||
else if ( rel != 0 && (coin= LP_coinsearch(rel)) != 0 && coin->inactive != 0 ) |
|||
return(1); |
|||
else return(0); |
|||
} |
|||
|
|||
struct iguana_info *LP_coinfind(char *symbol) |
|||
{ |
|||
struct iguana_info *coin,cdata; int32_t isinactive,isPoS,longestchain = 1; uint16_t port,busport; uint64_t txfee; double estimatedrate; uint8_t pubtype,p2shtype,wiftype; char *name,*assetname; |
|||
if ( (coin= LP_coinsearch(symbol)) != 0 ) |
|||
return(coin); |
|||
if ( (port= LP_rpcport(symbol)) == 0 ) |
|||
return(0); |
|||
if ( (busport= LP_busport(port)) == 0 ) |
|||
return(0); |
|||
isPoS = 0; |
|||
txfee = LP_MIN_TXFEE; |
|||
estimatedrate = 20; |
|||
pubtype = 60; |
|||
p2shtype = 85; |
|||
wiftype = 188; |
|||
assetname = ""; |
|||
if ( strcmp(symbol,"BTC") == 0 ) |
|||
{ |
|||
txfee = 0; |
|||
estimatedrate = 300; |
|||
pubtype = 0; |
|||
p2shtype = 5; |
|||
wiftype = 128; |
|||
name = "bitcoin"; |
|||
} |
|||
else if ( strcmp(symbol,"KMD") == 0 ) |
|||
name = "komodo"; |
|||
else return(0); |
|||
isinactive = LP_coininit(&cdata,symbol,name,assetname,isPoS,port,pubtype,p2shtype,wiftype,txfee,estimatedrate,longestchain,0,0,busport,0) < 0; |
|||
if ( (coin= LP_coinadd(&cdata)) != 0 ) |
|||
{ |
|||
coin->inactive = isinactive * (uint32_t)time(NULL); |
|||
if ( strcmp(symbol,"KMD") == 0 ) |
|||
coin->inactive = 0; |
|||
else if ( strcmp(symbol,"BTC") == 0 ) |
|||
{ |
|||
coin->inactive = (uint32_t)time(NULL) * !IAMLP; |
|||
printf("BTC inactive.%u\n",coin->inactive); |
|||
} |
|||
} |
|||
return(coin); |
|||
} |
|||
|
|||
// "coins":[{"coin":"<assetchain>", "rpcport":pppp}, {"coin":"LTC", "name":"litecoin", "rpcport":9332, "pubtype":48, "p2shtype":5, "wiftype":176, "txfee":100000 }]
|
|||
// {"coin":"HUSH", "name":"hush", "rpcport":8822, "taddr":28, "pubtype":184, "p2shtype":189, "wiftype":128, "txfee":10000 }
|
|||
|
|||
struct iguana_info *LP_coincreate(cJSON *item) |
|||
{ |
|||
struct iguana_info cdata,*coin=0; int32_t isPoS,longestchain = 1; uint16_t port; uint64_t txfee; double estimatedrate; uint8_t pubtype,p2shtype,wiftype; char *name=0,*symbol,*assetname=0; |
|||
if ( (symbol= jstr(item,"coin")) != 0 && symbol[0] != 0 && strlen(symbol) < 16 && LP_coinfind(symbol) == 0 && (port= juint(item,"rpcport")) != 0 ) |
|||
{ |
|||
isPoS = jint(item,"isPoS"); |
|||
txfee = j64bits(item,"txfee"); |
|||
if ( (estimatedrate= jdouble(item,"estimatedrate")) == 0. ) |
|||
estimatedrate = 20; |
|||
pubtype = juint(item,"pubtype"); |
|||
if ( (p2shtype= juint(item,"p2shtype")) == 0 ) |
|||
p2shtype = 85; |
|||
if ( (wiftype= juint(item,"wiftype")) == 0 ) |
|||
wiftype = 188; |
|||
if ( (assetname= jstr(item,"asset")) != 0 ) |
|||
{ |
|||
name = assetname; |
|||
pubtype = 60; |
|||
} |
|||
else if ( (name= jstr(item,"name")) == 0 ) |
|||
name = symbol; |
|||
if ( LP_coininit(&cdata,symbol,name,assetname==0?"":assetname,isPoS,port,pubtype,p2shtype,wiftype,txfee,estimatedrate,longestchain,juint(item,"wiftaddr"),juint(item,"taddr"),LP_busport(port),jstr(item,"confpath")) < 0 ) |
|||
{ |
|||
coin = LP_coinadd(&cdata); |
|||
coin->inactive = (uint32_t)time(NULL); |
|||
} else coin = LP_coinadd(&cdata); |
|||
} else if ( symbol != 0 && jobj(item,"rpcport") == 0 ) |
|||
printf("SKIP %s, missing rpcport field in coins array\n",symbol); |
|||
if ( coin != 0 && item != 0 ) |
|||
{ |
|||
if ( strcmp("KMD",coin->symbol) != 0 ) |
|||
{ |
|||
if ( jobj(item,"active") != 0 ) |
|||
coin->inactive = !jint(item,"active"); |
|||
else |
|||
{ |
|||
if ( IAMLP == 0 || assetname != name ) |
|||
coin->inactive = (uint32_t)time(NULL); |
|||
else coin->inactive = 0; |
|||
} |
|||
} else coin->inactive = 0; |
|||
} |
|||
if ( coin != 0 && coin->inactive != 0 ) |
|||
printf("LPnode.%d %s inactive.%u %p vs %p\n",IAMLP,coin->symbol,coin->inactive,assetname,name); |
|||
return(0); |
|||
} |
|||
|
@ -0,0 +1,416 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_commands.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
char *LP_numutxos() |
|||
{ |
|||
cJSON *retjson = cJSON_CreateObject(); |
|||
if ( LP_mypeer != 0 ) |
|||
{ |
|||
jaddstr(retjson,"ipaddr",LP_mypeer->ipaddr); |
|||
jaddnum(retjson,"port",LP_mypeer->port); |
|||
jaddnum(retjson,"numutxos",LP_mypeer->numutxos); |
|||
jaddnum(retjson,"numpeers",LP_mypeer->numpeers); |
|||
jaddnum(retjson,"session",LP_sessionid); |
|||
} else jaddstr(retjson,"error","client node"); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
|
|||
char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port
|
|||
{ |
|||
char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t changed,otherpeers,othernumutxos,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; |
|||
//printf("stats_JSON(%s)\n",jprint(argjson,0));
|
|||
if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 ) |
|||
{ |
|||
if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) |
|||
{ |
|||
flag = 1; |
|||
if ( (pushport= juint(argjson,"push")) == 0 ) |
|||
pushport = argport + 1; |
|||
if ( (subport= juint(argjson,"sub")) == 0 ) |
|||
subport = argport + 2; |
|||
if ( (peer= LP_peerfind((uint32_t)calc_ipbits(ipaddr),argport)) != 0 ) |
|||
{ |
|||
if ( 0 && (otherpeers= jint(argjson,"numpeers")) > peer->numpeers ) |
|||
peer->numpeers = otherpeers; |
|||
if ( 0 && (othernumutxos= jint(argjson,"numutxos")) > peer->numutxos ) |
|||
{ |
|||
printf("change.(%s) numutxos.%d -> %d mynumutxos.%d\n",peer->ipaddr,peer->numutxos,othernumutxos,LP_mypeer != 0 ? LP_mypeer->numutxos:0); |
|||
peer->numutxos = othernumutxos; |
|||
} |
|||
if ( peer->sessionid == 0 ) |
|||
peer->sessionid = juint(argjson,"session"); |
|||
//printf("peer.(%s) found (%d %d) (%d %d) (%s)\n",peer->ipaddr,peer->numpeers,peer->numutxos,otherpeers,othernumutxos,jprint(argjson,0));
|
|||
} else LP_addpeer(LP_mypeer,LP_mypubsock,ipaddr,argport,pushport,subport,jint(argjson,"numpeers"),jint(argjson,"numutxos"),juint(argjson,"session")); |
|||
} |
|||
} |
|||
if ( (method= jstr(argjson,"method")) == 0 ) |
|||
{ |
|||
if ( flag == 0 || jobj(argjson,"result") != 0 ) |
|||
printf("stats_JSON no method: (%s) (%s:%u)\n",jprint(argjson,0),ipaddr,argport); |
|||
return(0); |
|||
} |
|||
/*if ( strcmp(method,"hello") == 0 )
|
|||
{ |
|||
//printf("got hello from %s:%u\n",ipaddr!=0?ipaddr:"",argport);
|
|||
return(0); |
|||
} |
|||
else*/ if ( strcmp(method,"sendmessage") == 0 && jobj(argjson,"userpass") == 0 ) |
|||
{ |
|||
static char *laststr; |
|||
char *newstr; bits256 pubkey = jbits256(argjson,"pubkey"); |
|||
if ( bits256_nonz(pubkey) == 0 || bits256_cmp(pubkey,LP_mypub25519) == 0 ) |
|||
{ |
|||
newstr = jprint(argjson,0); |
|||
if ( laststr == 0 || strcmp(laststr,newstr) != 0 ) |
|||
{ |
|||
printf("got message.(%s) from %s:%u\n",newstr,ipaddr!=0?ipaddr:"",argport); |
|||
if ( laststr != 0 ) |
|||
free(laststr); |
|||
laststr = newstr; |
|||
LP_gotmessage(argjson); |
|||
retstr = clonestr(laststr); |
|||
} |
|||
} else retstr = clonestr("{\"error\":\"duplicate message\"}"); |
|||
} |
|||
//else if ( strcmp(method,"nn_tests") == 0 )
|
|||
// return(clonestr("{\"result\":\"success\"}"));
|
|||
else if ( strcmp(method,"help") == 0 ) |
|||
return(clonestr("{\"result\":\" \
|
|||
available localhost RPC commands:\n \ |
|||
pricearray(base, rel, firsttime=0, lasttime=-1, timescale=60) -> [timestamp, avebid, aveask, highbid, lowask]\n\ |
|||
setprice(base, rel, price)\n\ |
|||
autoprice(base, rel, price, margin, type)\n\ |
|||
goal(coin=*, val=<autocalc>)\n\ |
|||
myprice(base, rel)\n\ |
|||
enable(coin)\n\ |
|||
disable(coin)\n\ |
|||
inventory(coin)\n\ |
|||
bestfit(rel, relvolume)\n\ |
|||
ordermatch(base, txfee=0, rel, desttxfee=0, price, relvolume=0, txid, vout, feetxid, feevout, duration=3600)\n\ |
|||
trade(price, timeout=10, duration=3600, <quotejson returned from ordermatch>)\n\ |
|||
autotrade(base, rel, price, relvolume, timeout=10, duration=3600)\n\ |
|||
swapstatus()\n\ |
|||
swapstatus(requestid, quoteid)\n\ |
|||
public API:\n \ |
|||
getcoins()\n\ |
|||
getcoin(coin)\n\ |
|||
portfolio()\n\ |
|||
getpeers()\n\ |
|||
getutxos()\n\ |
|||
getutxos(coin, lastn)\n\ |
|||
orderbook(base, rel, duration=3600)\n\ |
|||
getprices(base, rel)\n\ |
|||
sendmessage(base=coin, rel="", pubkey=zero, <argjson method2>)\n\ |
|||
getmessages(firsti=0, num=100)\n\ |
|||
clearmessages(firsti=0, num=100)\n\ |
|||
snapshot(coin, height)\n\ |
|||
dividends(coin, height, <args>)\n\ |
|||
\"}")); |
|||
|
|||
base = jstr(argjson,"base"); |
|||
rel = jstr(argjson,"rel"); |
|||
if ( USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 ) |
|||
{ |
|||
if ( USERPASS_COUNTER == 0 ) |
|||
{ |
|||
USERPASS_COUNTER = 1; |
|||
retjson = cJSON_CreateObject(); |
|||
jaddstr(retjson,"userpass",USERPASS); |
|||
jaddbits256(retjson,"mypubkey",LP_mypub25519); |
|||
jadd(retjson,"coins",LP_coinsjson(LP_showwif)); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
if ( (userpass= jstr(argjson,"userpass")) == 0 || strcmp(userpass,USERPASS) != 0 ) |
|||
return(clonestr("{\"error\":\"authentication error\"}")); |
|||
jdelete(argjson,"userpass"); |
|||
if ( strcmp(method,"sendmessage") == 0 ) |
|||
{ |
|||
if ( jobj(argjson,"method2") == 0 ) |
|||
{ |
|||
printf("broadcast message\n"); |
|||
LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,jbits256(argjson,"pubkey"),jprint(argjson,0)); |
|||
} |
|||
return(clonestr("{\"result\":\"success\"}")); |
|||
} |
|||
else if ( strcmp(method,"getmessages") == 0 ) |
|||
{ |
|||
if ( (retjson= LP_getmessages(jint(argjson,"firsti"),jint(argjson,"num"))) != 0 ) |
|||
return(jprint(retjson,1)); |
|||
else return(clonestr("{\"error\":\"null messages\"}")); |
|||
} |
|||
else if ( strcmp(method,"deletemessages") == 0 ) |
|||
{ |
|||
LP_deletemessages(jint(argjson,"firsti"),jint(argjson,"num")); |
|||
return(clonestr("{\"result\":\"success\"}")); |
|||
} |
|||
else if ( strcmp(method,"portfolio") == 0 ) |
|||
{ |
|||
return(LP_portfolio()); |
|||
} |
|||
if ( base != 0 && rel != 0 ) |
|||
{ |
|||
double price,bid,ask; |
|||
if ( IAMLP == 0 && LP_isdisabled(base,rel) != 0 ) |
|||
return(clonestr("{\"error\":\"at least one of coins disabled\"}")); |
|||
price = jdouble(argjson,"price"); |
|||
if ( strcmp(method,"setprice") == 0 ) |
|||
{ |
|||
if ( price > SMALLVAL ) |
|||
{ |
|||
if ( LP_mypriceset(&changed,base,rel,price) < 0 ) |
|||
return(clonestr("{\"error\":\"couldnt set price\"}")); |
|||
//else if ( LP_mypriceset(&changed,rel,base,1./price) < 0 )
|
|||
// return(clonestr("{\"error\":\"couldnt set price\"}"));
|
|||
else return(LP_pricepings(ctx,myipaddr,LP_mypubsock,base,rel,price * LP_profitratio)); |
|||
} else return(clonestr("{\"error\":\"no price\"}")); |
|||
} |
|||
else if ( strcmp(method,"autoprice") == 0 ) |
|||
{ |
|||
if ( LP_autoprice(base,rel,price,jdouble(argjson,"margin"),jstr(argjson,"type")) < 0 ) |
|||
return(clonestr("{\"error\":\"couldnt set autoprice\"}")); |
|||
else return(clonestr("{\"result\":\"success\"}")); |
|||
} |
|||
else if ( strcmp(method,"pricearray") == 0 ) |
|||
{ |
|||
return(jprint(LP_pricearray(base,rel,juint(argjson,"firsttime"),juint(argjson,"lasttime"),jint(argjson,"timescale")),1)); |
|||
} |
|||
else if ( strcmp(method,"myprice") == 0 ) |
|||
{ |
|||
if ( LP_myprice(&bid,&ask,base,rel) > SMALLVAL ) |
|||
{ |
|||
retjson = cJSON_CreateObject(); |
|||
jaddstr(retjson,"base",base); |
|||
jaddstr(retjson,"rel",rel); |
|||
jaddnum(retjson,"bid",bid); |
|||
jaddnum(retjson,"ask",ask); |
|||
return(jprint(retjson,1)); |
|||
} else return(clonestr("{\"error\":\"no price set\"}")); |
|||
} |
|||
else if ( strcmp(method,"ordermatch") == 0 ) |
|||
{ |
|||
if ( price > SMALLVAL ) |
|||
return(LP_ordermatch(base,j64bits(argjson,"txfee"),price,jdouble(argjson,"relvolume"),rel,jbits256(argjson,"txid"),jint(argjson,"vout"),jbits256(argjson,"feetxid"),jint(argjson,"feevout"),j64bits(argjson,"desttxfee"),jint(argjson,"duration"))); |
|||
else return(clonestr("{\"error\":\"no price set\"}")); |
|||
} |
|||
else if ( strcmp(method,"trade") == 0 ) |
|||
{ |
|||
struct LP_quoteinfo Q; |
|||
if ( price > SMALLVAL || jobj(argjson,"quote") != 0 ) |
|||
{ |
|||
LP_quoteparse(&Q,jobj(argjson,"quote")); |
|||
return(LP_trade(ctx,myipaddr,pubsock,&Q,price,jint(argjson,"timeout"),jint(argjson,"duration"))); |
|||
} else return(clonestr("{\"error\":\"no price set or no quote object\"}")); |
|||
} |
|||
else if ( strcmp(method,"autotrade") == 0 ) |
|||
{ |
|||
if ( price > SMALLVAL ) |
|||
{ |
|||
return(LP_autotrade(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration"))); |
|||
} else return(clonestr("{\"error\":\"no price set\"}")); |
|||
} |
|||
} |
|||
else if ( rel != 0 && strcmp(method,"bestfit") == 0 ) |
|||
{ |
|||
double relvolume; |
|||
if ( (relvolume= jdouble(argjson,"relvolume")) > SMALLVAL ) |
|||
return(LP_bestfit(rel,relvolume)); |
|||
else return(clonestr("{\"error\":\"no relvolume set\"}")); |
|||
} |
|||
else if ( (coin= jstr(argjson,"coin")) != 0 ) |
|||
{ |
|||
if ( strcmp(method,"enable") == 0 ) |
|||
{ |
|||
if ( (ptr= LP_coinsearch(coin)) != 0 ) |
|||
ptr->inactive = 0; |
|||
return(jprint(LP_coinsjson(0),1)); |
|||
} |
|||
else if ( strcmp(method,"disable") == 0 ) |
|||
{ |
|||
if ( (ptr= LP_coinsearch(coin)) != 0 ) |
|||
ptr->inactive = (uint32_t)time(NULL); |
|||
return(jprint(LP_coinsjson(0),1)); |
|||
} |
|||
else if ( strcmp(method,"snapshot") == 0 ) |
|||
{ |
|||
if ( (ptr= LP_coinsearch(coin)) != 0 ) |
|||
return(jprint(LP_snapshot(ptr,juint(argjson,"height")),1)); |
|||
else return(clonestr("{\"error\":\"cant find coind\"}")); |
|||
} |
|||
else if ( strcmp(method,"dividends") == 0 ) |
|||
{ |
|||
if ( (ptr= LP_coinsearch(coin)) != 0 ) |
|||
return(LP_dividends(ptr,juint(argjson,"height"),argjson)); |
|||
else return(clonestr("{\"error\":\"cant find coind\"}")); |
|||
} |
|||
if ( LP_isdisabled(coin,0) != 0 ) |
|||
return(clonestr("{\"error\":\"coin is disabled\"}")); |
|||
if ( strcmp(method,"inventory") == 0 ) |
|||
{ |
|||
struct iguana_info *ptr; |
|||
if ( (ptr= LP_coinfind(coin)) != 0 ) |
|||
{ |
|||
//privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,ptr,"",USERPASS_WIFSTR);
|
|||
//LP_utxopurge(0);
|
|||
if ( bits256_nonz(LP_mypriv25519) != 0 ) |
|||
LP_privkey_init(-1,ptr,LP_mypriv25519,LP_mypub25519); |
|||
retjson = cJSON_CreateObject(); |
|||
jaddstr(retjson,"result","success"); |
|||
jaddstr(retjson,"coin",coin); |
|||
jaddnum(retjson,"timestamp",time(NULL)); |
|||
jadd(retjson,"alice",LP_inventory(coin,0)); |
|||
jadd(retjson,"bob",LP_inventory(coin,1)); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
} |
|||
else if ( strcmp(method,"goal") == 0 ) |
|||
return(LP_portfolio_goal(coin,jdouble(argjson,"val"))); |
|||
else if ( strcmp(method,"getcoin") == 0 ) |
|||
return(LP_getcoin(coin)); |
|||
} |
|||
else if ( strcmp(method,"goal") == 0 ) |
|||
return(LP_portfolio_goal("*",100.)); |
|||
else if ( strcmp(method,"swapstatus") == 0 ) |
|||
{ |
|||
uint32_t requestid,quoteid; |
|||
if ( (requestid= juint(argjson,"requestid")) != 0 && (quoteid= juint(argjson,"quoteid")) != 0 ) |
|||
return(basilisk_swapentry(requestid,quoteid)); |
|||
else return(basilisk_swaplist()); |
|||
} |
|||
else if ( strcmp(method,"myprices") == 0 ) |
|||
return(LP_myprices()); |
|||
else if ( strcmp(method,"trust") == 0 ) |
|||
return(LP_pubkey_trustset(jbits256(argjson,"pubkey"),jint(argjson,"trust"))); |
|||
} |
|||
if ( IAMLP == 0 ) |
|||
{ |
|||
if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 ) |
|||
{ |
|||
if ( jobj(reqjson,"method2") != 0 ) |
|||
{ |
|||
jdelete(reqjson,"method"); |
|||
method = jstr(reqjson,"method2"); |
|||
jaddstr(reqjson,"method",method); |
|||
} |
|||
argjson = reqjson; |
|||
} |
|||
} |
|||
if ( IAMLP == 0 && LP_isdisabled(base,rel) != 0 ) |
|||
return(clonestr("{\"result\":\"at least one of coins disabled\"}")); |
|||
else if ( IAMLP == 0 && LP_isdisabled(jstr(argjson,"coin"),0) != 0 ) |
|||
retstr = clonestr("{\"result\":\"coin is disabled\"}"); |
|||
else if ( strcmp(method,"reserved") == 0 ) |
|||
retstr = LP_quotereceived(argjson); |
|||
else if ( strcmp(method,"connected") == 0 ) |
|||
retstr = LP_connectedalice(argjson); |
|||
else if ( strcmp(method,"checktxid") == 0 ) |
|||
retstr = LP_spentcheck(argjson); |
|||
else if ( strcmp(method,"getcoins") == 0 ) |
|||
return(jprint(LP_coinsjson(0),1)); |
|||
else if ( strcmp(method,"numutxos") == 0 ) |
|||
return(LP_numutxos()); |
|||
else if ( strcmp(method,"postprice") == 0 ) |
|||
retstr = LP_postedprice(argjson); |
|||
else if ( strcmp(method,"encrypted") == 0 ) |
|||
retstr = clonestr("{\"result\":\"success\"}"); |
|||
else if ( strcmp(method,"getprices") == 0 ) |
|||
return(LP_prices()); |
|||
else if ( strcmp(method,"orderbook") == 0 ) |
|||
return(LP_orderbook(base,rel,jint(argjson,"duration"))); |
|||
else if ( strcmp(method,"registerall") == 0 ) |
|||
return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); |
|||
else if ( strcmp(method,"forward") == 0 ) |
|||
return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); |
|||
else if ( strcmp(method,"keepalive") == 0 ) |
|||
return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); |
|||
else if ( strcmp(method,"getpeers") == 0 ) |
|||
return(LP_peers()); |
|||
else if ( strcmp(method,"getutxos") == 0 ) |
|||
return(LP_utxos(1,LP_mypeer,jstr(argjson,"coin"),jint(argjson,"lastn"))); |
|||
else if ( strcmp(method,"utxo") == 0 ) |
|||
{ |
|||
if ( LP_utxoaddjson(1,LP_mypubsock,argjson) != 0 ) |
|||
retstr = clonestr("{\"result\":\"success\",\"utxo\":\"received\"}"); |
|||
else retstr = clonestr("{\"result\":\"couldnt add utxo\"}"); |
|||
} |
|||
else |
|||
{ |
|||
if ( IAMLP != 0 ) |
|||
{ |
|||
if ( strcmp(method,"register") == 0 ) |
|||
return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); |
|||
else if ( strcmp(method,"lookup") == 0 ) |
|||
return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); |
|||
if ( strcmp(method,"broadcast") == 0 ) |
|||
{ |
|||
bits256 zero; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE]; |
|||
if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 ) |
|||
{ |
|||
if ( (cipherstr= jstr(reqjson,"cipher")) != 0 ) |
|||
{ |
|||
cipherlen = (int32_t)strlen(cipherstr) >> 1; |
|||
if ( cipherlen <= sizeof(cipher) ) |
|||
{ |
|||
decode_hex(cipher,cipherlen,cipherstr); |
|||
LP_queuesend(calc_crc32(0,&cipher[2],cipherlen-2),LP_mypubsock,base,rel,cipher,cipherlen); |
|||
} else retstr = clonestr("{\"error\":\"cipher too big\"}"); |
|||
} |
|||
else |
|||
{ |
|||
memset(zero.bytes,0,sizeof(zero)); |
|||
LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); |
|||
} |
|||
retstr = clonestr("{\"result\":\"success\"}"); |
|||
} else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); |
|||
} |
|||
else if ( strcmp(method,"psock") == 0 ) |
|||
{ |
|||
if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 ) |
|||
{ |
|||
if ( LP_mypeer != 0 ) |
|||
myipaddr = LP_mypeer->ipaddr; |
|||
else printf("LP_psock dont have actual ipaddr?\n"); |
|||
} |
|||
if ( jint(argjson,"ispaired") != 0 ) |
|||
return(LP_psock(myipaddr,jint(argjson,"ispaired"))); |
|||
else return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); |
|||
} |
|||
else if ( strcmp(method,"notify") == 0 ) |
|||
retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}"); |
|||
} |
|||
else |
|||
{ |
|||
if ( strcmp(method,"psock") == 0 ) |
|||
{ |
|||
//printf("nonLP got (%s)\n",jprint(argjson,0));
|
|||
retstr = clonestr("{\"result\":\"success\"}"); |
|||
} |
|||
} |
|||
} |
|||
if ( retstr == 0 ) |
|||
printf("ERROR.(%s)\n",jprint(argjson,0)); |
|||
if ( reqjson != 0 ) |
|||
free_json(reqjson); |
|||
if ( retstr != 0 ) |
|||
{ |
|||
free(retstr); |
|||
return(0); |
|||
} |
|||
return(0); |
|||
} |
@ -0,0 +1,351 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_forwarding.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
cJSON *LP_dereference(cJSON *argjson,char *excludemethod) |
|||
{ |
|||
cJSON *reqjson = 0; |
|||
if ( jstr(argjson,"method2") != 0 && strncmp(excludemethod,jstr(argjson,"method2"),strlen(excludemethod)) != 0 ) |
|||
{ |
|||
reqjson = jduplicate(argjson); |
|||
jdelete(reqjson,"method"); |
|||
jaddstr(reqjson,"method",jstr(argjson,"method2")); |
|||
} |
|||
return(reqjson); |
|||
} |
|||
|
|||
/*
|
|||
struct LP_forwardinfo |
|||
{ |
|||
UT_hash_handle hh; |
|||
bits256 pubkey; |
|||
char pushaddr[64]; |
|||
int32_t pushsock; |
|||
uint32_t lasttime,hello; |
|||
} *LP_forwardinfos; |
|||
#define LP_KEEPALIVE (3600 * 24) |
|||
|
|||
struct LP_forwardinfo *LP_forwardfind(bits256 pubkey) |
|||
{ |
|||
struct LP_forwardinfo *ptr=0; |
|||
portable_mutex_lock(&LP_forwardmutex); |
|||
HASH_FIND(hh,LP_forwardinfos,&pubkey,sizeof(pubkey),ptr); |
|||
portable_mutex_unlock(&LP_forwardmutex); |
|||
if ( ptr != 0 && ptr->lasttime > time(NULL)-LP_KEEPALIVE ) |
|||
return(ptr); |
|||
else return(0); |
|||
} |
|||
|
|||
char *LP_lookup(bits256 pubkey) |
|||
{ |
|||
if ( bits256_nonz(pubkey) == 0 ) |
|||
return(clonestr("{\"result\":\"illegal pubkey\"}")); |
|||
if ( LP_forwardfind(pubkey) != 0 ) |
|||
return(clonestr("{\"result\":\"success\",\"forwarding\":1}")); |
|||
else return(clonestr("{\"result\":\"notfound\"}")); |
|||
} |
|||
|
|||
int32_t LP_hello(struct LP_forwardinfo *ptr) |
|||
{ |
|||
int32_t i,n=10; char msg[512]; struct nn_pollfd pfd; |
|||
if ( bits256_cmp(ptr->pubkey,LP_mypubkey) != 0 ) |
|||
{ |
|||
pfd.fd = ptr->pushsock; |
|||
pfd.events = NN_POLLOUT; |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
if ( nn_poll(&pfd,1,1) > 0 ) |
|||
{ |
|||
sprintf(msg,"{\"method\":\"hello\",\"from\":\"%s\"}",LP_mypeer != 0 ? LP_mypeer->ipaddr : ""); |
|||
//printf("HELLO sent.%d bytes to %s on i.%d\n",LP_send(ptr->pushsock,msg,0),ptr->pushaddr,i);
|
|||
ptr->hello = (uint32_t)time(NULL); |
|||
return(i); |
|||
} |
|||
} |
|||
//printf("%d iterations on nn_poll and %s pushsock still not ready\n",i,ptr->pushaddr);
|
|||
return(-1); |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
int32_t LP_hellos() |
|||
{ |
|||
struct LP_forwardinfo *ptr,*tmp; int32_t nonz = 0; |
|||
HASH_ITER(hh,LP_forwardinfos,ptr,tmp) |
|||
{ |
|||
if ( ptr->hello == 0 && LP_hello(ptr) >= 0 ) |
|||
nonz++; |
|||
} |
|||
return(nonz); |
|||
} |
|||
|
|||
int32_t LP_pushsock_create(struct LP_forwardinfo *ptr,char *pushaddr) |
|||
{ |
|||
int32_t pushsock,timeout; |
|||
if ( (pushsock= nn_socket(AF_SP,LP_COMMAND_SENDSOCK)) < 0 ) |
|||
{ |
|||
printf("LP_pushsock_create couldnt allocate socket for %s\n",pushaddr); |
|||
return(-1); |
|||
} |
|||
else if ( nn_connect(pushsock,pushaddr) < 0 ) |
|||
{ |
|||
nn_close(pushsock); |
|||
printf("LP_pushsock_create couldnt connect to %s\n",pushaddr); |
|||
return(-1); |
|||
} |
|||
timeout = 1; |
|||
nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); |
|||
nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); |
|||
if ( ptr != 0 ) |
|||
LP_hello(ptr); |
|||
return(pushsock); |
|||
} |
|||
|
|||
char *LP_register(bits256 pubkey,char *ipaddr,uint16_t port) |
|||
{ |
|||
struct LP_forwardinfo *ptr=0; int32_t pushsock; char pushaddr[64]; |
|||
if ( ipaddr == 0 || ipaddr[0] == 0 || is_ipaddr(ipaddr) == 0 || bits256_nonz(pubkey) == 0 ) |
|||
return(clonestr("{\"result\":\"illegal ipaddr or null pubkey\"}")); |
|||
nanomsg_transportname(0,pushaddr,ipaddr,port); |
|||
//char str[65]; printf("register.(%s) %s\n",pushaddr,bits256_str(str,pubkey));
|
|||
if ( (ptr= LP_forwardfind(pubkey)) != 0 ) |
|||
{ |
|||
ptr->lasttime = (uint32_t)time(NULL); |
|||
if ( ptr->pushsock >= 0 ) |
|||
{ |
|||
if ( strcmp(pushaddr,ptr->pushaddr) != 0 ) |
|||
{ |
|||
nn_close(ptr->pushsock); |
|||
if ( LP_psockmark(ptr->pushaddr) < 0 ) |
|||
{ |
|||
//printf("cant mark (%s)\n",ptr->pushaddr);
|
|||
} |
|||
char str[65]; printf("%u recreate pushsock for %s <- %s %s\n",(uint32_t)time(NULL),ptr->pushaddr,pushaddr,bits256_str(str,pubkey)); |
|||
strcpy(ptr->pushaddr,pushaddr); |
|||
if ( (ptr->pushsock= LP_pushsock_create(ptr,pushaddr)) < 0 ) |
|||
return(clonestr("{\"result\":\"success\",\"status\":\"couldnt recreate pushsock\",\"registered\":0}")); |
|||
} //else printf("no need to create identical endpoint\n");
|
|||
} |
|||
return(clonestr("{\"result\":\"success\",\"status\":\"already registered\",\"registered\":1}")); |
|||
} |
|||
else if ( (pushsock= LP_pushsock_create(0,pushaddr)) < 0 ) |
|||
return(clonestr("{\"result\":\"success\",\"status\":\"couldnt create pushsock\"}")); |
|||
else |
|||
{ |
|||
ptr = calloc(1,sizeof(*ptr)); |
|||
ptr->pubkey = pubkey; |
|||
strcpy(ptr->pushaddr,pushaddr); |
|||
ptr->pushsock = pushsock; |
|||
ptr->lasttime = (uint32_t)time(NULL); |
|||
portable_mutex_lock(&LP_forwardmutex); |
|||
HASH_ADD_KEYPTR(hh,LP_forwardinfos,&ptr->pubkey,sizeof(ptr->pubkey),ptr); |
|||
portable_mutex_unlock(&LP_forwardmutex); |
|||
//char str[65]; printf("registered (%s) -> (%s) pushsock.%d\n",bits256_str(str,pubkey),pushaddr,ptr->pushsock);
|
|||
LP_hello(ptr); |
|||
return(LP_lookup(pubkey)); |
|||
} |
|||
} |
|||
|
|||
int32_t LP_forwarding_register(bits256 pubkey,char *publicaddr,uint16_t publicport,int32_t max) |
|||
{ |
|||
char *argstr,ipaddr[64]; cJSON *argjson; struct LP_peerinfo *peer,*tmp; int32_t j,n=0,arglen; |
|||
if ( publicaddr == 0 || publicaddr[0] == 0 || bits256_nonz(pubkey) == 0 ) |
|||
{ |
|||
char str[65]; printf("LP_forwarding_register illegal publicaddr.(%s):%u or null pubkey (%s)\n",publicaddr,publicport,bits256_str(str,pubkey)); |
|||
return(0); |
|||
} |
|||
for (j=0; publicaddr[j]!=0; j++) |
|||
if ( publicaddr[j] >= '0' && publicaddr[j] <= '9' ) |
|||
break; |
|||
parse_ipaddr(ipaddr,publicaddr+j); |
|||
argjson = cJSON_CreateObject(); |
|||
jaddstr(argjson,"agent","stats"); |
|||
jaddstr(argjson,"method","register"); |
|||
jaddbits256(argjson,"client",pubkey); |
|||
jaddstr(argjson,"pushaddr",ipaddr); |
|||
jaddnum(argjson,"pushport",publicport); |
|||
argstr = jprint(argjson,1); |
|||
arglen = (int32_t)strlen(argstr) + 1; |
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
if ( strcmp(LP_myipaddr,peer->ipaddr) == 0 ) |
|||
continue; |
|||
if ( peer->pushsock >= 0 ) |
|||
{ |
|||
if ( LP_send(peer->pushsock,argstr,arglen,0) != arglen ) |
|||
{ |
|||
if ( strncmp(peer->ipaddr,"5.9.253",strlen("5.9.253")) == 0 ) |
|||
printf("error registering with %s:%u\n",peer->ipaddr,peer->port); |
|||
} |
|||
n++; |
|||
} |
|||
//printf("register.(%s) %s %u with (%s)\n",publicaddr,ipaddr,publicport,peer->ipaddr);
|
|||
} |
|||
free(argstr); |
|||
return(n); |
|||
} |
|||
|
|||
char *LP_registerall(int32_t numnodes) |
|||
{ |
|||
int32_t i,maxnodes,n=0; cJSON *retjson; |
|||
if ( numnodes < sizeof(default_LPnodes)/sizeof(*default_LPnodes) ) |
|||
numnodes = (int32_t)(sizeof(default_LPnodes)/sizeof(*default_LPnodes)); |
|||
if ( (maxnodes= LP_numpeers()) < numnodes ) |
|||
numnodes = maxnodes; |
|||
for (i=0; i<numnodes; i++) |
|||
if ( (n= LP_forwarding_register(LP_mypubkey,LP_publicaddr,LP_publicport,numnodes)) >= numnodes ) |
|||
break; |
|||
retjson = cJSON_CreateObject(); |
|||
if ( i == numnodes ) |
|||
jaddstr(retjson,"error","not enough nodes"); |
|||
jaddnum(retjson,"numnodes",numnodes); |
|||
jaddnum(retjson,"registered",n); |
|||
jaddnum(retjson,"iters",i); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
|
|||
char *LP_forwardhex(void *ctx,int32_t pubsock,bits256 pubkey,char *hexstr) |
|||
{ |
|||
struct LP_forwardinfo *ptr=0; uint8_t *data; int32_t datalen=0,sentbytes=0; char *msg,*retstr=0; cJSON *retjson=0,*argjson=0,*reqjson=0; |
|||
if ( hexstr == 0 || hexstr[0] == 0 ) |
|||
return(clonestr("{\"result\":\"nohex\"}")); |
|||
datalen = (int32_t)strlen(hexstr) >> 1; |
|||
data = malloc(datalen); |
|||
decode_hex(data,datalen,hexstr); |
|||
if ( (argjson= cJSON_Parse((char *)data)) != 0 ) |
|||
reqjson = LP_dereference(argjson,"forward"); |
|||
if ( bits256_nonz(pubkey) == 0 || bits256_cmp(pubkey,LP_mypubkey) == 0 ) |
|||
{ |
|||
if ( reqjson != 0 ) |
|||
{ |
|||
retstr = LP_command_process(ctx,LP_mypeer != 0 ? LP_mypeer->ipaddr : "127.0.0.1",LP_mypubsock,reqjson,0,0,LP_profitratio - 1.); |
|||
//printf("LP_forwardhex.(%s) -> (%s)\n",jprint(reqjson,0),retstr!=0?retstr:"");
|
|||
if ( pubsock >= 0 ) |
|||
{ |
|||
msg = jprint(reqjson,0); |
|||
LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); |
|||
} |
|||
} else printf("LP_forwardhex couldnt parse (%s)\n",(char *)data); |
|||
} |
|||
else if ( (ptr= LP_forwardfind(pubkey)) != 0 ) |
|||
{ |
|||
if ( ptr->pushsock >= 0 ) |
|||
{ |
|||
printf("%s forwardhex.(%s)\n",ptr->pushaddr,(char *)data); |
|||
sentbytes = LP_send(ptr->pushsock,(char *)data,datalen,0); |
|||
} |
|||
retjson = cJSON_CreateObject(); |
|||
if ( sentbytes >= 0 ) |
|||
{ |
|||
jaddstr(retjson,"result","success"); |
|||
if ( sentbytes == datalen ) |
|||
jaddnum(retjson,"forwarded",sentbytes); |
|||
else if ( sentbytes == 0 ) |
|||
jaddnum(retjson,"queued",sentbytes); |
|||
else jaddnum(retjson,"mismatch",sentbytes); |
|||
retstr = jprint(retjson,1); |
|||
} |
|||
else |
|||
{ |
|||
jaddstr(retjson,"error","send error"); |
|||
jaddnum(retjson,"sentbytes",sentbytes); |
|||
jaddnum(retjson,"datalen",datalen); |
|||
jaddnum(retjson,"hello",ptr->hello); |
|||
retstr = jprint(retjson,1); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
char str[65]; printf("couldnt find %s to forward to\n",bits256_str(str,pubkey)); |
|||
if ( pubsock >= 0 ) |
|||
{ |
|||
msg = jprint(reqjson,0); |
|||
LP_send(pubsock,msg,(int32_t)strlen(msg)+1,1); |
|||
} |
|||
retstr = clonestr("{\"result\":\"notfound\"}"); |
|||
} |
|||
free(data); |
|||
if ( reqjson != 0 ) |
|||
free_json(reqjson); |
|||
if ( argjson != 0 ) |
|||
free_json(argjson); |
|||
return(retstr); |
|||
} |
|||
|
|||
int32_t LP_forward(void *ctx,char *myipaddr,int32_t pubsock,bits256 pubkey,char *jsonstr,int32_t freeflag) |
|||
{ |
|||
struct LP_forwardinfo *ptr; struct LP_peerinfo *peer,*tmp; char *msg,*hexstr,*retstr; int32_t len,n=0,mlen; cJSON *reqjson,*argjson; |
|||
if ( jsonstr == 0 || jsonstr[0] == 0 ) |
|||
return(-1); |
|||
len = (int32_t)strlen(jsonstr) + 1; |
|||
if ( bits256_nonz(pubkey) != 0 ) |
|||
{ |
|||
if ( bits256_cmp(pubkey,LP_mypubkey) == 0 ) |
|||
{ |
|||
printf("GOT FORWARDED.(%s)\n",myipaddr); |
|||
if ( (argjson= cJSON_Parse(jsonstr)) != 0 ) |
|||
{ |
|||
if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,0,0)) != 0 ) |
|||
free(retstr); |
|||
free_json(argjson); |
|||
} |
|||
if ( freeflag != 0 ) |
|||
free(jsonstr); |
|||
return(1); |
|||
} |
|||
else if ( IAMLP != 0 && (ptr= LP_forwardfind(pubkey)) != 0 && ptr->pushsock >= 0 ) |
|||
{ |
|||
printf("GOT FORWARDED.(%s) -> pushsock.%d\n",jsonstr,ptr->pushsock); |
|||
if ( LP_send(ptr->pushsock,jsonstr,len,freeflag) == len ) |
|||
return(1); |
|||
} |
|||
} |
|||
hexstr = malloc(len*2 + 1); |
|||
init_hexbytes_noT(hexstr,(uint8_t *)jsonstr,len); |
|||
if ( freeflag != 0 ) |
|||
free(jsonstr); |
|||
reqjson = cJSON_CreateObject(); |
|||
jaddstr(reqjson,"method","forwardhex"); |
|||
jaddstr(reqjson,"hex",hexstr); |
|||
free(hexstr); |
|||
msg = jprint(reqjson,1); |
|||
mlen = (int32_t)strlen(msg) + 1; |
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
//printf("found LPnode.(%s) forward.(%s)\n",peer->ipaddr,msg);
|
|||
if ( LP_send(peer->pushsock,msg,mlen,0) == mlen ) |
|||
n++; |
|||
if ( n >= 8 )//sizeof(default_LPnodes)/sizeof(*default_LPnodes) )
|
|||
break; |
|||
} |
|||
if ( msg != 0 ) |
|||
free(msg); |
|||
if ( n == 0 ) |
|||
return(-1); |
|||
else return(n-1); |
|||
} |
|||
|
|||
|
|||
char *LP_broadcasted(cJSON *argjson) |
|||
{ |
|||
printf("RECV BROADCAST.(%s)\n",jprint(argjson,0)); |
|||
return(clonestr("{\"result\":\"need to update broadcast messages\"}")); |
|||
} |
|||
*/ |
|||
|
@ -0,0 +1,289 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_include.h
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
#ifndef LP_INCLUDE_H |
|||
#define LP_INCLUDE_H |
|||
|
|||
//#define LP_STRICTPEERS
|
|||
|
|||
#define LP_COMMAND_SENDSOCK NN_PUSH |
|||
#define LP_COMMAND_RECVSOCK NN_PULL |
|||
|
|||
#define LP_ENCRYPTED_MAXSIZE (4096 + 2 + crypto_box_NONCEBYTES + crypto_box_ZEROBYTES) |
|||
|
|||
#define LP_MAXPUBKEY_ERRORS 3 |
|||
#define PSOCK_KEEPALIVE 3600 |
|||
#define MAINLOOP_PERSEC 100 |
|||
#define MAX_PSOCK_PORT 60000 |
|||
#define MIN_PSOCK_PORT 10000 |
|||
#define LP_MEMPOOL_TIMEINCR 10 |
|||
#define LP_GETINFO_INCR 30 |
|||
#define LP_ORDERBOOK_DURATION 3600 |
|||
|
|||
#define LP_HTTP_TIMEOUT 2 // 1 is too small due to edge cases of time(NULL)
|
|||
#define LP_MAXPEER_ERRORS 3 |
|||
#define LP_MINPEER_GOOD 20 |
|||
#define LP_PEERGOOD_ERRORDECAY 0.9 |
|||
|
|||
#define LP_SWAPSTEP_TIMEOUT 30 |
|||
#define LP_AUTOTRADE_TIMEOUT 60 |
|||
#define LP_MIN_TXFEE 10000 |
|||
#define LP_MINVOL 10 |
|||
#define LP_MINCLIENTVOL 20 |
|||
#define LP_MINSIZE_TXFEEMULT 10 |
|||
#define LP_REQUIRED_TXFEE 0.95 |
|||
|
|||
#define LP_DEXFEE(destsatoshis) ((destsatoshis) / INSTANTDEX_INSURANCEDIV) |
|||
#define LP_DEPOSITSATOSHIS(satoshis) ((satoshis) + (satoshis >> 3)) |
|||
|
|||
#define INSTANTDEX_DECKSIZE 1000 |
|||
#define INSTANTDEX_LOCKTIME (3600*2 + 300*2) |
|||
#define INSTANTDEX_INSURANCEDIV 777 |
|||
#define INSTANTDEX_PUBKEY "03bc2c7ba671bae4a6fc835244c9762b41647b9827d4780a89a949b984a8ddcc06" |
|||
#define INSTANTDEX_RMD160 "ca1e04745e8ca0c60d8c5881531d51bec470743f" |
|||
#define JUMBLR_RMD160 "5177f8b427e5f47342a4b8ab5dac770815d4389e" |
|||
#define TIERNOLAN_RMD160 "daedddd8dbe7a2439841ced40ba9c3d375f98146" |
|||
#define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu" |
|||
#define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" |
|||
|
|||
//#define BASILISK_DISABLEWAITTX
|
|||
//#define BASILISK_DISABLESENDTX
|
|||
|
|||
#define LP_PROPAGATION_SLACK 100 // txid ordering is not enforced, so getting extra recent txid
|
|||
#define LP_RESERVETIME 60 |
|||
#define LP_AVETXSIZE 256 |
|||
#define LP_CACHEDURATION 60 |
|||
#define BASILISK_DEFAULT_NUMCONFIRMS 1 |
|||
#define DEX_SLEEP 3 |
|||
#define BASILISK_KEYSIZE ((int32_t)(2*sizeof(bits256)+sizeof(uint32_t)*2)) |
|||
|
|||
extern char GLOBAL_DBDIR[],USERPASS[],USERPASS_WIFSTR[]; |
|||
extern int32_t IAMLP,USERPASS_COUNTER; |
|||
|
|||
struct iguana_msgvin { bits256 prev_hash; uint8_t *vinscript,*userdata,*spendscript,*redeemscript; uint32_t prev_vout,sequence; uint16_t scriptlen,p2shlen,userdatalen,spendlen; }; |
|||
|
|||
struct iguana_msgvout { uint64_t value; uint32_t pk_scriptlen; uint8_t *pk_script; }; |
|||
|
|||
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,numinputs,numoutputs; |
|||
int64_t inputsum,outputsum,txfee; |
|||
uint8_t *serialized; |
|||
}; |
|||
|
|||
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,numpubkeys,numsigs,height,hashtype,userdatalen,suppress_pubkeys,ignore_cltverr; |
|||
uint32_t sequence,unspentind; struct vin_signer signers[16]; char coinaddr[65]; |
|||
uint8_t rmd160[20],spendscript[10000],p2shscript[10000],userdata[10000]; |
|||
}; |
|||
|
|||
struct basilisk_swapmessage |
|||
{ |
|||
bits256 srchash,desthash; |
|||
uint32_t crc32,msgbits,quoteid,datalen; |
|||
uint8_t *data; |
|||
}; |
|||
|
|||
struct basilisk_swap; |
|||
|
|||
struct basilisk_rawtxinfo |
|||
{ |
|||
char destaddr[64],coinstr[16]; |
|||
bits256 txid,signedtxid,actualtxid; |
|||
uint64_t amount,change,inputsum; |
|||
int32_t redeemlen,datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys; |
|||
uint32_t locktime,crcs[2]; |
|||
uint8_t addrtype,pubkey33[33],rmd160[20]; |
|||
}; |
|||
|
|||
struct basilisk_request |
|||
{ |
|||
uint32_t requestid,timestamp,quoteid,quotetime; // 0 to 15
|
|||
uint64_t srcamount,unused; // 16 to 31
|
|||
bits256 srchash; // 32 to 63
|
|||
bits256 desthash; |
|||
char src[8],dest[8]; |
|||
uint64_t destamount; |
|||
int32_t optionhours,DEXselector; |
|||
}; |
|||
|
|||
struct basilisk_rawtx |
|||
{ |
|||
char name[32]; |
|||
struct iguana_msgtx msgtx; |
|||
struct basilisk_rawtxinfo I; |
|||
struct iguana_info *coin; |
|||
char vinstr[8192],p2shaddr[64]; |
|||
cJSON *vins; |
|||
bits256 utxotxid; int32_t utxovout; |
|||
uint8_t txbytes[16384],spendscript[512],redeemscript[1024],extraspace[4096],pubkey33[33]; |
|||
}; |
|||
|
|||
struct basilisk_swapinfo |
|||
{ |
|||
struct basilisk_request req; |
|||
char bobstr[64],alicestr[64]; |
|||
bits256 myhash,otherhash,orderhash; |
|||
uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,putduration,callduration; |
|||
int32_t bobconfirms,aliceconfirms,iambob,reclaimed,bobspent,alicespent,pad; |
|||
uint64_t alicesatoshis,bobsatoshis,bobinsurance,aliceinsurance,Atxfee,Btxfee; |
|||
|
|||
bits256 myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn; |
|||
uint32_t crcs_mypub[2],crcs_mychoosei[2],crcs_myprivs[2],crcs_mypriv[2]; |
|||
int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate,pad2; |
|||
uint8_t secretAm[20],secretBn[20]; |
|||
uint8_t secretAm256[32],secretBn256[32]; |
|||
uint8_t userdata_aliceclaim[256],userdata_aliceclaimlen; |
|||
uint8_t userdata_alicereclaim[256],userdata_alicereclaimlen; |
|||
uint8_t userdata_alicespend[256],userdata_alicespendlen; |
|||
uint8_t userdata_bobspend[256],userdata_bobspendlen; |
|||
uint8_t userdata_bobreclaim[256],userdata_bobreclaimlen; |
|||
uint8_t userdata_bobrefund[256],userdata_bobrefundlen; |
|||
}; |
|||
|
|||
struct LP_outpoint { bits256 spendtxid; uint64_t value,interest; int32_t spendvini,spendheight; char coinaddr[40]; }; |
|||
|
|||
struct LP_transaction |
|||
{ |
|||
UT_hash_handle hh; |
|||
bits256 txid; int32_t height,numvouts,numvins; uint32_t timestamp; |
|||
struct LP_outpoint outpoints[]; |
|||
}; |
|||
|
|||
struct LP_address |
|||
{ |
|||
UT_hash_handle hh; |
|||
int64_t balance; |
|||
char coinaddr[40]; |
|||
}; |
|||
|
|||
struct iguana_info |
|||
{ |
|||
UT_hash_handle hh; |
|||
portable_mutex_t txmutex; struct LP_transaction *transactions; struct LP_address *addresses; |
|||
uint64_t txfee; |
|||
int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock; uint16_t busport; |
|||
uint32_t counter,inactive,lastmempool,lastgetinfo; |
|||
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag; |
|||
char symbol[16],smartaddr[64],userpass[1024],serverport[128]; |
|||
// portfolio
|
|||
double price_kmd,force,perc,goal,goalperc,relvolume; |
|||
uint64_t maxamount,kmd_equiv,balanceA,balanceB,valuesumA,valuesumB; |
|||
uint8_t pubkey33[33]; |
|||
}; |
|||
|
|||
struct _LP_utxoinfo { bits256 txid; uint64_t value; int32_t vout; }; |
|||
|
|||
struct LP_utxostats { uint32_t sessionid,lasttime,errors,swappending,spentflag,lastspentcheck,bestflag; }; |
|||
|
|||
struct LP_utxobob { struct _LP_utxoinfo utxo,deposit; }; |
|||
|
|||
struct LP_utxoalice { struct _LP_utxoinfo utxo,fee; }; |
|||
|
|||
struct LP_utxoswap { bits256 otherpubkey; void *swap; uint64_t satoshis; }; |
|||
|
|||
struct LP_utxoinfo |
|||
{ |
|||
UT_hash_handle hh,hh2; |
|||
bits256 pubkey; |
|||
struct _LP_utxoinfo payment,deposit,fee; |
|||
struct LP_utxostats T; |
|||
struct LP_utxoswap S; |
|||
//struct LP_utxonetwork N;
|
|||
int32_t iambob,iamlp; |
|||
uint8_t key[sizeof(bits256) + sizeof(int32_t)]; |
|||
uint8_t key2[sizeof(bits256) + sizeof(int32_t)]; |
|||
char coin[16],coinaddr[64],spendscript[256],gui[16]; |
|||
}; |
|||
|
|||
struct LP_peerinfo |
|||
{ |
|||
UT_hash_handle hh; |
|||
uint64_t ip_port; |
|||
uint32_t ipbits,errortime,errors,numpeers,numutxos,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid; |
|||
int32_t pushsock,subsock; |
|||
uint16_t port; |
|||
char ipaddr[64]; |
|||
}; |
|||
|
|||
struct LP_quoteinfo |
|||
{ |
|||
struct basilisk_request R; |
|||
bits256 srchash,desthash,txid,txid2,desttxid,feetxid,privkey; |
|||
uint64_t satoshis,txfee,destsatoshis,desttxfee; |
|||
uint32_t timestamp,quotetime; int32_t vout,vout2,destvout,feevout,pair; |
|||
char srccoin[16],coinaddr[64],destcoin[16],destaddr[64]; |
|||
}; |
|||
|
|||
struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; }; |
|||
|
|||
struct basilisk_swap |
|||
{ |
|||
void *ctx; struct iguana_info bobcoin,alicecoin; struct LP_utxoinfo *utxo; |
|||
struct LP_endpoint N; |
|||
void (*balancingtrade)(struct basilisk_swap *swap,int32_t iambob); |
|||
int32_t subsock,pushsock,connected,aliceunconf,depositunconf,paymentunconf; uint32_t lasttime,aborted; |
|||
FILE *fp; |
|||
bits256 persistent_privkey,persistent_pubkey; |
|||
struct basilisk_swapinfo I; |
|||
struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim; |
|||
bits256 privkeys[INSTANTDEX_DECKSIZE]; |
|||
struct basilisk_swapmessage *messages; int32_t nummessages,sentflag; |
|||
char Bdeposit[64],Bpayment[64]; |
|||
uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; |
|||
uint8_t persistent_pubkey33[33],changermd160[20],pad[15],verifybuf[65536]; |
|||
|
|||
}; |
|||
|
|||
void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx); |
|||
uint32_t basilisk_requestid(struct basilisk_request *rp); |
|||
uint32_t basilisk_quoteid(struct basilisk_request *rp); |
|||
struct basilisk_swap *LP_swapinit(int32_t iambob,int32_t optionduration,bits256 privkey,struct basilisk_request *rp,struct LP_quoteinfo *qp); |
|||
char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *method,char *params); |
|||
uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx,uint32_t nextbits,int32_t suppress_swapsend); |
|||
//double LP_query(char *method,struct LP_quoteinfo *qp,char *base,char *rel,bits256 mypub);
|
|||
int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys); |
|||
void LP_quotesinit(char *base,char *rel); |
|||
int32_t LP_forward(void *ctx,char *myipaddr,int32_t pubsock,bits256 pubkey,char *jsonstr,int32_t freeflag); |
|||
int32_t LP_ismine(struct LP_utxoinfo *utxo); |
|||
int32_t LP_isavailable(struct LP_utxoinfo *utxo); |
|||
struct LP_peerinfo *LP_peerfind(uint32_t ipbits,uint16_t port); |
|||
char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen); |
|||
void LP_availableset(struct LP_utxoinfo *utxo); |
|||
int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2); |
|||
int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock); |
|||
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired); |
|||
void LP_utxo_clientpublish(struct LP_utxoinfo *utxo); |
|||
int32_t LP_coinbus(uint16_t coin_busport); |
|||
struct iguana_info *LP_coinfind(char *symbol); |
|||
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32); |
|||
char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price); |
|||
uint64_t LP_txfeecalc(char *symbol,uint64_t txfee); |
|||
|
|||
|
|||
#endif |
@ -0,0 +1,97 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_messages.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
struct LP_messageinfo { struct LP_messageinfo *next,*prev; cJSON *msgjson; int32_t ind; } *LP_MSGS; |
|||
int32_t Num_messages; |
|||
|
|||
void LP_gotmessage(cJSON *argjson) |
|||
{ |
|||
struct LP_messageinfo *msg = calloc(1,sizeof(*msg)); |
|||
msg->msgjson = jduplicate(argjson); |
|||
msg->ind = Num_messages++; |
|||
portable_mutex_lock(&LP_messagemutex); |
|||
DL_APPEND(LP_MSGS,msg); |
|||
portable_mutex_unlock(&LP_messagemutex); |
|||
} |
|||
|
|||
void LP_deletemessages(int32_t firsti,int32_t num) |
|||
{ |
|||
struct LP_messageinfo *msg,*tmp; int32_t lasti; |
|||
if ( num == 0 ) |
|||
num = 100; |
|||
if ( firsti < 0 ) |
|||
firsti = 0; |
|||
else if ( firsti >= Num_messages ) |
|||
return; |
|||
lasti = firsti + num - 1; |
|||
if ( lasti < Num_messages-1 ) |
|||
lasti = Num_messages - 1; |
|||
DL_FOREACH_SAFE(LP_MSGS,msg,tmp) |
|||
{ |
|||
if ( msg->ind >= firsti && msg->ind <= lasti ) |
|||
{ |
|||
portable_mutex_lock(&LP_messagemutex); |
|||
DL_DELETE(LP_MSGS,msg); |
|||
portable_mutex_unlock(&LP_messagemutex); |
|||
free_json(msg->msgjson); |
|||
free(msg); |
|||
} |
|||
} |
|||
} |
|||
|
|||
cJSON *LP_getmessages(int32_t firsti,int32_t num) |
|||
{ |
|||
struct LP_messageinfo *msg,*tmp; int32_t lasti,n=0,maxi=-1,mini=-1; cJSON *retjson,*item,*array = cJSON_CreateArray(); |
|||
retjson = cJSON_CreateObject(); |
|||
if ( num == 0 ) |
|||
num = 100; |
|||
if ( firsti < 0 ) |
|||
firsti = 0; |
|||
else if ( firsti >= Num_messages ) |
|||
{ |
|||
jadd(retjson,"messages",array); |
|||
return(retjson); |
|||
} |
|||
lasti = firsti + num - 1; |
|||
if ( lasti < Num_messages-1 ) |
|||
lasti = Num_messages - 1; |
|||
DL_FOREACH_SAFE(LP_MSGS,msg,tmp) |
|||
{ |
|||
if ( msg->ind >= firsti && msg->ind <= lasti ) |
|||
{ |
|||
item = cJSON_CreateObject(); |
|||
jaddnum(item,"ind",msg->ind); |
|||
jadd(item,"msg",jduplicate(msg->msgjson)); |
|||
jaddi(array,item); |
|||
if ( mini == -1 || msg->ind < mini ) |
|||
mini = msg->ind; |
|||
if ( maxi == -1 || msg->ind > maxi ) |
|||
maxi = msg->ind; |
|||
n++; |
|||
} |
|||
} |
|||
jadd(retjson,"messages",array); |
|||
jaddnum(retjson,"firsti",firsti); |
|||
jaddnum(retjson,"lasti",lasti); |
|||
jaddnum(retjson,"minind",mini); |
|||
jaddnum(retjson,"maxind",maxi); |
|||
jaddnum(retjson,"num",n); |
|||
return(retjson); |
|||
} |
@ -0,0 +1,684 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
|
|||
//
|
|||
// LP_nativeDEX.c
|
|||
// marketmaker
|
|||
//
|
|||
// new features:
|
|||
// bittrex balancing
|
|||
// detect port conflicts on enable
|
|||
// stats
|
|||
// PoW, JS
|
|||
// verify actual pricing
|
|||
// autoutxo, if < 10*txfee and > 10 utxo: combine smallest utxo into dexfee; autosplit if imbalanced
|
|||
|
|||
// unduplicated bugs:
|
|||
// swap cancel should cleanly cancel
|
|||
|
|||
#include <stdio.h> |
|||
#include "LP_include.h" |
|||
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex; |
|||
int32_t LP_canbind; |
|||
|
|||
struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2]; |
|||
struct LP_peerinfo *LP_peerinfos,*LP_mypeer; |
|||
struct LP_forwardinfo *LP_forwardinfos; |
|||
struct iguana_info *LP_coins; |
|||
#include "LP_network.c" |
|||
|
|||
char *activecoins[] = { "BTC", "KMD" }; |
|||
char GLOBAL_DBDIR[] = { "DB" }; |
|||
char USERPASS[65],USERPASS_WIFSTR[64],LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" }; |
|||
char LP_gui[16] = { "cli" }; |
|||
|
|||
char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", };//"5.9.253.204" }; //
|
|||
|
|||
//uint32_t LP_deadman_switch;
|
|||
uint16_t LP_fixed_pairport,LP_publicport; |
|||
int32_t LP_mybussock = -1; |
|||
int32_t LP_mypubsock = -1; |
|||
int32_t LP_mypullsock = -1; |
|||
int32_t LP_pendingswaps,LP_showwif,USERPASS_COUNTER,IAMLP = 0; |
|||
uint32_t LP_sessionid; |
|||
double LP_profitratio = 1.; |
|||
bits256 LP_mypub25519,LP_mypriv25519; |
|||
|
|||
// stubs
|
|||
|
|||
void tradebot_swap_balancingtrade(struct basilisk_swap *swap,int32_t iambob) |
|||
{ |
|||
|
|||
} |
|||
|
|||
void tradebot_pendingadd(cJSON *tradejson,char *base,double basevolume,char *rel,double relvolume) |
|||
{ |
|||
// add to trades
|
|||
} |
|||
|
|||
char *LP_getdatadir() |
|||
{ |
|||
return(USERHOME); |
|||
} |
|||
|
|||
char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_t skip) |
|||
{ |
|||
return(0); |
|||
} |
|||
|
|||
#include "LP_secp.c" |
|||
#include "LP_bitcoin.c" |
|||
#include "LP_coins.c" |
|||
#include "LP_rpc.c" |
|||
#include "LP_prices.c" |
|||
#include "LP_scan.c" |
|||
#include "LP_transaction.c" |
|||
#include "LP_remember.c" |
|||
#include "LP_swap.c" |
|||
#include "LP_peers.c" |
|||
#include "LP_utxos.c" |
|||
#include "LP_forwarding.c" |
|||
#include "LP_ordermatch.c" |
|||
#include "LP_portfolio.c" |
|||
#include "LP_messages.c" |
|||
#include "LP_commands.c" |
|||
|
|||
char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) |
|||
{ |
|||
char *retstr=0; |
|||
if ( jobj(argjson,"result") != 0 || jobj(argjson,"error") != 0 ) |
|||
return(0); |
|||
if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) |
|||
{ |
|||
if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) |
|||
{ |
|||
//printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr);
|
|||
//if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 &&
|
|||
//LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0);
|
|||
} |
|||
} |
|||
return(retstr); |
|||
} |
|||
|
|||
char *LP_decrypt(uint8_t *ptr,int32_t *recvlenp) |
|||
{ |
|||
uint8_t decoded[LP_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES],*nonce,*cipher; int32_t recvlen,cipherlen; char *jsonstr = 0; |
|||
recvlen = *recvlenp; |
|||
nonce = &ptr[2]; |
|||
cipher = &ptr[2 + crypto_box_NONCEBYTES]; |
|||
cipherlen = recvlen - (2 + crypto_box_NONCEBYTES); |
|||
if ( cipherlen > 0 && cipherlen <= sizeof(decoded) ) |
|||
{ |
|||
if ( (jsonstr= (char *)_SuperNET_decipher(nonce,cipher,decoded,cipherlen,GENESIS_PUBKEY,LP_mypriv25519)) != 0 ) |
|||
{ |
|||
recvlen = (cipherlen - crypto_box_ZEROBYTES); |
|||
if ( strlen(jsonstr)+1 != recvlen ) |
|||
{ |
|||
printf("unexpected len %d vs recvlen.%d\n",(int32_t)strlen(jsonstr)+1,recvlen); |
|||
jsonstr = 0; |
|||
} else printf("decrypted (%s)\n",jsonstr); |
|||
} |
|||
} else printf("cipher.%d too big for %d\n",cipherlen,(int32_t)sizeof(decoded)); |
|||
*recvlenp = recvlen; |
|||
return(jsonstr); |
|||
} |
|||
|
|||
char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,uint8_t *ptr,int32_t recvlen,int32_t recvsock) |
|||
{ |
|||
static uint32_t dup,uniq; |
|||
int32_t i,len,cipherlen,datalen=0,duplicate=0,encrypted=0; char *method,*method2,*tmp,*cipherstr,*retstr=0,*jsonstr=0; cJSON *argjson; uint32_t crc32; |
|||
crc32 = calc_crc32(0,&ptr[2],recvlen-2); |
|||
if ( (crc32 & 0xff) == ptr[0] && ((crc32>>8) & 0xff) == ptr[1] ) |
|||
encrypted = 1; |
|||
portable_mutex_lock(&LP_commandmutex); |
|||
i = LP_crc32find(&duplicate,-1,crc32); |
|||
if ( duplicate != 0 ) |
|||
dup++; |
|||
else uniq++; |
|||
if ( (rand() % 1000) == 0 ) |
|||
printf("%s dup.%d (%u / %u) %.1f%% encrypted.%d recv.%u [%02x %02x] vs %02x %02x U.%d\n",typestr,duplicate,dup,dup+uniq,(double)100*dup/(dup+uniq),encrypted,crc32,ptr[0],ptr[1],crc32&0xff,(crc32>>8)&0xff,LP_mypeer != 0 ? LP_mypeer->numutxos : -1); |
|||
if ( duplicate == 0 ) |
|||
{ |
|||
if ( i >= 0 ) |
|||
LP_crc32find(&duplicate,i,crc32); |
|||
if ( encrypted != 0 ) |
|||
jsonstr = LP_decrypt(ptr,&recvlen); |
|||
else if ( (datalen= is_hexstr((char *)ptr,0)) > 0 ) |
|||
{ |
|||
datalen >>= 1; |
|||
jsonstr = malloc(datalen + 1); |
|||
decode_hex((void *)jsonstr,datalen,(char *)ptr); |
|||
jsonstr[datalen] = 0; |
|||
} else jsonstr = (char *)ptr; |
|||
if ( jsonstr != 0 && (argjson= cJSON_Parse(jsonstr)) != 0 ) |
|||
{ |
|||
uint8_t decoded[LP_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES]; |
|||
//printf("[%s]\n",jsonstr);
|
|||
cipherlen = 0; |
|||
if ( (cipherstr= jstr(argjson,"cipher")) != 0 && (cipherlen= is_hexstr(cipherstr,0)) > 32 && cipherlen <= sizeof(decoded)*2 ) |
|||
{ |
|||
method2 = jstr(argjson,"method2"); |
|||
if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"encrypted") == 0 ||(method2 != 0 && strcmp(method2,"encrypted") == 0)) ) |
|||
{ |
|||
cipherlen >>= 1; |
|||
decode_hex(decoded,cipherlen,cipherstr); |
|||
crc32 = calc_crc32(0,&decoded[2],cipherlen-2); |
|||
if ( (tmp= LP_decrypt(decoded,&cipherlen)) != 0 ) |
|||
{ |
|||
jsonstr = tmp; |
|||
free_json(argjson); |
|||
argjson = cJSON_Parse(jsonstr); |
|||
recvlen = cipherlen; |
|||
encrypted = 1; |
|||
if ( (crc32 & 0xff) == decoded[0] && ((crc32>>8) & 0xff) == decoded[1] ) |
|||
{ |
|||
i = LP_crc32find(&duplicate,-1,crc32); |
|||
if ( duplicate == 0 && i >= 0 ) |
|||
LP_crc32find(&duplicate,i,crc32); |
|||
} |
|||
printf("%02x %02x %08x duplicate.%d decrypted.(%s)\n",decoded[0],decoded[1],crc32,duplicate,jsonstr); |
|||
} |
|||
else |
|||
{ |
|||
printf("packet not for this node %u\n",crc32); |
|||
} |
|||
} else printf("error (%s) method is %s\n",jsonstr,method); |
|||
} |
|||
if ( jsonstr != 0 && argjson != 0 ) |
|||
{ |
|||
len = (int32_t)strlen(jsonstr) + 1; |
|||
if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) |
|||
{ |
|||
} |
|||
free_json(argjson); |
|||
} |
|||
} |
|||
} //else printf("DUPLICATE.(%s)\n",(char *)ptr);
|
|||
portable_mutex_unlock(&LP_commandmutex); |
|||
if ( jsonstr != 0 && (void *)jsonstr != (void *)ptr && encrypted == 0 ) |
|||
free(jsonstr); |
|||
if ( ptr != 0 ) |
|||
nn_freemsg(ptr), ptr = 0; |
|||
return(retstr); |
|||
} |
|||
|
|||
void LP_utxo_spentcheck(int32_t pubsock,struct LP_utxoinfo *utxo) |
|||
{ |
|||
struct _LP_utxoinfo u; struct iguana_info *coin; char str[65]; uint32_t now = (uint32_t)time(NULL); |
|||
if ( IAMLP != 0 && (coin= LP_coinfind(utxo->coin)) != 0 && coin->inactive != 0 ) |
|||
return; |
|||
//printf("%s lag.%d\n",bits256_str(str,utxo->txid),now-utxo->lastspentcheck);
|
|||
if ( utxo->T.spentflag == 0 && now > utxo->T.lastspentcheck+60 ) |
|||
{ |
|||
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; |
|||
utxo->T.lastspentcheck = now; |
|||
if ( LP_txvalue(0,utxo->coin,utxo->payment.txid,utxo->payment.vout) == 0 ) |
|||
{ |
|||
printf("txid.%s %s/v%d %.8f has been spent\n",utxo->coin,bits256_str(str,utxo->payment.txid),utxo->payment.vout,dstr(utxo->payment.value)); |
|||
LP_spentnotify(utxo,0); |
|||
} |
|||
else if ( LP_txvalue(0,utxo->coin,u.txid,u.vout) == 0 ) |
|||
{ |
|||
printf("txid2.%s %s/v%d %.8f has been spent\n",utxo->coin,bits256_str(str,u.txid),u.vout,dstr(u.value)); |
|||
LP_spentnotify(utxo,1); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void LP_myutxo_updates(void *ctx,int32_t pubsock,char *passphrase) |
|||
{ |
|||
//LP_utxopurge(0); not good to disrupt existing pointers
|
|||
LP_privkey_updates(ctx,pubsock,passphrase,0); |
|||
} |
|||
|
|||
int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pubsock,struct LP_peerinfo *peer,uint32_t now,int32_t interval,int32_t maxentries) |
|||
{ |
|||
int32_t lastn,n = -1; |
|||
if ( peer->lastutxos < now-interval ) |
|||
{ |
|||
//lastn = peer->numutxos - mypeer->numutxos + LP_PROPAGATION_SLACK;
|
|||
//if ( lastn < LP_PROPAGATION_SLACK * 2 )
|
|||
lastn = LP_PROPAGATION_SLACK * 2; |
|||
if ( mypeer == 0 || strcmp(peer->ipaddr,mypeer->ipaddr) != 0 ) |
|||
{ |
|||
peer->lastutxos = now; |
|||
//printf("query utxos from %s\n",peer->ipaddr);
|
|||
n = LP_utxosquery(mypeer,pubsock,peer->ipaddr,peer->port,"",lastn,mypeer != 0 ? mypeer->ipaddr : "127.0.0.1",myport,maxentries); |
|||
} |
|||
} //else printf("LP_peer_utxosquery skip.(%s) %u\n",peer->ipaddr,peer->lastutxos);
|
|||
return(n); |
|||
} |
|||
|
|||
int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock) |
|||
{ |
|||
int32_t recvlen=1,nonz = 0; void *ptr; char *retstr; struct nn_pollfd pfd; |
|||
if ( sock >= 0 ) |
|||
{ |
|||
while ( nonz < 1000 && recvlen > 0 ) |
|||
{ |
|||
memset(&pfd,0,sizeof(pfd)); |
|||
pfd.fd = sock; |
|||
pfd.events = NN_POLLIN; |
|||
if ( nn_poll(&pfd,1,1) != 1 ) |
|||
break; |
|||
if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) |
|||
{ |
|||
nonz++; |
|||
if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) |
|||
free(retstr); |
|||
} |
|||
} |
|||
} |
|||
return(nonz); |
|||
} |
|||
|
|||
void command_rpcloop(void *myipaddr) |
|||
{ |
|||
int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; void *ctx; //struct iguana_info *coin,*ctmp;
|
|||
ctx = bitcoin_ctx(); |
|||
if ( (origipaddr= myipaddr) == 0 ) |
|||
origipaddr = "127.0.0.1"; |
|||
while ( 1 ) |
|||
{ |
|||
nonz = 0; |
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
if ( peer->errors >= LP_MAXPEER_ERRORS ) |
|||
{ |
|||
if ( (rand() % 10000) == 0 ) |
|||
peer->errors--; |
|||
else continue; |
|||
} |
|||
//printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock);
|
|||
nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock); |
|||
} |
|||
/*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht
|
|||
{ |
|||
if ( coin->inactive != 0 ) |
|||
continue; |
|||
if ( coin->bussock >= 0 ) |
|||
nonz += LP_sock_check(coin->symbol,ctx,origipaddr,-1,coin->bussock,LP_profitratio - 1.); |
|||
}*/ |
|||
if ( LP_mypullsock >= 0 ) |
|||
nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock); |
|||
//if ( LP_mybussock >= 0 )
|
|||
// nonz += LP_sock_check("BUS",ctx,origipaddr,-1,LP_mybussock);
|
|||
if ( nonz == 0 ) |
|||
usleep(10000); |
|||
} |
|||
} |
|||
|
|||
int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport,char *passphrase) |
|||
{ |
|||
static uint32_t counter,numpeers,lastresync; //lastforward
|
|||
struct LP_utxoinfo *utxo,*utmp; cJSON *retjson; struct iguana_info *coin,*ctmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp,*mostpeer; uint32_t id,now; int32_t mostutxos,nonz = 0,n=0,num,lastn=-1; |
|||
now = (uint32_t)time(NULL); |
|||
if ( (origipaddr= myipaddr) == 0 ) |
|||
origipaddr = "127.0.0.1"; |
|||
if ( mypeer == 0 ) |
|||
myipaddr = "127.0.0.1"; |
|||
//if ( LP_canbind == 0 ) printf("counter.%d canbind.%d peers\n",counter,LP_canbind);
|
|||
numpeers = LP_numpeers(); |
|||
mostutxos = 0; |
|||
mostpeer = 0; |
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
if ( peer->errors >= LP_MAXPEER_ERRORS ) |
|||
{ |
|||
if ( (rand() % 10000) == 0 ) |
|||
{ |
|||
peer->errors--; |
|||
peer->diduquery = 0; |
|||
} |
|||
if ( IAMLP == 0 ) |
|||
continue; |
|||
} |
|||
if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 10000) == 0) ) |
|||
{ |
|||
//if ( IAMLP != 0 )
|
|||
// printf("numpeers.%d updatepeer.%s lag.%d\n",numpeers,peer->ipaddr,now-peer->lastpeers);
|
|||
peer->lastpeers = now; |
|||
//if ( IAMLP != 0 && peer->numpeers != numpeers )
|
|||
// printf("%s num.%d vs %d\n",peer->ipaddr,peer->numpeers,numpeers);
|
|||
if ( strcmp(peer->ipaddr,myipaddr) != 0 ) |
|||
LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport); |
|||
if ( IAMLP != 0 && LP_mypeer != 0 && strcmp(peer->ipaddr,myipaddr) != 0 ) |
|||
{ |
|||
if ( (retstr= issue_LP_numutxos(peer->ipaddr,peer->port,LP_mypeer->ipaddr,LP_mypeer->port,LP_mypeer->numpeers,LP_mypeer->numutxos)) != 0 ) |
|||
{ |
|||
//printf("%d <- (%s)\n",peer->numutxos,retstr);
|
|||
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|||
{ |
|||
if ( (num= jint(retjson,"numutxos")) > peer->numutxos ) |
|||
peer->numutxos = num; |
|||
if ( (num= jint(retjson,"numpeers")) > peer->numpeers ) |
|||
peer->numpeers = num; |
|||
if ( (id= juint(retjson,"session")) != 0 ) |
|||
peer->sessionid = id; |
|||
free_json(retjson); |
|||
} |
|||
free(retstr); |
|||
retstr = 0; |
|||
} |
|||
} |
|||
} |
|||
if ( peer->diduquery == 0 ) |
|||
{ |
|||
if ( lastn != n || n < 20 ) |
|||
{ |
|||
lastn = n; |
|||
n = LP_peer_utxosquery(mypeer,myport,pubsock,peer,now,60,100); |
|||
} |
|||
LP_peer_pricesquery(peer->ipaddr,peer->port); |
|||
peer->diduquery = now; |
|||
} |
|||
if ( peer->numutxos > mostutxos ) |
|||
{ |
|||
mostutxos = peer->numutxos; |
|||
mostpeer = peer; |
|||
} |
|||
} |
|||
//printf("numutxos vs mine.%d\n",LP_mypeer != 0 ? LP_mypeer->numutxos : -1);
|
|||
if ( LP_mypeer != 0 && LP_mypeer->numutxos < mostutxos && mostpeer != 0 && time(NULL) > lastresync+180 ) |
|||
{ |
|||
printf("myutxos.%d most.%d %s\n",LP_mypeer->numutxos,mostutxos,mostpeer->ipaddr); |
|||
LP_peer_utxosquery(LP_mypeer,myport,pubsock,mostpeer,now,60,(mostutxos-LP_mypeer->numutxos) * 2); |
|||
lastresync = (uint32_t)time(NULL); |
|||
//LP_peer_pricesquery(mostpeer->ipaddr,mostpeer->port);
|
|||
} |
|||
if ( (counter % 6000) == 10 ) |
|||
{ |
|||
LP_myutxo_updates(ctx,pubsock,passphrase); |
|||
HASH_ITER(hh,LP_utxoinfos[0],utxo,utmp) |
|||
{ |
|||
LP_utxo_spentcheck(pubsock,utxo); |
|||
} |
|||
HASH_ITER(hh,LP_utxoinfos[1],utxo,utmp) |
|||
{ |
|||
LP_utxo_spentcheck(pubsock,utxo); |
|||
if ( LP_isunspent(utxo) > 0 && utxo->T.lasttime == 0 && LP_ismine(utxo) > 0 ) |
|||
{ |
|||
char str[65]; printf("publish mybob %s\n",bits256_str(str,utxo->payment.txid)); |
|||
LP_utxo_clientpublish(utxo); |
|||
} |
|||
} |
|||
} |
|||
HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht
|
|||
{ |
|||
cJSON *obj; int32_t height; bits256 zero; |
|||
//printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain);
|
|||
if ( coin->inactive != 0 ) |
|||
continue; |
|||
memset(zero.bytes,0,sizeof(zero)); |
|||
if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) |
|||
{ |
|||
if ( (obj= LP_getinfo(coin->symbol)) != 0 ) |
|||
{ |
|||
if ( (height= jint(obj,"blocks")) > coin->longestchain ) |
|||
{ |
|||
coin->longestchain = height; |
|||
if ( coin->firstrefht != 0 ) |
|||
printf(">>>>>>>>>> set %s longestchain %d (ref.%d [%d, %d])\n",coin->symbol,height,coin->firstrefht,coin->firstscanht,coin->lastscanht); |
|||
} else LP_mempoolscan(coin->symbol,zero); |
|||
free_json(obj); |
|||
} else printf("error getting info.%s\n",coin->symbol); |
|||
coin->lastgetinfo = (uint32_t)time(NULL); |
|||
} |
|||
if ( coin->firstrefht == 0 ) |
|||
continue; |
|||
else if ( coin->firstscanht == 0 ) |
|||
coin->lastscanht = coin->firstscanht = coin->firstrefht; |
|||
else if ( coin->firstrefht < coin->firstscanht ) |
|||
{ |
|||
printf("detected %s firstrefht.%d < firstscanht.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht); |
|||
coin->lastscanht = coin->firstscanht = coin->firstrefht; |
|||
} |
|||
if ( coin->lastscanht == coin->longestchain+1 ) |
|||
continue; |
|||
else if ( coin->lastscanht > coin->longestchain+1 ) |
|||
{ |
|||
printf("detected chain rewind lastscanht.%d vs longestchain.%d, first.%d ref.%d\n",coin->lastscanht,coin->longestchain,coin->firstscanht,coin->firstrefht); |
|||
LP_undospends(coin,coin->longestchain-1); |
|||
LP_mempoolscan(coin->symbol,zero); |
|||
coin->lastscanht = coin->longestchain - 1; |
|||
if ( coin->firstscanht < coin->lastscanht ) |
|||
coin->lastscanht = coin->firstscanht; |
|||
continue; |
|||
} |
|||
//printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain);
|
|||
if ( LP_blockinit(coin,coin->lastscanht) < 0 ) |
|||
{ |
|||
printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht); |
|||
continue; |
|||
} |
|||
coin->lastscanht++; |
|||
break; |
|||
} |
|||
if ( (counter % 6000) == 60 ) |
|||
{ |
|||
if ( (retstr= basilisk_swapentry(0,0)) != 0 ) |
|||
{ |
|||
//printf("SWAPS.(%s)\n",retstr);
|
|||
free(retstr); |
|||
} |
|||
} |
|||
counter++; |
|||
return(nonz); |
|||
} |
|||
|
|||
void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins,char *passphrase) |
|||
{ |
|||
int32_t i,n; cJSON *item; |
|||
for (i=0; i<sizeof(activecoins)/sizeof(*activecoins); i++) |
|||
{ |
|||
fprintf(stderr,"%s ",activecoins[i]); |
|||
LP_coinfind(activecoins[i]); |
|||
LP_priceinfoadd(activecoins[i]); |
|||
} |
|||
if ( (n= cJSON_GetArraySize(coins)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(coins,i); |
|||
fprintf(stderr,"%s ",jstr(item,"coin")); |
|||
LP_coincreate(item); |
|||
LP_priceinfoadd(jstr(item,"coin")); |
|||
} |
|||
} |
|||
fprintf(stderr,"privkey updates\n"); |
|||
LP_privkey_updates(ctx,pubsock,passphrase,1); |
|||
} |
|||
|
|||
void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,char *seednode) |
|||
{ |
|||
int32_t i,j; uint32_t r; |
|||
if ( IAMLP != 0 ) |
|||
{ |
|||
LP_mypeer = mypeer = LP_addpeer(mypeer,pubsock,myipaddr,myport,0,0,0,0,LP_sessionid); |
|||
if ( myipaddr == 0 || mypeer == 0 ) |
|||
{ |
|||
printf("couldnt get myipaddr or null mypeer.%p\n",mypeer); |
|||
exit(-1); |
|||
} |
|||
if ( seednode == 0 || seednode[0] == 0 ) |
|||
{ |
|||
for (i=0; i<sizeof(default_LPnodes)/sizeof(*default_LPnodes); i++) |
|||
{ |
|||
//if ( (rand() % 100) > 25 )
|
|||
// continue;
|
|||
LP_peersquery(mypeer,pubsock,default_LPnodes[i],myport,mypeer->ipaddr,myport); |
|||
} |
|||
} else LP_peersquery(mypeer,pubsock,seednode,myport,mypeer->ipaddr,myport); |
|||
} |
|||
else |
|||
{ |
|||
if ( myipaddr == 0 ) |
|||
{ |
|||
printf("couldnt get myipaddr\n"); |
|||
exit(-1); |
|||
} |
|||
if ( seednode == 0 || seednode[0] == 0 ) |
|||
{ |
|||
OS_randombytes((void *)&r,sizeof(r)); |
|||
for (j=0; j<sizeof(default_LPnodes)/sizeof(*default_LPnodes); j++) |
|||
{ |
|||
i = (r + j) % (sizeof(default_LPnodes)/sizeof(*default_LPnodes)); |
|||
LP_peersquery(mypeer,pubsock,default_LPnodes[i],myport,"127.0.0.1",myport); |
|||
} |
|||
} else LP_peersquery(mypeer,pubsock,seednode,myport,"127.0.0.1",myport); |
|||
} |
|||
} |
|||
|
|||
void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybusport,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson) |
|||
{ |
|||
char *myipaddr=0; long filesize,n; int32_t timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128]; void *ctx = bitcoin_ctx(); |
|||
LP_showwif = juint(argjson,"wif"); |
|||
if ( passphrase == 0 || passphrase[0] == 0 ) |
|||
{ |
|||
printf("jeezy says we cant use the nullstring as passphrase and I agree\n"); |
|||
exit(-1); |
|||
} |
|||
IAMLP = !amclient; |
|||
#ifndef __linux__ |
|||
if ( IAMLP != 0 ) |
|||
{ |
|||
printf("must run a unix node for LP node\n"); |
|||
exit(-1); |
|||
} |
|||
#endif |
|||
OS_randombytes((void *)&n,sizeof(n)); |
|||
if ( jobj(argjson,"gui") != 0 ) |
|||
safecopy(LP_gui,jstr(argjson,"gui"),sizeof(LP_gui)); |
|||
if ( jobj(argjson,"canbind") == 0 ) |
|||
{ |
|||
#ifndef __linux__ |
|||
LP_canbind = IAMLP; |
|||
#else |
|||
LP_canbind = IAMLP; |
|||
#endif |
|||
} |
|||
else |
|||
{ |
|||
LP_canbind = jint(argjson,"canbind"); |
|||
printf(">>>>>>>>>>> set LP_canbind.%d\n",LP_canbind); |
|||
} |
|||
if ( LP_canbind > 1000 && LP_canbind < 65536 ) |
|||
LP_fixed_pairport = LP_canbind; |
|||
if ( LP_canbind != 0 ) |
|||
LP_canbind = 1; |
|||
srand((int32_t)n); |
|||
if ( userhome != 0 && userhome[0] != 0 ) |
|||
{ |
|||
safecopy(USERHOME,userhome,sizeof(USERHOME)); |
|||
#ifdef __APPLE__ |
|||
strcat(USERHOME,"/Library/Application Support"); |
|||
#endif |
|||
} |
|||
portable_mutex_init(&LP_peermutex); |
|||
portable_mutex_init(&LP_utxomutex); |
|||
portable_mutex_init(&LP_UTXOmutex); |
|||
portable_mutex_init(&LP_commandmutex); |
|||
portable_mutex_init(&LP_swaplistmutex); |
|||
portable_mutex_init(&LP_cachemutex); |
|||
portable_mutex_init(&LP_networkmutex); |
|||
portable_mutex_init(&LP_forwardmutex); |
|||
portable_mutex_init(&LP_psockmutex); |
|||
portable_mutex_init(&LP_coinmutex); |
|||
portable_mutex_init(&LP_pubkeymutex); |
|||
portable_mutex_init(&LP_messagemutex); |
|||
portable_mutex_init(&LP_portfoliomutex); |
|||
LP_sessionid = (uint32_t)time(NULL); |
|||
printf("getting myipaddr sessionid.%u\n",LP_sessionid); |
|||
if ( system("curl -s4 checkip.amazonaws.com > /tmp/myipaddr") == 0 ) |
|||
{ |
|||
if ( (myipaddr= OS_filestr(&filesize,"/tmp/myipaddr")) != 0 && myipaddr[0] != 0 ) |
|||
{ |
|||
n = strlen(myipaddr); |
|||
if ( myipaddr[n-1] == '\n' ) |
|||
myipaddr[--n] = 0; |
|||
strcpy(LP_myipaddr,myipaddr); |
|||
} else printf("error getting myipaddr\n"); |
|||
} else printf("error issuing curl\n"); |
|||
if ( IAMLP != 0 ) |
|||
{ |
|||
pubsock = -1; |
|||
nanomsg_transportname(0,subaddr,myipaddr,mypubport); |
|||
nanomsg_transportname(1,bindaddr,myipaddr,mypubport); |
|||
if ( (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) |
|||
{ |
|||
if ( nn_bind(pubsock,bindaddr) >= 0 ) |
|||
{ |
|||
timeout = 10; |
|||
nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); |
|||
} |
|||
else |
|||
{ |
|||
printf("error binding to (%s).%d\n",subaddr,pubsock); |
|||
if ( pubsock >= 0 ) |
|||
nn_close(pubsock), pubsock = -1; |
|||
} |
|||
} else printf("error getting pubsock %d\n",pubsock); |
|||
printf(">>>>>>>>> myipaddr.%s (%s) pullsock.%d\n",myipaddr,subaddr,pubsock); |
|||
LP_mypubsock = pubsock; |
|||
} |
|||
printf("got %s, initpeers\n",myipaddr); |
|||
LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode")); |
|||
printf("get public socket\n"); |
|||
LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); |
|||
strcpy(LP_publicaddr,pushaddr); |
|||
LP_publicport = mypullport; |
|||
LP_mybussock = LP_coinbus(mybusport); |
|||
//LP_deadman_switch = (uint32_t)time(NULL);
|
|||
printf("canbind.%d my command address is (%s) pullsock.%d pullport.%u\n",LP_canbind,pushaddr,LP_mypullsock,mypullport); |
|||
printf("initcoins\n"); |
|||
LP_initcoins(ctx,pubsock,jobj(argjson,"coins"),passphrase); |
|||
if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)&myipaddr) != 0 ) |
|||
{ |
|||
printf("error launching LP_psockloop for (%s)\n",myipaddr); |
|||
exit(-1); |
|||
} |
|||
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) |
|||
{ |
|||
printf("error launching stats rpcloop for port.%u\n",myport); |
|||
exit(-1); |
|||
} |
|||
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)&myipaddr) != 0 ) |
|||
{ |
|||
printf("error launching stats rpcloop for port.%u\n",myport); |
|||
exit(-1); |
|||
} |
|||
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)&myipaddr) != 0 ) |
|||
{ |
|||
printf("error launching stats rpcloop for port.%u\n",myport); |
|||
exit(-1); |
|||
} |
|||
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,(void *)&myipaddr) != 0 ) |
|||
{ |
|||
printf("error launching stats rpcloop for port.%u\n",myport); |
|||
exit(-1); |
|||
} |
|||
//if ( (retstr= basilisk_swapentry(0,0)) != 0 )
|
|||
// free(retstr);
|
|||
while ( 1 ) |
|||
{ |
|||
//fprintf(stderr,".");
|
|||
if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport,passphrase) == 0 ) |
|||
usleep(1000000 / MAINLOOP_PERSEC); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
@ -0,0 +1,720 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_network.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
struct psock |
|||
{ |
|||
uint32_t lasttime,lastping,errors; |
|||
int32_t publicsock,sendsock,ispaired; |
|||
uint16_t publicport,sendport; |
|||
char sendaddr[128],publicaddr[128]; |
|||
} *PSOCKS; |
|||
|
|||
uint16_t Numpsocks,Psockport = MIN_PSOCK_PORT; |
|||
|
|||
char *nanomsg_transportname(int32_t bindflag,char *str,char *ipaddr,uint16_t port) |
|||
{ |
|||
sprintf(str,"tcp://%s:%u",bindflag == 0 ? ipaddr : "*",port); // ws is worse
|
|||
return(str); |
|||
} |
|||
|
|||
int32_t _LP_send(int32_t sock,void *msg,int32_t sendlen,int32_t freeflag) |
|||
{ |
|||
int32_t sentbytes; |
|||
if ( sock < 0 ) |
|||
{ |
|||
printf("LP_send.(%s) to illegal socket\n",(char *)msg); |
|||
if ( freeflag != 0 ) |
|||
free(msg); |
|||
return(-1); |
|||
} |
|||
if ( (sentbytes= nn_send(sock,msg,sendlen,0)) != sendlen ) |
|||
printf("LP_send sent %d instead of %d\n",sentbytes,sendlen); |
|||
//else printf("SENT.(%s)\n",msg);
|
|||
if ( freeflag != 0 ) |
|||
free(msg); |
|||
return(sentbytes); |
|||
} |
|||
|
|||
int32_t LP_sockcheck(int32_t sock) |
|||
{ |
|||
struct nn_pollfd pfd; |
|||
pfd.fd = sock; |
|||
pfd.events = NN_POLLOUT; |
|||
if ( nn_poll(&pfd,1,1) > 0 ) |
|||
return(1); |
|||
else return(-1); |
|||
} |
|||
|
|||
struct LP_queue |
|||
{ |
|||
struct LP_queue *next,*prev; |
|||
int32_t sock,peerind,msglen; |
|||
uint32_t starttime,crc32; |
|||
uint8_t msg[]; |
|||
} *LP_Q; |
|||
int32_t LP_Qenqueued,LP_Qerrors,LP_Qfound; |
|||
|
|||
void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,int32_t peerind) |
|||
{ |
|||
struct LP_queue *ptr; |
|||
ptr = calloc(1,sizeof(*ptr) + msglen); |
|||
ptr->crc32 = crc32; |
|||
ptr->sock = sock; |
|||
ptr->peerind = peerind; |
|||
ptr->msglen = msglen; |
|||
memcpy(ptr->msg,msg,msglen); |
|||
DL_APPEND(LP_Q,ptr); |
|||
LP_Qenqueued++; |
|||
//printf("Q.%p: peerind.%d msglen.%d\n",ptr,peerind,msglen);
|
|||
} |
|||
|
|||
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) |
|||
{ |
|||
static uint32_t crcs[8192]; static unsigned long dup,total; |
|||
int32_t i; |
|||
*duplicatep = 0; |
|||
if ( ind < 0 ) |
|||
{ |
|||
total++; |
|||
for (i=0; i<sizeof(crcs)/sizeof(*crcs); i++) |
|||
{ |
|||
if ( crc32 == crcs[i] ) |
|||
{ |
|||
if ( i > 0 ) |
|||
{ |
|||
crcs[i] = crcs[i >> 1]; |
|||
crcs[i >> 1] = crc32; |
|||
dup++; |
|||
//printf("duplicate %u in slot %d -> slot %d (%lu / %lu)\n",crc32,i,i>>1,dup,total);
|
|||
} |
|||
*duplicatep = 1; |
|||
break; |
|||
} |
|||
else if ( crcs[i] == 0 ) |
|||
break; |
|||
} |
|||
if ( i >= sizeof(crcs)/sizeof(*crcs) ) |
|||
i = (rand() % (sizeof(crcs)/sizeof(*crcs))); |
|||
return(i); |
|||
} |
|||
else |
|||
{ |
|||
crcs[ind] = crc32; |
|||
return(ind); |
|||
} |
|||
} |
|||
|
|||
int32_t LP_peerindsock(int32_t *peerindp) |
|||
{ |
|||
struct LP_peerinfo *peer,*tmp; int32_t peerind = 0; |
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
peerind++; |
|||
if ( peer->errors < LP_MAXPEER_ERRORS && peer->pushsock >= 0 ) |
|||
{ |
|||
if ( peerind < *peerindp ) |
|||
continue; |
|||
*peerindp = peerind; |
|||
//printf("peerind.%d -> sock %d\n",peerind,peer->pushsock);
|
|||
return(peer->pushsock); |
|||
} |
|||
} |
|||
return(-1); |
|||
} |
|||
|
|||
void queue_loop(void *ignore) |
|||
{ |
|||
struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; |
|||
while ( 1 ) |
|||
{ |
|||
nonz = 0; |
|||
//printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0);
|
|||
n = 0; |
|||
DL_FOREACH_SAFE(LP_Q,ptr,tmp) |
|||
{ |
|||
n++; |
|||
flag = 0; |
|||
if ( ptr->sock >= 0 ) |
|||
{ |
|||
if ( LP_sockcheck(ptr->sock) > 0 ) |
|||
{ |
|||
if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) |
|||
printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); |
|||
// else printf("%d %p qsent %u msglen.%d peerind.%d\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind);
|
|||
ptr->sock = -1; |
|||
if ( ptr->peerind > 0 ) |
|||
ptr->starttime = (uint32_t)time(NULL); |
|||
else flag = 1; |
|||
} |
|||
} |
|||
else if ( time(NULL) > ptr->starttime+13 ) |
|||
{ |
|||
LP_crc32find(&duplicate,-1,ptr->crc32); |
|||
if ( duplicate > 0 ) |
|||
{ |
|||
LP_Qfound++; |
|||
if ( (LP_Qfound % 10) == 0 ) |
|||
printf("found.%u Q.%d err.%d match.%d\n",ptr->crc32,LP_Qenqueued,LP_Qerrors,LP_Qfound); |
|||
flag = 1; |
|||
} |
|||
else |
|||
{ |
|||
printf("couldnt find.%u peerind.%d Q.%d err.%d match.%d\n",ptr->crc32,ptr->peerind,LP_Qenqueued,LP_Qerrors,LP_Qfound); |
|||
ptr->peerind++; |
|||
if ( (ptr->sock= LP_peerindsock(&ptr->peerind)) < 0 ) |
|||
{ |
|||
printf("%d no more peers to try at peerind.%d %p Q_LP.%p\n",n,ptr->peerind,ptr,LP_Q); |
|||
flag = 1; |
|||
LP_Qerrors++; |
|||
} |
|||
} |
|||
} |
|||
if ( flag != 0 ) |
|||
{ |
|||
nonz++; |
|||
portable_mutex_lock(&LP_networkmutex); |
|||
DL_DELETE(LP_Q,ptr); |
|||
portable_mutex_unlock(&LP_networkmutex); |
|||
free(ptr); |
|||
ptr = 0; |
|||
} |
|||
} |
|||
//if ( n != 0 )
|
|||
// printf("LP_Q.[%d]\n",n);
|
|||
if ( nonz == 0 ) |
|||
usleep(500000); |
|||
} |
|||
} |
|||
|
|||
void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32_t msglen,int32_t needack) |
|||
{ |
|||
int32_t sentbytes,peerind = 0; |
|||
if ( sock0 >= 0 || sock1 >= 0 ) |
|||
{ |
|||
if ( sock0 >= 0 && LP_sockcheck(sock0) > 0 ) |
|||
{ |
|||
if ( (sentbytes= nn_send(sock0,msg,msglen,0)) != msglen ) |
|||
printf("_LP_queuesend0 sent %d instead of %d\n",sentbytes,msglen); |
|||
else |
|||
{ |
|||
//printf("Q sent %u\n",crc32);
|
|||
sock0 = -1; |
|||
} |
|||
} |
|||
if ( sock1 >= 0 && LP_sockcheck(sock1) > 0 ) |
|||
{ |
|||
if ( (sentbytes= nn_send(sock1,msg,msglen,0)) != msglen ) |
|||
printf("_LP_queuesend1 sent %d instead of %d\n",sentbytes,msglen); |
|||
else sock1 = -1; |
|||
} |
|||
if ( sock0 < 0 && sock1 < 0 ) |
|||
return; |
|||
} |
|||
else |
|||
{ |
|||
peerind = 1; |
|||
sock0 = LP_peerindsock(&peerind); |
|||
} |
|||
portable_mutex_lock(&LP_networkmutex); |
|||
if ( sock0 >= 0 ) |
|||
_LP_sendqueueadd(crc32,sock0,msg,msglen,needack * peerind); |
|||
if ( sock1 >= 0 ) |
|||
_LP_sendqueueadd(crc32,sock1,msg,msglen,needack); |
|||
portable_mutex_unlock(&LP_networkmutex); |
|||
} |
|||
|
|||
void LP_queuesend(uint32_t crc32,int32_t pubsock,char *base,char *rel,uint8_t *msg,int32_t msglen) |
|||
{ |
|||
//struct iguana_info *coin; int32_t flag=0,socks[2];
|
|||
if ( pubsock >= 0 ) |
|||
{ |
|||
//socks[0] = socks[1] = -1;
|
|||
//if ( rel != 0 && rel[0] != 0 && (coin= LP_coinfind(rel)) != 0 && coin->bussock >= 0 )
|
|||
// socks[flag++] = coin->bussock;
|
|||
//if ( base != 0 && base[0] != 0 && (coin= LP_coinfind(base)) != 0 && coin->bussock >= 0 )
|
|||
// socks[flag++] = coin->bussock;
|
|||
//if ( flag == 0 && pubsock >= 0 )
|
|||
_LP_queuesend(crc32,pubsock,-1,msg,msglen,0); |
|||
//else _LP_queuesend(socks[0],socks[1],msg,msglen,0);
|
|||
} else _LP_queuesend(crc32,-1,-1,msg,msglen,1); |
|||
} |
|||
|
|||
// first 2 bytes == (crc32 & 0xffff) if encrypted, then nonce is next crypto_box_NONCEBYTES
|
|||
// GENESIS_PRIVKEY is always the sender
|
|||
|
|||
void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON *argjson,uint32_t crc32) |
|||
{ |
|||
int32_t msglen; |
|||
msg = (void *)jprint(argjson,0); |
|||
msglen = (int32_t)strlen((char *)msg) + 1; |
|||
if ( crc32 == 0 ) |
|||
crc32 = calc_crc32(0,&msg[2],msglen - 2); |
|||
if ( IAMLP == 0 ) |
|||
{ |
|||
free(msg); |
|||
jdelete(argjson,"method"); |
|||
jaddstr(argjson,"method","broadcast"); |
|||
msg = (void *)jprint(argjson,0); |
|||
msglen = (int32_t)strlen((char *)msg) + 1; |
|||
LP_queuesend(crc32,-1,base,rel,msg,msglen); |
|||
} else LP_queuesend(crc32,pubsock,base,rel,msg,msglen); |
|||
free(msg); |
|||
} |
|||
|
|||
void LP_broadcast_message(int32_t pubsock,char *base,char *rel,bits256 destpub25519,char *msgstr) |
|||
{ |
|||
uint8_t encoded[LP_ENCRYPTED_MAXSIZE],space[sizeof(encoded)],*msg,*nonce,*cipher; int32_t encrypted=0,msglen; uint32_t crc32=0; cJSON *argjson; char *methodstr,method[64],cipherstr[LP_ENCRYPTED_MAXSIZE*2+1]; |
|||
msglen = (int32_t)strlen(msgstr) + 1; |
|||
msg = (void *)msgstr; |
|||
if ( bits256_nonz(destpub25519) != 0 ) |
|||
{ |
|||
nonce = &encoded[2]; |
|||
OS_randombytes(nonce,crypto_box_NONCEBYTES); |
|||
cipher = &encoded[2 + crypto_box_NONCEBYTES]; |
|||
msglen = _SuperNET_cipher(nonce,&encoded[2 + crypto_box_NONCEBYTES],msg,msglen,destpub25519,GENESIS_PRIVKEY,space); |
|||
msglen += crypto_box_NONCEBYTES; |
|||
crc32 = calc_crc32(0,&encoded[2],msglen); |
|||
encoded[0] = crc32 & 0xff; |
|||
encoded[1] = (crc32 >> 8) & 0xff; |
|||
msg = encoded; |
|||
msglen += 2; |
|||
encrypted = 1; |
|||
//printf("msgstr.(%s)\n",msgstr);
|
|||
free(msgstr), msgstr = 0; |
|||
} |
|||
if ( encrypted == 0 ) |
|||
{ |
|||
if ( (argjson= cJSON_Parse(msgstr)) != 0 ) |
|||
{ |
|||
if ( (methodstr= jstr(argjson,"method")) != 0 && strlen(methodstr) <= sizeof(method) ) |
|||
{ |
|||
strcpy(method,methodstr); |
|||
jdelete(argjson,"method"); |
|||
if ( jobj(argjson,"method2") != 0 ) |
|||
jdelete(argjson,"method2"); |
|||
jaddstr(argjson,"method2",method); |
|||
jaddstr(argjson,"method",method); |
|||
//printf("CRC32.%u (%s)\n",crc32,(char *)msg);
|
|||
LP_broadcast_finish(pubsock,base,rel,msg,argjson,0); |
|||
} // else printf("no valid method in (%s)\n",msgstr);
|
|||
free_json(argjson); |
|||
} else printf("couldnt parse (%s)\n",msgstr); |
|||
} |
|||
else |
|||
{ |
|||
argjson = cJSON_CreateObject(); |
|||
init_hexbytes_noT(cipherstr,msg,msglen); |
|||
jaddstr(argjson,"cipher",cipherstr); |
|||
jaddstr(argjson,"method2","encrypted"); |
|||
jaddstr(argjson,"method","encrypted"); |
|||
LP_broadcast_finish(pubsock,base,rel,msg,argjson,crc32); |
|||
free_json(argjson); |
|||
} |
|||
if ( msgstr != 0 ) |
|||
free(msgstr); |
|||
} |
|||
|
|||
uint32_t LP_swapsend(int32_t pairsock,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t nextbits,uint32_t crcs[2]) |
|||
{ |
|||
uint8_t *buf; int32_t sentbytes,offset=0,i; |
|||
buf = malloc(datalen + sizeof(msgbits) + sizeof(swap->I.req.quoteid) + sizeof(bits256)*2); |
|||
for (i=0; i<32; i++) |
|||
buf[offset++] = swap->I.myhash.bytes[i]; |
|||
for (i=0; i<32; i++) |
|||
buf[offset++] = swap->I.otherhash.bytes[i]; |
|||
offset += iguana_rwnum(1,&buf[offset],sizeof(swap->I.req.quoteid),&swap->I.req.quoteid); |
|||
offset += iguana_rwnum(1,&buf[offset],sizeof(msgbits),&msgbits); |
|||
if ( datalen > 0 ) |
|||
memcpy(&buf[offset],data,datalen), offset += datalen; |
|||
if ( (sentbytes= nn_send(pairsock,buf,offset,0)) != offset ) |
|||
{ |
|||
printf("sentbytes.%d vs offset.%d\n",sentbytes,offset); |
|||
if ( sentbytes < 0 ) |
|||
{ |
|||
} |
|||
} |
|||
//printf("sent %d bytes\n",sentbytes);
|
|||
//else printf("send.[%d] %x offset.%d datalen.%d [%llx]\n",sentbytes,msgbits,offset,datalen,*(long long *)data);
|
|||
free(buf); |
|||
return(nextbits); |
|||
} |
|||
|
|||
void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to work
|
|||
{ |
|||
static struct nn_pollfd *pfds; |
|||
int32_t i,n,nonz,iter,retval,sentbytes,size=0,sendsock = -1; uint32_t now; struct psock *ptr=0; void *buf=0; char keepalive[512]; |
|||
while ( 1 ) |
|||
{ |
|||
now = (uint32_t)time(NULL); |
|||
if ( buf != 0 && ptr != 0 && sendsock >= 0 ) |
|||
{ |
|||
if ( size > 0 ) |
|||
{ |
|||
if ( (sentbytes= nn_send(sendsock,buf,size,0)) != size ) // need tight loop
|
|||
printf("LP_psockloop sent %d instead of %d\n",sentbytes,size); |
|||
if ( buf != 0 ) |
|||
{ |
|||
if ( buf != keepalive ) |
|||
nn_freemsg(buf); |
|||
buf = 0; |
|||
size = 0; |
|||
ptr = 0; |
|||
sendsock = -1; |
|||
} |
|||
} |
|||
} |
|||
else if ( Numpsocks > 0 ) |
|||
{ |
|||
if ( pfds == 0 ) |
|||
pfds = calloc(MAX_PSOCK_PORT,sizeof(*pfds)); |
|||
portable_mutex_lock(&LP_psockmutex); |
|||
memset(pfds,0,sizeof(*pfds) * ((Numpsocks*2 <= MAX_PSOCK_PORT) ? Numpsocks*2 : MAX_PSOCK_PORT)); |
|||
for (iter=0; iter<2; iter++) |
|||
{ |
|||
for (i=n=0; i<Numpsocks; i++) |
|||
{ |
|||
ptr = &PSOCKS[i]; |
|||
if ( iter == 0 ) |
|||
{ |
|||
pfds[n].fd = ptr->publicsock; |
|||
pfds[n].events = POLLIN; |
|||
} |
|||
else |
|||
{ |
|||
if ( pfds[n].fd != ptr->publicsock ) |
|||
{ |
|||
printf("unexpected fd.%d mismatched publicsock.%d\n",pfds[n].fd,ptr->publicsock); |
|||
break; |
|||
} |
|||
else if ( (pfds[n].revents & POLLIN) != 0 ) |
|||
{ |
|||
printf("publicsock.%d %s has pollin\n",ptr->publicsock,ptr->publicaddr); |
|||
if ( (size= nn_recv(ptr->publicsock,&buf,NN_MSG,0)) > 0 ) |
|||
{ |
|||
ptr->lasttime = now; |
|||
sendsock = ptr->sendsock; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
n++; |
|||
if ( iter == 0 ) |
|||
{ |
|||
pfds[n].fd = ptr->sendsock; |
|||
pfds[n].events = POLLIN; |
|||
} |
|||
else |
|||
{ |
|||
if ( pfds[n].fd != ptr->sendsock ) |
|||
{ |
|||
printf("unexpected fd.%d mismatched sendsock.%d\n",pfds[n].fd,ptr->sendsock); |
|||
break; |
|||
} |
|||
else if ( (pfds[n].revents & POLLIN) != 0 ) |
|||
{ |
|||
if ( (size= nn_recv(ptr->sendsock,&buf,NN_MSG,0)) > 0 ) |
|||
{ |
|||
//printf("%s paired has pollin (%s)\n",ptr->sendaddr,(char *)buf);
|
|||
ptr->lasttime = now; |
|||
if ( ptr->ispaired != 0 ) |
|||
{ |
|||
sendsock = ptr->publicsock; |
|||
break; |
|||
} |
|||
else |
|||
{ |
|||
nn_freemsg(buf); |
|||
buf = 0; |
|||
size = 0; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
n++; |
|||
} |
|||
if ( iter == 0 ) |
|||
{ |
|||
if ( (retval= nn_poll(pfds,n,1)) <= 0 ) |
|||
{ |
|||
if ( retval != 0 ) |
|||
printf("nn_poll retval.%d\n",retval); |
|||
break; |
|||
} else printf("num pfds.%d retval.%d\n",n,retval); |
|||
} |
|||
} |
|||
//free(pfds);
|
|||
//printf("sendsock.%d Numpsocks.%d\n",sendsock,Numpsocks);
|
|||
if ( sendsock < 0 ) |
|||
{ |
|||
for (i=nonz=0; i<Numpsocks; i++) |
|||
{ |
|||
if ( i < Numpsocks ) |
|||
{ |
|||
ptr = &PSOCKS[i]; |
|||
if ( now > ptr->lasttime+PSOCK_KEEPALIVE ) |
|||
{ |
|||
printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime); |
|||
if ( ptr->publicsock >= 0 ) |
|||
nn_close(ptr->publicsock); |
|||
if ( ptr->sendsock >= 0 ) |
|||
nn_close(ptr->sendsock); |
|||
//portable_mutex_lock(&LP_psockmutex);
|
|||
if ( Numpsocks > 1 ) |
|||
{ |
|||
PSOCKS[i] = PSOCKS[--Numpsocks]; |
|||
memset(&PSOCKS[Numpsocks],0,sizeof(*ptr)); |
|||
} else Numpsocks = 0; |
|||
//portable_mutex_unlock(&LP_psockmutex);
|
|||
break; |
|||
} |
|||
else if ( now > ptr->lastping+PSOCK_KEEPALIVE/2 && ptr->errors < 3 ) |
|||
{ |
|||
ptr->lastping = now; |
|||
if ( 0 ) |
|||
{ |
|||
sendsock = ptr->sendsock; |
|||
sprintf(keepalive,"{\"method\":\"keepalive\",\"endpoint\":\"%s\"}",ptr->sendaddr); |
|||
size = (int32_t)strlen(keepalive) + 1; |
|||
buf = keepalive; |
|||
printf("send keepalive.(%s)\n",keepalive); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
if ( nonz == 0 && i == Numpsocks ) |
|||
usleep(100000); |
|||
} |
|||
portable_mutex_unlock(&LP_psockmutex); |
|||
} else usleep(100000); |
|||
} |
|||
} |
|||
|
|||
void LP_psockadd(int32_t ispaired,int32_t publicsock,uint16_t recvport,int32_t sendsock,uint16_t sendport,char *subaddr,char *publicaddr) |
|||
{ |
|||
struct psock *ptr; |
|||
portable_mutex_lock(&LP_psockmutex); |
|||
PSOCKS = realloc(PSOCKS,sizeof(*PSOCKS) * (Numpsocks + 1)); |
|||
ptr = &PSOCKS[Numpsocks++]; |
|||
ptr->ispaired = ispaired; |
|||
ptr->publicsock = publicsock; |
|||
ptr->publicport = recvport; |
|||
ptr->sendsock = sendsock; |
|||
ptr->sendport = sendport; |
|||
safecopy(ptr->sendaddr,subaddr,sizeof(ptr->sendaddr)); |
|||
safecopy(ptr->publicaddr,publicaddr,sizeof(ptr->publicaddr)); |
|||
ptr->lasttime = (uint32_t)time(NULL); |
|||
portable_mutex_unlock(&LP_psockmutex); |
|||
} |
|||
|
|||
int32_t LP_psockmark(char *publicaddr) |
|||
{ |
|||
int32_t i,retval = -1; struct psock *ptr; |
|||
portable_mutex_lock(&LP_psockmutex); |
|||
for (i=0; i<Numpsocks; i++) |
|||
{ |
|||
ptr = &PSOCKS[i]; |
|||
if ( strcmp(publicaddr,ptr->publicaddr) == 0 ) |
|||
{ |
|||
printf("mark PSOCKS[%d] %s for deletion\n",i,publicaddr); |
|||
ptr->lasttime = 0; |
|||
retval = i; |
|||
break; |
|||
} |
|||
} |
|||
portable_mutex_unlock(&LP_psockmutex); |
|||
return(retval); |
|||
} |
|||
|
|||
char *LP_psock(char *myipaddr,int32_t ispaired) |
|||
{ |
|||
char pushaddr[128],subaddr[128]; uint16_t i,publicport,subport,maxiters=100; int32_t timeout,pullsock=-1,pubsock=-1; cJSON *retjson=0; |
|||
retjson = cJSON_CreateObject(); |
|||
publicport = Psockport++; |
|||
subport = Psockport++; |
|||
for (i=0; i<maxiters; i++,publicport+=2,subport+=2) |
|||
{ |
|||
if ( publicport < MIN_PSOCK_PORT ) |
|||
publicport = MIN_PSOCK_PORT+1; |
|||
if ( subport <= publicport ) |
|||
subport = publicport + 1; |
|||
pullsock = pubsock = -1; |
|||
nanomsg_transportname(1,pushaddr,myipaddr,publicport); |
|||
nanomsg_transportname(1,subaddr,myipaddr,subport); |
|||
if ( (pullsock= nn_socket(AF_SP,ispaired!=0?NN_PAIR:NN_PULL)) >= 0 && (pubsock= nn_socket(AF_SP,ispaired!=0?NN_PAIR:NN_PAIR)) >= 0 ) |
|||
{ |
|||
if ( nn_bind(pullsock,pushaddr) >= 0 && nn_bind(pubsock,subaddr) >= 0 ) |
|||
{ |
|||
timeout = 1; |
|||
nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); |
|||
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); |
|||
if ( ispaired != 0 ) |
|||
{ |
|||
//maxsize = 1024 * 1024;
|
|||
//nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize));
|
|||
} |
|||
//if ( ispaired != 0 )
|
|||
{ |
|||
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); |
|||
nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); |
|||
} |
|||
nanomsg_transportname(0,pushaddr,myipaddr,publicport); |
|||
nanomsg_transportname(0,subaddr,myipaddr,subport); |
|||
LP_psockadd(ispaired,pullsock,publicport,pubsock,subport,subaddr,pushaddr); |
|||
jaddstr(retjson,"result","success"); |
|||
jaddstr(retjson,"LPipaddr",myipaddr); |
|||
jaddstr(retjson,"connectaddr",subaddr); |
|||
jaddnum(retjson,"connectport",subport); |
|||
jaddnum(retjson,"ispaired",ispaired); |
|||
jaddstr(retjson,"publicaddr",pushaddr); |
|||
jaddnum(retjson,"publicport",publicport); |
|||
printf("i.%d publicaddr.(%s) for subaddr.(%s), pullsock.%d pubsock.%d\n",i,pushaddr,subaddr,pullsock,pubsock); |
|||
break; |
|||
} else printf("bind error on %s or %s\n",pushaddr,subaddr); |
|||
if ( pullsock >= 0 ) |
|||
nn_close(pullsock); |
|||
if ( pubsock >= 0 ) |
|||
nn_close(pubsock); |
|||
} |
|||
} |
|||
if ( Psockport > MAX_PSOCK_PORT ) |
|||
Psockport = MIN_PSOCK_PORT; |
|||
if ( i == maxiters ) |
|||
jaddstr(retjson,"error","cant find psock ports"); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
|
|||
/*
|
|||
LP_pushaddr_get makes transparent the fact that most nodes cannot bind()! |
|||
|
|||
The idea is to create an LP node NN_PAIR sock that the LP node binds to and client node connects to. Additionally, the LP node creates an NN_PULL that other nodes can NN_PUSH to and returns this address in pushaddr/retval for the client node to register with. The desired result is that other than the initial LP node, all the other nodes do a normal NN_PUSH, requiring no change to the NN_PUSH/NN_PULL logic. Of course, the initial LP node needs to autoforward all packets from the public NN_PULL to the NN_PUB |
|||
|
|||
similar to LP_pushaddr_get, create an NN_PAIR for DEX atomic data, can be assumed to have a max lifetime of 2*INSTANTDEX_LOCKTIME |
|||
|
|||
both are combined in LP_psock_get |
|||
|
|||
*/ |
|||
char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired) |
|||
{ |
|||
char url[512],*retstr; |
|||
sprintf(url,"http://%s:%u/api/stats/psock?ispaired=%d",destip,destport,ispaired); |
|||
//return(LP_issue_curl("psock",destip,destport,url));
|
|||
retstr = issue_curlt(url,LP_HTTP_TIMEOUT*3); |
|||
printf("issue_LP_psock got (%s) from %s\n",retstr,destip); |
|||
return(retstr); |
|||
} |
|||
|
|||
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired) |
|||
{ |
|||
uint16_t publicport = 0; char *retstr,*addr; cJSON *retjson; struct LP_peerinfo *peer,*tmp; |
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
connectaddr[0] = publicaddr[0] = 0; |
|||
if ( peer->errors < LP_MAXPEER_ERRORS && (retstr= issue_LP_psock(peer->ipaddr,peer->port,ispaired)) != 0 ) |
|||
{ |
|||
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|||
{ |
|||
printf("from %s:%u (%s)\n",peer->ipaddr,peer->port,retstr); |
|||
if ( (addr= jstr(retjson,"publicaddr")) != 0 ) |
|||
safecopy(publicaddr,addr,128); |
|||
if ( (addr= jstr(retjson,"connectaddr")) != 0 ) |
|||
safecopy(connectaddr,addr,128); |
|||
if ( publicaddr[0] != 0 && connectaddr[0] != 0 ) |
|||
publicport = juint(retjson,"publicport"); |
|||
free_json(retjson); |
|||
} |
|||
printf("got.(%s) connect.%s public.%s\n",retstr,connectaddr,publicaddr); |
|||
free(retstr); |
|||
} else printf("error psock from %s:%u\n",peer->ipaddr,peer->port); |
|||
if ( publicport != 0 ) |
|||
break; |
|||
} |
|||
return(publicport); |
|||
} |
|||
|
|||
int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char *myipaddr,uint16_t mypullport,int32_t ispaired) |
|||
{ |
|||
int32_t nntype,pullsock,timeout; char bindaddr[128],connectaddr[128]; |
|||
*mypullportp = mypullport; |
|||
if ( ispaired == 0 ) |
|||
{ |
|||
if ( LP_canbind != 0 ) |
|||
nntype = LP_COMMAND_RECVSOCK; |
|||
else nntype = NN_PAIR;//NN_SUB;
|
|||
} else nntype = NN_PAIR; |
|||
if ( LP_canbind != 0 ) |
|||
{ |
|||
nanomsg_transportname(0,publicaddr,myipaddr,mypullport); |
|||
nanomsg_transportname(1,bindaddr,myipaddr,mypullport); |
|||
} |
|||
else |
|||
{ |
|||
*mypullportp = 0; |
|||
if ( ispaired == 0 ) |
|||
{ |
|||
strcpy(publicaddr,"127.0.0.1"); |
|||
return(-1); |
|||
} |
|||
while ( *mypullportp == 0 ) |
|||
{ |
|||
if ( (*mypullportp= LP_psock_get(connectaddr,publicaddr,ispaired)) != 0 ) |
|||
break; |
|||
sleep(10); |
|||
printf("try to get publicaddr again\n"); |
|||
} |
|||
} |
|||
while ( 1 ) |
|||
{ |
|||
if ( (pullsock= nn_socket(AF_SP,nntype)) >= 0 ) |
|||
{ |
|||
if ( LP_canbind == 0 ) |
|||
{ |
|||
if ( nn_connect(pullsock,connectaddr) < 0 ) |
|||
{ |
|||
printf("bind to %s error for %s: %s\n",connectaddr,publicaddr,nn_strerror(nn_errno())); |
|||
exit(-1); |
|||
} else printf("nntype.%d NN_PAIR.%d connect to %s connectsock.%d\n",nntype,NN_PAIR,connectaddr,pullsock); |
|||
} |
|||
else |
|||
{ |
|||
if ( nn_bind(pullsock,bindaddr) < 0 ) |
|||
{ |
|||
printf("bind to %s error for %s: %s\n",bindaddr,publicaddr,nn_strerror(nn_errno())); |
|||
exit(-1); |
|||
} |
|||
} |
|||
timeout = 1; |
|||
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); |
|||
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); |
|||
//maxsize = 2 * 1024 * 1024;
|
|||
//nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize));
|
|||
if ( nntype == NN_SUB ) |
|||
nn_setsockopt(pullsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0); |
|||
} |
|||
//if ( LP_canbind != 0 || ispaired != 0 || nn_tests(ctx,pullsock,publicaddr,NN_PUSH) >= 0 )
|
|||
// break;
|
|||
//printf("nn_tests failed, try again\n");
|
|||
//sleep(3);
|
|||
break; |
|||
if ( pullsock >= 0 ) |
|||
nn_close(pullsock); |
|||
} |
|||
return(pullsock); |
|||
} |
@ -0,0 +1,792 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
|
|||
//
|
|||
// LP_ordermatch.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
uint64_t LP_txfeecalc(char *symbol,uint64_t txfee) |
|||
{ |
|||
struct iguana_info *coin; |
|||
if ( strcmp(symbol,"BTC") == 0 ) |
|||
{ |
|||
if ( txfee == 0 && (txfee= LP_getestimatedrate(symbol) * LP_AVETXSIZE) < LP_MIN_TXFEE ) |
|||
txfee = LP_MIN_TXFEE; |
|||
} |
|||
else if ( (coin= LP_coinfind(symbol)) != 0 ) |
|||
txfee = coin->txfee; |
|||
if ( txfee < LP_MIN_TXFEE ) |
|||
txfee = LP_MIN_TXFEE; |
|||
return(txfee); |
|||
} |
|||
|
|||
void LP_txfees(uint64_t *txfeep,uint64_t *desttxfeep,char *base,char *rel) |
|||
{ |
|||
*txfeep = LP_txfeecalc(base,0); |
|||
*desttxfeep = LP_txfeecalc(rel,0); |
|||
} |
|||
|
|||
double LP_qprice_calc(int64_t *destsatoshisp,int64_t *satoshisp,double price,uint64_t b_satoshis,uint64_t txfee,uint64_t a_value,uint64_t maxdestsatoshis,uint64_t desttxfee) |
|||
{ |
|||
uint64_t destsatoshis,satoshis; |
|||
a_value -= (desttxfee + 1); |
|||
destsatoshis = ((b_satoshis - txfee) * price); |
|||
if ( destsatoshis > a_value ) |
|||
destsatoshis = a_value; |
|||
if ( maxdestsatoshis != 0 && destsatoshis > maxdestsatoshis-desttxfee-1 ) |
|||
destsatoshis = maxdestsatoshis-desttxfee-1; |
|||
satoshis = (destsatoshis / price + 0.49) - txfee; |
|||
*destsatoshisp = destsatoshis; |
|||
*satoshisp = satoshis; |
|||
if ( satoshis > 0 ) |
|||
return((double)destsatoshis / satoshis); |
|||
else return(0.); |
|||
} |
|||
|
|||
struct basilisk_request *LP_requestinit(struct basilisk_request *rp,bits256 srchash,bits256 desthash,char *src,uint64_t srcsatoshis,char *dest,uint64_t destsatoshis,uint32_t timestamp,uint32_t quotetime,int32_t DEXselector) |
|||
{ |
|||
struct basilisk_request R; |
|||
memset(rp,0,sizeof(*rp)); |
|||
rp->srchash = srchash; |
|||
rp->srcamount = srcsatoshis; |
|||
rp->timestamp = timestamp; |
|||
rp->DEXselector = DEXselector; |
|||
safecopy(rp->src,src,sizeof(rp->src)); |
|||
safecopy(rp->dest,dest,sizeof(rp->dest)); |
|||
R = *rp; |
|||
rp->requestid = basilisk_requestid(rp); |
|||
rp->quotetime = quotetime; |
|||
rp->desthash = desthash; |
|||
rp->destamount = destsatoshis; |
|||
rp->quoteid = basilisk_quoteid(rp); |
|||
printf("r.%u %u, q.%u %u: %s %.8f -> %s %.8f\n",rp->timestamp,rp->requestid,rp->quotetime,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount)); |
|||
return(rp); |
|||
} |
|||
|
|||
cJSON *LP_quotejson(struct LP_quoteinfo *qp) |
|||
{ |
|||
double price; cJSON *retjson = cJSON_CreateObject(); |
|||
jaddstr(retjson,"base",qp->srccoin); |
|||
jaddstr(retjson,"rel",qp->destcoin); |
|||
if ( qp->coinaddr[0] != 0 ) |
|||
jaddstr(retjson,"address",qp->coinaddr); |
|||
if ( qp->timestamp != 0 ) |
|||
jaddnum(retjson,"timestamp",qp->timestamp); |
|||
if ( bits256_nonz(qp->txid) != 0 ) |
|||
{ |
|||
jaddbits256(retjson,"txid",qp->txid); |
|||
jaddnum(retjson,"vout",qp->vout); |
|||
} |
|||
if ( bits256_nonz(qp->srchash) != 0 ) |
|||
jaddbits256(retjson,"srchash",qp->srchash); |
|||
if ( qp->txfee != 0 ) |
|||
jadd64bits(retjson,"txfee",qp->txfee); |
|||
if ( qp->quotetime != 0 ) |
|||
jaddnum(retjson,"quotetime",qp->quotetime); |
|||
if ( qp->satoshis != 0 ) |
|||
jadd64bits(retjson,"satoshis",qp->satoshis); |
|||
if ( bits256_nonz(qp->desthash) != 0 ) |
|||
jaddbits256(retjson,"desthash",qp->desthash); |
|||
if ( bits256_nonz(qp->txid2) != 0 ) |
|||
{ |
|||
jaddbits256(retjson,"txid2",qp->txid2); |
|||
jaddnum(retjson,"vout2",qp->vout2); |
|||
} |
|||
if ( bits256_nonz(qp->desttxid) != 0 ) |
|||
{ |
|||
if ( qp->destaddr[0] != 0 ) |
|||
jaddstr(retjson,"destaddr",qp->destaddr); |
|||
jaddbits256(retjson,"desttxid",qp->desttxid); |
|||
jaddnum(retjson,"destvout",qp->destvout); |
|||
} |
|||
if ( bits256_nonz(qp->feetxid) != 0 ) |
|||
{ |
|||
jaddbits256(retjson,"feetxid",qp->feetxid); |
|||
jaddnum(retjson,"feevout",qp->feevout); |
|||
} |
|||
if ( qp->desttxfee != 0 ) |
|||
jadd64bits(retjson,"desttxfee",qp->desttxfee); |
|||
if ( qp->destsatoshis != 0 ) |
|||
{ |
|||
jadd64bits(retjson,"destsatoshis",qp->destsatoshis); |
|||
if ( qp->satoshis != 0 ) |
|||
{ |
|||
price = (double)qp->destsatoshis / qp->satoshis; |
|||
jaddnum(retjson,"price",price); |
|||
} |
|||
} |
|||
return(retjson); |
|||
} |
|||
|
|||
int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson) |
|||
{ |
|||
safecopy(qp->srccoin,jstr(argjson,"base"),sizeof(qp->srccoin)); |
|||
safecopy(qp->coinaddr,jstr(argjson,"address"),sizeof(qp->coinaddr)); |
|||
safecopy(qp->destcoin,jstr(argjson,"rel"),sizeof(qp->destcoin)); |
|||
safecopy(qp->destaddr,jstr(argjson,"destaddr"),sizeof(qp->destaddr)); |
|||
qp->timestamp = juint(argjson,"timestamp"); |
|||
qp->quotetime = juint(argjson,"quotetime"); |
|||
qp->txid = jbits256(argjson,"txid"); |
|||
qp->txid2 = jbits256(argjson,"txid2"); |
|||
qp->vout = jint(argjson,"vout"); |
|||
qp->vout2 = jint(argjson,"vout2"); |
|||
qp->feevout = jint(argjson,"feevout"); |
|||
qp->srchash = jbits256(argjson,"srchash"); |
|||
qp->desttxid = jbits256(argjson,"desttxid"); |
|||
qp->feetxid = jbits256(argjson,"feetxid"); |
|||
qp->destvout = jint(argjson,"destvout"); |
|||
qp->desthash = jbits256(argjson,"desthash"); |
|||
qp->satoshis = j64bits(argjson,"satoshis"); |
|||
qp->destsatoshis = j64bits(argjson,"destsatoshis"); |
|||
qp->txfee = j64bits(argjson,"txfee"); |
|||
qp->desttxfee = j64bits(argjson,"desttxfee"); |
|||
return(0); |
|||
} |
|||
|
|||
int32_t LP_quoteinfoinit(struct LP_quoteinfo *qp,struct LP_utxoinfo *utxo,char *destcoin,double price,uint64_t satoshis,uint64_t destsatoshis) |
|||
{ |
|||
memset(qp,0,sizeof(*qp)); |
|||
if ( qp->timestamp == 0 ) |
|||
qp->timestamp = (uint32_t)time(NULL); |
|||
safecopy(qp->destcoin,destcoin,sizeof(qp->destcoin)); |
|||
LP_txfees(&qp->txfee,&qp->desttxfee,utxo->coin,qp->destcoin); |
|||
qp->satoshis = satoshis;//(destsatoshis / price) + 0.49;
|
|||
qp->destsatoshis = destsatoshis; |
|||
if ( utxo->iambob == 0 || qp->txfee >= qp->satoshis || qp->txfee >= utxo->deposit.value || utxo->deposit.value < LP_DEPOSITSATOSHIS(qp->satoshis) ) |
|||
{ |
|||
printf("quoteinit error.(%d %d %d %d) %.8f vs %.8f\n",utxo->iambob == 0,qp->txfee >= qp->satoshis,qp->txfee >= utxo->deposit.value,utxo->deposit.value < LP_DEPOSITSATOSHIS(qp->satoshis),dstr(utxo->deposit.value),dstr(LP_DEPOSITSATOSHIS(qp->satoshis))); |
|||
return(-1); |
|||
} |
|||
qp->txid = utxo->payment.txid; |
|||
qp->vout = utxo->payment.vout; |
|||
qp->txid2 = utxo->deposit.txid; |
|||
qp->vout2 = utxo->deposit.vout; |
|||
if ( qp->desttxfee >= qp->destsatoshis ) |
|||
{ |
|||
printf("quoteinit desttxfee %.8f < %.8f destsatoshis\n",dstr(qp->desttxfee),dstr(qp->destsatoshis)); |
|||
return(-2); |
|||
} |
|||
safecopy(qp->srccoin,utxo->coin,sizeof(qp->srccoin)); |
|||
safecopy(qp->coinaddr,utxo->coinaddr,sizeof(qp->coinaddr)); |
|||
qp->srchash = utxo->pubkey; |
|||
return(0); |
|||
} |
|||
|
|||
int32_t LP_quotedestinfo(struct LP_quoteinfo *qp,bits256 desttxid,int32_t destvout,bits256 feetxid,int32_t feevout,bits256 desthash,char *destaddr) |
|||
{ |
|||
qp->desttxid = desttxid; |
|||
qp->destvout = destvout; |
|||
qp->desthash = desthash; |
|||
qp->feetxid = feetxid; |
|||
qp->feevout = feevout; |
|||
safecopy(qp->destaddr,destaddr,sizeof(qp->destaddr)); |
|||
return(0); |
|||
} |
|||
|
|||
char *LP_quotereceived(cJSON *argjson) |
|||
{ |
|||
struct LP_cacheinfo *ptr; double price; struct LP_quoteinfo Q; |
|||
LP_quoteparse(&Q,argjson); |
|||
price = (double)Q.destsatoshis / Q.satoshis; |
|||
if ( (ptr= LP_cacheadd(Q.srccoin,Q.destcoin,Q.txid,Q.vout,price,&Q)) != 0 ) |
|||
{ |
|||
ptr->Q = Q; |
|||
printf(">>>>>>>>>> received quote %s/%s %.8f\n",Q.srccoin,Q.destcoin,price); |
|||
return(clonestr("{\"result\":\"updated\"}")); |
|||
} else return(clonestr("{\"error\":\"nullptr\"}")); |
|||
} |
|||
|
|||
char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price) |
|||
{ |
|||
bits256 zero; char *msg; cJSON *reqjson = cJSON_CreateObject(); |
|||
memset(zero.bytes,0,sizeof(zero)); |
|||
jaddbits256(reqjson,"pubkey",LP_mypub25519); |
|||
jaddstr(reqjson,"base",base); |
|||
jaddstr(reqjson,"rel",rel); |
|||
jaddnum(reqjson,"price",price); |
|||
jaddstr(reqjson,"method","postprice"); |
|||
msg = jprint(reqjson,1); |
|||
LP_broadcast_message(pubsock,base,rel,zero,msg); |
|||
return(clonestr("{\"result\":\"success\"}")); |
|||
} |
|||
|
|||
char *LP_postedprice(cJSON *argjson) |
|||
{ |
|||
bits256 pubkey; double price; char *base,*rel; |
|||
//printf("PRICE POSTED.(%s)\n",jprint(argjson,0));
|
|||
if ( (base= jstr(argjson,"base")) != 0 && (rel= jstr(argjson,"rel")) != 0 && (price= jdouble(argjson,"price")) > SMALLVAL ) |
|||
{ |
|||
pubkey = jbits256(argjson,"pubkey"); |
|||
if ( bits256_nonz(pubkey) != 0 ) |
|||
{ |
|||
LP_pricefeedupdate(pubkey,base,rel,price); |
|||
return(clonestr("{\"result\":\"success\"}")); |
|||
} |
|||
} |
|||
return(clonestr("{\"error\":\"missing fields in posted price\"}")); |
|||
} |
|||
|
|||
int32_t LP_quote_checkmempool(struct LP_quoteinfo *qp) |
|||
{ |
|||
int32_t selector,spendvini; bits256 spendtxid; |
|||
if ( (selector= LP_mempool_vinscan(&spendtxid,&spendvini,qp->srccoin,qp->txid,qp->vout,qp->txid2,qp->vout2)) >= 0 ) |
|||
{ |
|||
char str[65]; printf("LP_tradecommand selector.%d in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); |
|||
return(-1); |
|||
} |
|||
if ( (selector= LP_mempool_vinscan(&spendtxid,&spendvini,qp->destcoin,qp->desttxid,qp->destvout,qp->feetxid,qp->feevout)) >= 0 ) |
|||
{ |
|||
char str[65]; printf("LP_tradecommand dest selector.%d in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); |
|||
return(-1); |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
double LP_quote_validate(struct LP_utxoinfo **autxop,struct LP_utxoinfo **butxop,struct LP_quoteinfo *qp,int32_t iambob) |
|||
{ |
|||
double qprice; uint64_t txfee,desttxfee,srcvalue,srcvalue2,destvalue,destvalue2; |
|||
*autxop = *butxop = 0; |
|||
if ( LP_iseligible(&srcvalue,&srcvalue2,1,qp->srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 ) |
|||
{ |
|||
printf("bob not eligible\n"); |
|||
return(-2); |
|||
} |
|||
if ( LP_iseligible(&destvalue,&destvalue2,0,qp->destcoin,qp->desttxid,qp->destvout,qp->destsatoshis,qp->feetxid,qp->feevout) == 0 ) |
|||
{ |
|||
char str[65]; printf("alice not eligible (%.8f %.8f) %s/v%d\n",dstr(destvalue),dstr(destvalue2),bits256_str(str,qp->feetxid),qp->feevout); |
|||
return(-3); |
|||
} |
|||
if ( LP_quote_checkmempool(qp) < 0 ) |
|||
return(-4); |
|||
if ( (*butxop= LP_utxofind(1,qp->txid,qp->vout)) == 0 ) |
|||
return(-5); |
|||
if ( bits256_cmp((*butxop)->deposit.txid,qp->txid2) != 0 || (*butxop)->deposit.vout != qp->vout2 ) |
|||
return(-6); |
|||
if ( strcmp((*butxop)->coinaddr,qp->coinaddr) != 0 ) |
|||
return(-7); |
|||
if ( iambob == 0 ) |
|||
{ |
|||
if ( (*autxop= LP_utxofind(0,qp->desttxid,qp->destvout)) == 0 ) |
|||
return(-8); |
|||
if ( bits256_cmp((*autxop)->fee.txid,qp->feetxid) != 0 || (*autxop)->fee.vout != qp->feevout ) |
|||
return(-9); |
|||
if ( strcmp((*autxop)->coinaddr,qp->destaddr) != 0 ) |
|||
return(-10); |
|||
} |
|||
if ( destvalue < qp->desttxfee+qp->destsatoshis || srcvalue < qp->txfee+qp->satoshis ) |
|||
{ |
|||
printf("destvalue %.8f srcvalue %.8f, destsatoshis %.8f or satoshis %.8f is too small txfees %.8f %.8f?\n",dstr(destvalue),dstr(srcvalue),dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->desttxfee),dstr(qp->txfee)); |
|||
return(-11); |
|||
} |
|||
qprice = ((double)qp->destsatoshis / qp->satoshis); |
|||
if ( qp->satoshis < (srcvalue / LP_MINVOL) || srcvalue < qp->txfee*LP_MINSIZE_TXFEEMULT ) |
|||
{ |
|||
printf("utxo payment %.8f is less than %f covered by Q %.8f or <10x txfee %.8f\n",dstr(srcvalue),1./LP_MINVOL,dstr(qp->satoshis),dstr(qp->txfee)); |
|||
return(-12); |
|||
} |
|||
if ( qp->destsatoshis < (destvalue / LP_MINCLIENTVOL) || destvalue < qp->desttxfee*LP_MINSIZE_TXFEEMULT ) |
|||
{ |
|||
printf("destsatoshis %.8f is less than %f of value %.8f or < 10x txfee %.8f\n",dstr(qp->destsatoshis),1./LP_MINCLIENTVOL,dstr(destvalue),dstr(qp->desttxfee)); |
|||
return(-13); |
|||
} |
|||
LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); |
|||
printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee)); |
|||
if ( qp->txfee < LP_REQUIRED_TXFEE*txfee || qp->desttxfee < LP_REQUIRED_TXFEE*desttxfee ) |
|||
return(-14); |
|||
return(qprice); |
|||
} |
|||
|
|||
int32_t LP_arrayfind(cJSON *array,bits256 txid,int32_t vout) |
|||
{ |
|||
int32_t i,n = cJSON_GetArraySize(array); cJSON *item; |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
if ( vout == jint(item,"vout") && bits256_cmp(txid,jbits256(item,"txid")) == 0 ) |
|||
return(i); |
|||
} |
|||
return(-1); |
|||
} |
|||
|
|||
double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) |
|||
{ |
|||
cJSON *reqjson; char *msg; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo; |
|||
if ( strcmp(method,"request") == 0 ) |
|||
{ |
|||
if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 ) |
|||
LP_unavailableset(utxo,qp->srchash); |
|||
else |
|||
{ |
|||
printf("couldnt find my txid to make request\n"); |
|||
return(0.); |
|||
} |
|||
} |
|||
reqjson = LP_quotejson(qp); |
|||
if ( bits256_nonz(qp->desthash) != 0 ) |
|||
flag = 1; |
|||
jaddbits256(reqjson,"pubkey",qp->srchash); |
|||
jaddstr(reqjson,"method",method); |
|||
msg = jprint(reqjson,1); |
|||
printf("QUERY.(%s)\n",msg); |
|||
LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg); |
|||
for (i=0; i<30; i++) |
|||
{ |
|||
if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL ) |
|||
{ |
|||
if ( flag == 0 || bits256_nonz(qp->desthash) != 0 ) |
|||
{ |
|||
printf("break out of loop.%d price %.8f %s/%s\n",i,price,qp->srccoin,qp->destcoin); |
|||
break; |
|||
} |
|||
} |
|||
usleep(100000); |
|||
} |
|||
return(price); |
|||
} |
|||
|
|||
int32_t LP_nanobind(void *ctx,char *pairstr) |
|||
{ |
|||
int32_t i,r,pairsock = -1; uint16_t mypullport; char bindaddr[128]; |
|||
if ( LP_canbind != 0 ) |
|||
{ |
|||
if ( (pairsock= nn_socket(AF_SP,NN_PAIR)) < 0 ) |
|||
printf("error creating utxo->pair\n"); |
|||
else |
|||
{ |
|||
for (i=0; i<10; i++) |
|||
{ |
|||
r = (10000 + (rand() % 50000)) & 0xffff; |
|||
if ( LP_fixed_pairport != 0 ) |
|||
r = LP_fixed_pairport; |
|||
nanomsg_transportname(0,pairstr,LP_myipaddr,r); |
|||
nanomsg_transportname(1,bindaddr,LP_myipaddr,r); |
|||
if ( nn_bind(pairsock,bindaddr) >= 0 ) |
|||
{ |
|||
//timeout = 1;
|
|||
//nn_setsockopt(pairsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
|
|||
//nn_setsockopt(pairsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
|
|||
printf("nanobind %s to %d\n",pairstr,pairsock); |
|||
return(pairsock); |
|||
} else printf("error binding to %s for %s\n",bindaddr,pairstr); |
|||
if ( LP_fixed_pairport != 0 ) |
|||
break; |
|||
} |
|||
} |
|||
} else pairsock = LP_initpublicaddr(ctx,&mypullport,pairstr,"127.0.0.1",0,1); |
|||
return(pairsock); |
|||
} |
|||
|
|||
int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJSON *argjson,char *base,char *rel,double price,struct LP_quoteinfo *qp) |
|||
{ |
|||
char pairstr[512],*msg; cJSON *retjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; struct basilisk_swap *swap; struct iguana_info *coin; |
|||
printf("LP_connectstartbob.(%s) with.(%s) %s\n",LP_myipaddr,jprint(argjson,0),LP_myipaddr); |
|||
qp->quotetime = (uint32_t)time(NULL); |
|||
if ( (coin= LP_coinfind(utxo->coin)) == 0 ) |
|||
{ |
|||
printf("cant find coin.%s\n",utxo->coin); |
|||
return(-1); |
|||
} |
|||
privkey = LP_privkey(utxo->coinaddr,coin->taddr); |
|||
if ( bits256_nonz(privkey) != 0 && qp->quotetime >= qp->timestamp-3 && qp->quotetime <= utxo->T.swappending && bits256_cmp(LP_mypub25519,qp->srchash) == 0 ) |
|||
{ |
|||
if ( (pair= LP_nanobind(ctx,pairstr)) >= 0 ) |
|||
{ |
|||
LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); |
|||
swap = LP_swapinit(1,0,privkey,&qp->R,qp); |
|||
swap->N.pair = pair; |
|||
utxo->S.swap = swap; |
|||
swap->utxo = utxo; |
|||
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_bobloop,(void *)swap) == 0 ) |
|||
{ |
|||
retjson = LP_quotejson(qp); |
|||
jaddstr(retjson,"method","connected"); |
|||
jaddstr(retjson,"pair",pairstr); |
|||
jaddnum(retjson,"requestid",qp->R.requestid); |
|||
jaddnum(retjson,"quoteid",qp->R.quoteid); |
|||
char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,utxo->S.otherpubkey)); |
|||
msg = jprint(retjson,1); |
|||
LP_broadcast_message(pubsock,base,rel,utxo->S.otherpubkey,msg); |
|||
retval = 0; |
|||
} else printf("error launching swaploop\n"); |
|||
} else printf("couldnt bind to any port %s\n",pairstr); |
|||
} |
|||
else |
|||
{ |
|||
printf("dest %.8f vs required %.8f (%d %d %d %d %d)\n",dstr(qp->destsatoshis),dstr(price*(utxo->S.satoshis-qp->txfee)),bits256_nonz(privkey) != 0 ,qp->timestamp == utxo->T.swappending-LP_RESERVETIME,qp->quotetime >= qp->timestamp-3,qp->quotetime < utxo->T.swappending,bits256_cmp(LP_mypub25519,qp->srchash) == 0); |
|||
} |
|||
if ( retval < 0 ) |
|||
{ |
|||
if ( pair >= 0 ) |
|||
nn_close(pair); |
|||
LP_availableset(utxo); |
|||
} else LP_unavailableset(utxo,utxo->S.otherpubkey); |
|||
return(retval); |
|||
} |
|||
|
|||
char *LP_connectedalice(cJSON *argjson) // alice
|
|||
{ |
|||
cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; |
|||
if ( LP_quoteparse(&Q,argjson) < 0 ) |
|||
clonestr("{\"error\":\"cant parse quote\"}"); |
|||
if ( bits256_cmp(Q.desthash,LP_mypub25519) != 0 ) |
|||
return(clonestr("{\"result\",\"update stats\"}")); |
|||
printf("CONNECTED.(%s)\n",jprint(argjson,0)); |
|||
if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) |
|||
{ |
|||
LP_availableset(autxo); |
|||
LP_pendingswaps--; |
|||
printf("quote validate error %.0f\n",qprice); |
|||
return(clonestr("{\"error\":\"quote validation error\"}")); |
|||
} |
|||
if ( LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin) <= SMALLVAL || bid <= SMALLVAL ) |
|||
{ |
|||
printf("this node has no price for %s/%s (%.8f %.8f)\n",Q.destcoin,Q.srccoin,bid,ask); |
|||
LP_availableset(autxo); |
|||
LP_pendingswaps--; |
|||
return(clonestr("{\"error\":\"no price set\"}")); |
|||
} |
|||
printf("%s/%s bid %.8f ask %.8f\n",Q.srccoin,Q.destcoin,bid,ask); |
|||
//if ( (price= ask) == 0. )
|
|||
price = bid; |
|||
/*if ( SATOSHIDEN*qprice > (SATOSHIDEN * price) * 1.001 + 10 )
|
|||
{ |
|||
printf("qprice %.8f too big vs %.8f\n",qprice,price); |
|||
LP_availableset(autxo); |
|||
LP_pendingswaps--; |
|||
return(clonestr("{\"error\":\"quote price too expensive\"}")); |
|||
}*/ |
|||
if ( (coin= LP_coinfind(Q.destcoin)) == 0 ) |
|||
{ |
|||
LP_pendingswaps--; |
|||
return(clonestr("{\"error\":\"cant get alicecoin\"}")); |
|||
} |
|||
Q.privkey = LP_privkey(Q.destaddr,coin->taddr); |
|||
if ( bits256_nonz(Q.privkey) != 0 && Q.quotetime >= Q.timestamp-3 ) |
|||
{ |
|||
retjson = cJSON_CreateObject(); |
|||
if ( (pairstr= jstr(argjson,"pair")) == 0 || (pairsock= nn_socket(AF_SP,NN_PAIR)) < 0 ) |
|||
jaddstr(retjson,"error","couldnt create pairsock"); |
|||
else if ( nn_connect(pairsock,pairstr) >= 0 ) |
|||
{ |
|||
//timeout = 1;
|
|||
//nn_setsockopt(pairsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
|
|||
//nn_setsockopt(pairsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
|
|||
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector); |
|||
swap = LP_swapinit(0,0,Q.privkey,&Q.R,&Q); |
|||
swap->N.pair = pairsock; |
|||
autxo->S.swap = swap; |
|||
swap->utxo = autxo; |
|||
printf("alice pairstr.(%s) pairsock.%d\n",pairstr,pairsock); |
|||
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_aliceloop,(void *)swap) == 0 ) |
|||
{ |
|||
jaddstr(retjson,"result","success"); |
|||
jadd(retjson,"trade",LP_quotejson(&Q)); |
|||
jaddnum(retjson,"requestid",Q.R.requestid); |
|||
jaddnum(retjson,"quoteid",Q.R.quoteid); |
|||
} else jaddstr(retjson,"error","couldnt aliceloop"); |
|||
} else printf("connect error %s\n",nn_strerror(nn_errno())); |
|||
printf("connected result.(%s)\n",jprint(retjson,0)); |
|||
if ( jobj(retjson,"error") != 0 ) |
|||
LP_availableset(autxo); |
|||
else LP_pendingswaps++; |
|||
return(jprint(retjson,1)); |
|||
} |
|||
else |
|||
{ |
|||
LP_availableset(autxo); |
|||
printf("no privkey found\n"); |
|||
return(clonestr("{\"error\",\"no privkey\"}")); |
|||
} |
|||
} |
|||
|
|||
int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) |
|||
{ |
|||
char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo *autxo,*butxo; int32_t retval = -1; struct LP_quoteinfo Q; |
|||
if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) |
|||
{ |
|||
printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); |
|||
retval = 1; |
|||
if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 ) |
|||
{ |
|||
if ( (price= LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin)) <= SMALLVAL || ask <= SMALLVAL ) |
|||
{ |
|||
printf("this node has no price for %s/%s\n",Q.srccoin,Q.destcoin); |
|||
return(-3); |
|||
} |
|||
price = ask; |
|||
if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,1)) <= SMALLVAL ) |
|||
{ |
|||
printf("quote validate error %.0f\n",qprice); |
|||
return(-4); |
|||
} |
|||
if ( qprice < (price - 0.00000001) * 0.9999 ) |
|||
{ |
|||
printf("(%.8f %.8f) quote price %.8f too low vs %.8f for %s/%s\n",bid,ask,qprice,price,Q.srccoin,Q.destcoin); |
|||
return(-5); |
|||
} |
|||
if ( butxo->S.swap == 0 && time(NULL) > butxo->T.swappending ) |
|||
butxo->T.swappending = 0; |
|||
if ( strcmp(method,"request") == 0 ) // bob needs apayment + fee tx's
|
|||
{ |
|||
if ( LP_isavailable(butxo) > 0 ) |
|||
{ |
|||
butxo->T.swappending = Q.timestamp + LP_RESERVETIME; |
|||
retjson = LP_quotejson(&Q); |
|||
butxo->S.otherpubkey = jbits256(argjson,"desthash"); |
|||
LP_unavailableset(butxo,butxo->S.otherpubkey); |
|||
jaddnum(retjson,"quotetime",juint(argjson,"quotetime")); |
|||
jaddnum(retjson,"pending",butxo->T.swappending); |
|||
jaddbits256(retjson,"desthash",butxo->S.otherpubkey); |
|||
jaddbits256(retjson,"pubkey",butxo->S.otherpubkey); |
|||
jaddstr(retjson,"method","reserved"); |
|||
msg = jprint(retjson,1); |
|||
printf("set swappending.%u accept qprice %.8f, min %.8f\n(%s)",butxo->T.swappending,qprice,price,msg); |
|||
LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); |
|||
butxo->T.lasttime = (uint32_t)time(NULL); |
|||
} else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); |
|||
} |
|||
else if ( strcmp(method,"connect") == 0 ) // bob
|
|||
{ |
|||
retval = 4; |
|||
if ( butxo->T.swappending != 0 && butxo->S.swap == 0 ) |
|||
LP_connectstartbob(ctx,pubsock,butxo,argjson,Q.srccoin,Q.destcoin,qprice,&Q); |
|||
else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); |
|||
} |
|||
} |
|||
} |
|||
return(retval); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,uint64_t maxdestsatoshis) |
|||
{ |
|||
int64_t satoshis,destsatoshis; uint64_t val,val2; bits256 txid,pubkey; char *obookstr; cJSON *orderbook,*asks,*item; struct LP_utxoinfo *butxo,*bestutxo = 0; int32_t i,n,j,vout,numasks; double bestmetric=0.,metric,vol,price,qprice,bestprice = 0.; struct LP_pubkeyinfo *pubp; |
|||
*ordermatchpricep = 0.; |
|||
*bestsatoshisp = *bestdestsatoshisp = 0; |
|||
if ( duration <= 0 ) |
|||
duration = LP_ORDERBOOK_DURATION; |
|||
if ( maxprice <= 0. || LP_priceinfofind(base) == 0 ) |
|||
return(0); |
|||
LP_txfees(&txfee,&desttxfee,base,autxo->coin); |
|||
if ( (obookstr= LP_orderbook(base,autxo->coin,duration)) != 0 ) |
|||
{ |
|||
if ( (orderbook= cJSON_Parse(obookstr)) != 0 ) |
|||
{ |
|||
if ( (asks= jarray(&numasks,orderbook,"asks")) != 0 ) |
|||
{ |
|||
for (i=0; i<numasks; i++) |
|||
{ |
|||
item = jitem(asks,i); |
|||
price = jdouble(item,"price"); |
|||
if ( LP_pricevalid(price) > 0 && price <= maxprice ) |
|||
{ |
|||
//price *= 1.0001;
|
|||
//if ( price > maxprice )
|
|||
// price = maxprice;
|
|||
pubkey = jbits256(item,"pubkey"); |
|||
if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 && pubp->numerrors < LP_MAXPUBKEY_ERRORS ) |
|||
{ |
|||
if ( bestprice == 0. ) // assumes price ordered asks
|
|||
bestprice = price; |
|||
//printf("item.[%d] %s\n",i,jprint(item,0));
|
|||
txid = jbits256(item,"txid"); |
|||
vout = jint(item,"vout"); |
|||
vol = jdouble(item,"volume"); |
|||
metric = price / bestprice; |
|||
if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 )//&& butxo->T.bestflag == 0 )
|
|||
{ |
|||
if ( LP_iseligible(&val,&val2,butxo->iambob,butxo->coin,butxo->payment.txid,butxo->payment.vout,butxo->S.satoshis,butxo->deposit.txid,butxo->deposit.vout) > 0 ) |
|||
{ |
|||
destsatoshis = ((butxo->S.satoshis - txfee) * price); |
|||
satoshis = (destsatoshis / price + 0.49) - txfee; |
|||
if ( satoshis <= 0 ) |
|||
continue; |
|||
qprice = (double)destsatoshis / satoshis; |
|||
n = (int32_t)((double)destsatoshis / desttxfee); |
|||
if ( n < 10 ) |
|||
n = 10; |
|||
else n = 3; |
|||
for (j=0; j<n; j++) |
|||
{ |
|||
if ( (qprice= LP_qprice_calc(&destsatoshis,&satoshis,(price*(100.+j))/100.,butxo->S.satoshis,txfee,autxo->payment.value,maxdestsatoshis,desttxfee)) > price+SMALLVAL ) |
|||
break; |
|||
} |
|||
//printf("j.%d/%d qprice %.8f vs price %.8f best.(%.8f %.8f)\n",j,n,qprice,price,dstr(satoshis),dstr(destsatoshis));
|
|||
if ( metric < 1.2 && destsatoshis > desttxfee && destsatoshis-desttxfee > (autxo->payment.value / LP_MINCLIENTVOL) && satoshis-txfee > (butxo->S.satoshis / LP_MINVOL) && satoshis <= butxo->payment.value-txfee ) |
|||
{ |
|||
printf("value %.8f price %.8f/%.8f best %.8f destsatoshis %.8f * metric %.8f -> (%f)\n",dstr(autxo->payment.value),price,bestprice,bestmetric,dstr(destsatoshis),metric,dstr(destsatoshis) * metric * metric * metric); |
|||
metric = dstr(destsatoshis) * metric * metric * metric; |
|||
if ( bestmetric == 0. || metric < bestmetric ) |
|||
{ |
|||
bestutxo = butxo; |
|||
*ordermatchpricep = price; |
|||
*bestdestsatoshisp = destsatoshis; |
|||
*bestsatoshisp = satoshis; |
|||
bestmetric = metric; |
|||
printf("set best!\n"); |
|||
} |
|||
} // else printf("skip.(%d %d %d %d %d) metric %f destsatoshis %.8f value %.8f destvalue %.8f txfees %.8f %.8f sats %.8f\n",metric < 1.2,destsatoshis > desttxfee,destsatoshis-desttxfee > (autxo->payment.value / LP_MINCLIENTVOL),satoshis-txfee > (butxo->S.satoshis / LP_MINVOL),satoshis < butxo->payment.value-txfee,metric,dstr(destsatoshis),dstr(butxo->S.satoshis),dstr(autxo->payment.value),dstr(txfee),dstr(desttxfee),dstr(satoshis));
|
|||
} |
|||
else |
|||
{ |
|||
printf("ineligible.(%.8f %.8f)\n",price,dstr(butxo->S.satoshis)); |
|||
if ( butxo->T.spentflag == 0 ) |
|||
butxo->T.spentflag = (uint32_t)time(NULL); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if ( butxo != 0 ) |
|||
printf("%llu %llu %d %d %d: ",(long long)(vol*SATOSHIDEN),(long long)butxo->S.satoshis,vol*SATOSHIDEN == butxo->S.satoshis,LP_isavailable(butxo) > 0,LP_ismine(butxo) == 0); |
|||
printf("cant find butxo.%p or value mismatch %.8f != %.8f or bestflag.%d\n",butxo,vol,butxo!=0?dstr(butxo->S.satoshis):0,butxo->T.bestflag); |
|||
} |
|||
} else printf("self trading or blacklisted peer\n"); |
|||
} |
|||
else |
|||
{ |
|||
if ( i == 0 ) |
|||
printf("maxprice %.8f vs %.8f\n",maxprice,price); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
free_json(orderbook); |
|||
} |
|||
free(obookstr); |
|||
} |
|||
if ( bestutxo == 0 || *ordermatchpricep == 0. || *bestdestsatoshisp == 0 ) |
|||
return(0); |
|||
int32_t changed; |
|||
LP_mypriceset(&changed,autxo->coin,base,1. / *ordermatchpricep); |
|||
return(bestutxo); |
|||
} |
|||
|
|||
char *LP_bestfit(char *rel,double relvolume) |
|||
{ |
|||
struct LP_utxoinfo *autxo; |
|||
if ( relvolume <= 0. || LP_priceinfofind(rel) == 0 ) |
|||
return(clonestr("{\"error\":\"invalid parameter\"}")); |
|||
if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 ) |
|||
return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); |
|||
return(jprint(LP_utxojson(autxo),1)); |
|||
} |
|||
|
|||
char *LP_ordermatch(char *base,int64_t txfee,double maxprice,double maxvolume,char *rel,bits256 txid,int32_t vout,bits256 feetxid,int32_t feevout,int64_t desttxfee,int32_t duration) |
|||
{ |
|||
struct LP_quoteinfo Q; int64_t bestsatoshis=0,bestdestsatoshis = 0; double ordermatchprice = 0.; struct LP_utxoinfo *autxo,*bestutxo; |
|||
txfee = LP_txfeecalc(base,txfee); |
|||
desttxfee = LP_txfeecalc(rel,desttxfee); |
|||
if ( (autxo= LP_utxopairfind(0,txid,vout,feetxid,feevout)) == 0 ) |
|||
return(clonestr("{\"error\":\"cant find alice utxopair\"}")); |
|||
if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*maxvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) |
|||
return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); |
|||
if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) |
|||
return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); |
|||
if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) |
|||
return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); |
|||
return(jprint(LP_quotejson(&Q),1)); |
|||
} |
|||
|
|||
char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration) |
|||
{ |
|||
struct LP_utxoinfo *bobutxo,*aliceutxo; cJSON *bestitem=0; int32_t DEXselector=0; uint32_t expiration; double price; struct LP_pubkeyinfo *pubp; |
|||
if ( (aliceutxo= LP_utxopairfind(0,qp->desttxid,qp->destvout,qp->feetxid,qp->feevout)) == 0 ) |
|||
{ |
|||
char str[65],str2[65]; printf("dest.(%s)/v%d fee.(%s)/v%d\n",bits256_str(str,qp->desttxid),qp->destvout,bits256_str(str2,qp->feetxid),qp->feevout); |
|||
return(clonestr("{\"error\":\"cant find alice utxopair\"}")); |
|||
} |
|||
if ( (bobutxo= LP_utxopairfind(1,qp->txid,qp->vout,qp->txid2,qp->vout2)) == 0 ) |
|||
return(clonestr("{\"error\":\"cant find bob utxopair\"}")); |
|||
bobutxo->T.bestflag = (uint32_t)time(NULL); |
|||
//if ( (retstr= LP_registerall(0)) != 0 )
|
|||
// free(retstr);
|
|||
price = LP_query(ctx,myipaddr,mypubsock,"request",qp); |
|||
bestitem = LP_quotejson(qp); |
|||
if ( LP_pricevalid(price) > 0 ) |
|||
{ |
|||
if ( price <= maxprice ) |
|||
{ |
|||
price = LP_query(ctx,myipaddr,mypubsock,"connect",qp); |
|||
LP_requestinit(&qp->R,qp->srchash,qp->desthash,bobutxo->coin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); |
|||
expiration = (uint32_t)time(NULL) + timeout; |
|||
while ( time(NULL) < expiration ) |
|||
{ |
|||
if ( aliceutxo->S.swap != 0 ) |
|||
break; |
|||
sleep(1); |
|||
} |
|||
if ( aliceutxo->S.swap == 0 ) |
|||
{ |
|||
if ( (pubp= LP_pubkeyadd(bobutxo->pubkey)) != 0 ) |
|||
pubp->numerrors++; |
|||
jaddstr(bestitem,"status","couldnt establish connection"); |
|||
} else jaddstr(bestitem,"status","connected"); |
|||
jaddnum(bestitem,"quotedprice",price); |
|||
jaddnum(bestitem,"maxprice",maxprice); |
|||
jaddnum(bestitem,"requestid",qp->R.requestid); |
|||
jaddnum(bestitem,"quoteid",qp->R.quoteid); |
|||
printf("Alice r.%u qp->%u\n",qp->R.requestid,qp->R.quoteid); |
|||
} |
|||
else |
|||
{ |
|||
jaddnum(bestitem,"quotedprice",price); |
|||
jaddnum(bestitem,"maxprice",maxprice); |
|||
jaddstr(bestitem,"status","too expensive"); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
jaddnum(bestitem,"maxprice",maxprice); |
|||
jaddstr(bestitem,"status","no response to request"); |
|||
} |
|||
if ( aliceutxo->S.swap == 0 ) |
|||
LP_availableset(aliceutxo); |
|||
return(jprint(bestitem,0)); |
|||
} |
|||
|
|||
char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration) |
|||
{ |
|||
uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; |
|||
if ( duration <= 0 ) |
|||
duration = LP_ORDERBOOK_DURATION; |
|||
if ( timeout <= 0 ) |
|||
timeout = LP_AUTOTRADE_TIMEOUT; |
|||
if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) |
|||
return(clonestr("{\"error\":\"invalid parameter\"}")); |
|||
if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 ) |
|||
return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); |
|||
LP_txfees(&txfee,&desttxfee,base,rel); |
|||
if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*relvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) |
|||
{ |
|||
printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); |
|||
return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); |
|||
} |
|||
if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) |
|||
return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); |
|||
if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) |
|||
return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); |
|||
if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) |
|||
{ |
|||
printf("quote validate error %.0f\n",qprice); |
|||
return(clonestr("{\"error\":\"quote validation error\"}")); |
|||
} |
|||
printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); |
|||
return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); |
|||
} |
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,253 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_peers.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
struct LP_peerinfo *LP_peerfind(uint32_t ipbits,uint16_t port) |
|||
{ |
|||
struct LP_peerinfo *peer=0; uint64_t ip_port; |
|||
ip_port = ((uint64_t)port << 32) | ipbits; |
|||
portable_mutex_lock(&LP_peermutex); |
|||
HASH_FIND(hh,LP_peerinfos,&ip_port,sizeof(ip_port),peer); |
|||
portable_mutex_unlock(&LP_peermutex); |
|||
return(peer); |
|||
} |
|||
|
|||
cJSON *LP_peerjson(struct LP_peerinfo *peer) |
|||
{ |
|||
cJSON *item = cJSON_CreateObject(); |
|||
jaddstr(item,"ipaddr",peer->ipaddr); |
|||
jaddnum(item,"port",peer->port); |
|||
if ( strcmp(peer->ipaddr,LP_myipaddr) == 0 ) |
|||
{ |
|||
jaddnum(item,"session",LP_sessionid); |
|||
if ( LP_mypeer != 0 ) |
|||
jaddnum(item,"numutxos",LP_mypeer->numutxos); |
|||
} else jaddnum(item,"session",peer->sessionid); |
|||
//jaddnum(item,"profit",peer->profitmargin);
|
|||
return(item); |
|||
} |
|||
|
|||
char *LP_peers() |
|||
{ |
|||
struct LP_peerinfo *peer,*tmp; cJSON *peersjson = cJSON_CreateArray(); |
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
//if ( peer->errors < LP_MAXPEER_ERRORS )
|
|||
jaddi(peersjson,LP_peerjson(peer)); |
|||
} |
|||
return(jprint(peersjson,1)); |
|||
} |
|||
|
|||
struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char *ipaddr,uint16_t port,uint16_t pushport,uint16_t subport,int32_t numpeers,int32_t numutxos,uint32_t sessionid) |
|||
{ |
|||
uint32_t ipbits; int32_t pushsock,subsock,timeout; char checkip[64],pushaddr[64],subaddr[64]; struct LP_peerinfo *peer = 0; |
|||
#ifdef LP_STRICTPEERS |
|||
if ( strncmp("5.9.253",ipaddr,strlen("5.9.253")) != 0 ) |
|||
return(0); |
|||
#endif |
|||
ipbits = (uint32_t)calc_ipbits(ipaddr); |
|||
expand_ipbits(checkip,ipbits); |
|||
if ( strcmp(checkip,ipaddr) == 0 ) |
|||
{ |
|||
if ( (peer= LP_peerfind(ipbits,port)) != 0 ) |
|||
{ |
|||
/*if ( numpeers > peer->numpeers )
|
|||
peer->numpeers = numpeers; |
|||
if ( numutxos > peer->numutxos ) |
|||
peer->numutxos = numutxos; |
|||
if ( peer->sessionid == 0 ) |
|||
peer->sessionid = sessionid;*/ |
|||
} |
|||
else |
|||
{ |
|||
peer = calloc(1,sizeof(*peer)); |
|||
if ( strcmp(peer->ipaddr,LP_myipaddr) == 0 ) |
|||
peer->sessionid = LP_sessionid; |
|||
else peer->sessionid = sessionid; |
|||
peer->pushsock = peer->subsock = pushsock = subsock = -1; |
|||
strcpy(peer->ipaddr,ipaddr); |
|||
if ( pushport != 0 && subport != 0 && (pushsock= nn_socket(AF_SP,NN_PUSH)) >= 0 ) |
|||
{ |
|||
nanomsg_transportname(0,pushaddr,peer->ipaddr,pushport); |
|||
if ( nn_connect(pushsock,pushaddr) >= 0 ) |
|||
{ |
|||
timeout = 1; |
|||
nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); |
|||
//maxsize = 2 * 1024 * 1024;
|
|||
//nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDBUF,&maxsize,sizeof(maxsize));
|
|||
printf("connected to push.(%s) %d\n",pushaddr,pushsock); |
|||
peer->connected = (uint32_t)time(NULL); |
|||
peer->pushsock = pushsock; |
|||
if ( (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) |
|||
{ |
|||
timeout = 1; |
|||
nn_setsockopt(subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); |
|||
nn_setsockopt(subsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0); |
|||
nanomsg_transportname(0,subaddr,peer->ipaddr,subport); |
|||
if ( nn_connect(subsock,subaddr) >= 0 ) |
|||
{ |
|||
peer->subsock = subsock; |
|||
printf("connected to sub.(%s) %d\n",subaddr,peer->subsock); |
|||
} else nn_close(subsock); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
nn_close(pushsock); |
|||
printf("error connecting to push.(%s)\n",pushaddr); |
|||
} |
|||
} else printf("%s pushport.%u subport.%u pushsock.%d\n",ipaddr,pushport,subport,pushsock); |
|||
//peer->profitmargin = profitmargin;
|
|||
peer->ipbits = ipbits; |
|||
peer->port = port; |
|||
peer->ip_port = ((uint64_t)port << 32) | ipbits; |
|||
portable_mutex_lock(&LP_peermutex); |
|||
HASH_ADD(hh,LP_peerinfos,ip_port,sizeof(peer->ip_port),peer); |
|||
if ( mypeer != 0 ) |
|||
{ |
|||
mypeer->numpeers++; |
|||
printf("_LPaddpeer %s -> numpeers.%d mypubsock.%d other.(%d %d)\n",ipaddr,mypeer->numpeers,mypubsock,numpeers,numutxos); |
|||
} else peer->numpeers = 1; // will become mypeer
|
|||
portable_mutex_unlock(&LP_peermutex); |
|||
if ( IAMLP != 0 && mypubsock >= 0 ) |
|||
{ |
|||
struct iguana_info *coin,*ctmp; bits256 zero; char *msg,busaddr[64]; |
|||
msg = jprint(LP_peerjson(peer),1); |
|||
memset(zero.bytes,0,sizeof(zero)); |
|||
//LP_send(mypubsock,msg,(int32_t)strlen(msg)+1,1);
|
|||
LP_broadcast_message(mypubsock,"","",zero,msg); |
|||
if ( 0 ) |
|||
{ |
|||
HASH_ITER(hh,LP_coins,coin,ctmp) |
|||
{ |
|||
if ( coin->bussock >= 0 ) |
|||
{ |
|||
nanomsg_transportname(0,busaddr,peer->ipaddr,coin->busport); |
|||
nn_connect(coin->bussock,busaddr); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} else printf("LP_addpeer: checkip.(%s) vs (%s)\n",checkip,ipaddr); |
|||
return(peer); |
|||
} |
|||
|
|||
int32_t LP_coinbus(uint16_t coin_busport) |
|||
{ |
|||
struct LP_peerinfo *peer,*tmp; char busaddr[64]; int32_t timeout,bussock = -1; |
|||
return(-1); |
|||
if ( IAMLP != 0 && LP_mypeer != 0 && (bussock= nn_socket(AF_SP,NN_BUS)) >= 0 ) |
|||
{ |
|||
timeout = 1; |
|||
nn_setsockopt(bussock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); |
|||
nn_setsockopt(bussock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); |
|||
nanomsg_transportname(0,busaddr,LP_mypeer->ipaddr,coin_busport); |
|||
if ( nn_bind(bussock,busaddr) < 0 ) |
|||
{ |
|||
printf("error binding to coin_busport.%s\n",busaddr); |
|||
nn_close(bussock); |
|||
} |
|||
else |
|||
{ |
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
if ( LP_mypeer->port != peer->port || strcmp(LP_mypeer->ipaddr,peer->ipaddr) != 0 ) |
|||
{ |
|||
nanomsg_transportname(0,busaddr,peer->ipaddr,coin_busport); |
|||
nn_connect(bussock,busaddr); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return(bussock); |
|||
} |
|||
|
|||
int32_t LP_peersparse(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *retstr,uint32_t now) |
|||
{ |
|||
struct LP_peerinfo *peer; uint32_t argipbits; char *argipaddr; uint16_t argport,pushport,subport; cJSON *array,*item; int32_t i,n=0; |
|||
if ( (array= cJSON_Parse(retstr)) != 0 ) |
|||
{ |
|||
if ( (n= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
if ( (argipaddr= jstr(item,"ipaddr")) != 0 && (argport= juint(item,"port")) != 0 ) |
|||
{ |
|||
if ( (pushport= juint(item,"push")) == 0 ) |
|||
pushport = argport + 1; |
|||
if ( (subport= juint(item,"sub")) == 0 ) |
|||
subport = argport + 2; |
|||
argipbits = (uint32_t)calc_ipbits(argipaddr); |
|||
if ( (peer= LP_peerfind(argipbits,argport)) == 0 ) |
|||
{ |
|||
peer = LP_addpeer(mypeer,mypubsock,argipaddr,argport,pushport,subport,jint(item,"numpeers"),jint(item,"numutxos"),juint(item,"session")); |
|||
} |
|||
if ( peer != 0 ) |
|||
{ |
|||
peer->lasttime = now; |
|||
if ( strcmp(argipaddr,destipaddr) == 0 && destport == argport && peer->numpeers != n ) |
|||
peer->numpeers = n; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
free_json(array); |
|||
} |
|||
return(n); |
|||
} |
|||
|
|||
void LP_peersquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *myipaddr,uint16_t myport) |
|||
{ |
|||
char *retstr; struct LP_peerinfo *peer,*tmp; uint32_t now,flag = 0; |
|||
peer = LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport); |
|||
if ( (retstr= issue_LP_getpeers(destipaddr,destport,myipaddr,myport,mypeer!=0?mypeer->numpeers:0,mypeer!=0?mypeer->numutxos:0)) != 0 ) |
|||
{ |
|||
//printf("got.(%s)\n",retstr);
|
|||
now = (uint32_t)time(NULL); |
|||
LP_peersparse(mypeer,mypubsock,destipaddr,destport,retstr,now); |
|||
free(retstr); |
|||
if ( IAMLP != 0 ) |
|||
{ |
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
if ( peer->lasttime != now ) |
|||
{ |
|||
printf("{%s:%u}.%d ",peer->ipaddr,peer->port,peer->lasttime - now); |
|||
flag++; |
|||
if ( (retstr= issue_LP_notify(destipaddr,destport,peer->ipaddr,peer->port,peer->numpeers,0,peer->sessionid)) != 0 ) |
|||
free(retstr); |
|||
} |
|||
} |
|||
if ( flag != 0 ) |
|||
printf(" <- missing peers\n"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
int32_t LP_numpeers() |
|||
{ |
|||
struct LP_peerinfo *peer,*tmp; int32_t numpeers = 0; |
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
numpeers++; |
|||
} |
|||
return(numpeers); |
|||
} |
@ -0,0 +1,577 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_portfolio.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
char LP_portfolio_base[16],LP_portfolio_rel[16]; |
|||
double LP_portfolio_relvolume; |
|||
|
|||
cJSON *LP_portfolio_entry(struct iguana_info *coin) |
|||
{ |
|||
cJSON *item = cJSON_CreateObject(); |
|||
jaddstr(item,"coin",coin->symbol); |
|||
jaddstr(item,"address",coin->smartaddr); |
|||
jaddnum(item,"amount",dstr(coin->maxamount)); |
|||
jaddnum(item,"price",coin->price_kmd); |
|||
jaddnum(item,"kmd_equiv",dstr(coin->kmd_equiv)); |
|||
jaddnum(item,"perc",coin->perc); |
|||
jaddnum(item,"goal",coin->goal); |
|||
jaddnum(item,"goalperc",coin->goalperc); |
|||
jaddnum(item,"relvolume",coin->relvolume); |
|||
jaddnum(item,"force",coin->force); |
|||
jaddnum(item,"balanceA",dstr(coin->balanceA)); |
|||
jaddnum(item,"valuesumA",dstr(coin->valuesumA)); |
|||
if ( coin->valuesumA != 0 ) |
|||
jaddnum(item,"aliceutil",100. * (double)coin->balanceA/coin->valuesumA); |
|||
jaddnum(item,"balanceB",dstr(coin->balanceB)); |
|||
jaddnum(item,"valuesumB",dstr(coin->valuesumB)); |
|||
jaddnum(item,"balance",dstr(coin->maxamount)); |
|||
if ( coin->valuesumB != 0 ) |
|||
jaddnum(item,"bobutil",100. * (double)coin->balanceB/coin->valuesumB); |
|||
return(item); |
|||
} |
|||
|
|||
uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr) |
|||
{ |
|||
cJSON *array,*item; int32_t i,n; uint64_t valuesum,satoshisum,value; |
|||
valuesum = satoshisum = 0; |
|||
if ( (array= LP_listunspent(symbol,coinaddr)) != 0 ) |
|||
{ |
|||
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
value = SATOSHIDEN * jdouble(item,"amount"); |
|||
if ( value == 0 ) |
|||
value = SATOSHIDEN * jdouble(item,"value"); |
|||
valuesum += value; |
|||
} |
|||
} |
|||
free_json(array); |
|||
} |
|||
if ( (array= LP_inventory(symbol,iambob)) != 0 ) |
|||
{ |
|||
if ( (n= cJSON_GetArraySize(array)) > 0 && is_cJSON_Array(array) != 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
//valuesum += j64bits(item,"value") + j64bits(item,"value2");
|
|||
satoshisum += j64bits(item,"satoshis"); |
|||
} |
|||
} |
|||
free_json(array); |
|||
} |
|||
*valuep = valuesum; |
|||
return(satoshisum); |
|||
} |
|||
|
|||
char *LP_portfolio() |
|||
{ |
|||
double maxval = 0.,minval = 0.,goalsum = 0.; uint64_t kmdsum = 0; int32_t iter; cJSON *retjson,*array; struct iguana_info *coin,*tmp,*sellcoin = 0,*buycoin = 0; |
|||
array = cJSON_CreateArray(); |
|||
retjson = cJSON_CreateObject(); |
|||
for (iter=0; iter<2; iter++) |
|||
{ |
|||
HASH_ITER(hh,LP_coins,coin,tmp) |
|||
{ |
|||
if ( coin->inactive != 0 ) |
|||
continue; |
|||
if ( iter == 0 ) |
|||
{ |
|||
LP_privkey_init(-1,coin,LP_mypriv25519,LP_mypub25519); |
|||
coin->balanceA = LP_balance(&coin->valuesumA,0,coin->symbol,coin->smartaddr); |
|||
coin->balanceB = LP_balance(&coin->valuesumB,1,coin->symbol,coin->smartaddr); |
|||
if ( strcmp(coin->symbol,"KMD") != 0 ) |
|||
coin->price_kmd = LP_price(coin->symbol,"KMD"); |
|||
else coin->price_kmd = 1.; |
|||
coin->maxamount = coin->valuesumA; |
|||
if ( coin->valuesumB > coin->maxamount ) |
|||
coin->maxamount = coin->valuesumB; |
|||
coin->kmd_equiv = coin->maxamount * coin->price_kmd; |
|||
kmdsum += coin->kmd_equiv; |
|||
goalsum += coin->goal; |
|||
} |
|||
else |
|||
{ |
|||
coin->relvolume = 0.; |
|||
if ( kmdsum > SMALLVAL ) |
|||
coin->perc = 100. * coin->kmd_equiv / kmdsum; |
|||
if ( goalsum > SMALLVAL && coin->goal > SMALLVAL ) |
|||
{ |
|||
coin->goalperc = 100. * coin->goal / goalsum; |
|||
if ( (coin->force= (coin->goalperc - coin->perc)) < 0. ) |
|||
{ |
|||
coin->force *= -coin->force; |
|||
if ( coin->price_kmd > SMALLVAL ) |
|||
coin->relvolume = (dstr(coin->maxamount) * (coin->perc - coin->goalperc)) / 100.; |
|||
} else coin->force *= coin->force; |
|||
if ( coin->force > maxval ) |
|||
{ |
|||
maxval = coin->force; |
|||
buycoin = coin; |
|||
} |
|||
if ( coin->force < minval ) |
|||
{ |
|||
minval = coin->force; |
|||
sellcoin = coin; |
|||
} |
|||
} else coin->goalperc = coin->force = 0.; |
|||
jaddi(array,LP_portfolio_entry(coin)); |
|||
} |
|||
} |
|||
} |
|||
jaddstr(retjson,"result","success"); |
|||
jaddnum(retjson,"kmd_equiv",dstr(kmdsum)); |
|||
if ( buycoin != 0 ) |
|||
{ |
|||
jaddstr(retjson,"buycoin",buycoin->symbol); |
|||
jaddnum(retjson,"buyforce",maxval); |
|||
} |
|||
if ( sellcoin != 0 ) |
|||
{ |
|||
jaddstr(retjson,"sellcoin",sellcoin->symbol); |
|||
jaddnum(retjson,"sellforce",minval); |
|||
} |
|||
if ( LP_portfolio_relvolume > SMALLVAL ) |
|||
{ |
|||
jaddstr(retjson,"base",LP_portfolio_base); |
|||
jaddstr(retjson,"rel",LP_portfolio_rel); |
|||
jaddnum(retjson,"relvolume",LP_portfolio_relvolume); |
|||
} |
|||
jadd(retjson,"portfolio",array); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
|
|||
char *LP_portfolio_goal(char *symbol,double goal) |
|||
{ |
|||
struct iguana_info *coin,*tmp; int32_t iter,n = 0; double kmdbtc = 50.; |
|||
if ( strcmp(symbol,"*") == 0 ) |
|||
{ |
|||
for (iter=0; iter<2; iter++) |
|||
{ |
|||
HASH_ITER(hh,LP_coins,coin,tmp) |
|||
{ |
|||
if ( coin->inactive != 0 ) |
|||
continue; |
|||
if ( iter == 0 ) |
|||
coin->goal = 0; |
|||
if ( coin->inactive == 0 && strcmp(coin->symbol,"KMD") != 0 && strcmp(coin->symbol,"BTC") != 0 ) |
|||
{ |
|||
if ( iter == 0 ) |
|||
n++; |
|||
else coin->goal = (100. - kmdbtc) / n; |
|||
} |
|||
} |
|||
if ( n == 0 ) |
|||
break; |
|||
} |
|||
if ( (coin= LP_coinfind("KMD")) != 0 && coin->inactive == 0 ) |
|||
coin->goal = kmdbtc * 0.5; |
|||
if ( (coin= LP_coinfind("BTC")) != 0 && coin->inactive == 0 ) |
|||
coin->goal = kmdbtc * 0.5; |
|||
return(LP_portfolio()); |
|||
} |
|||
else if ( (coin= LP_coinfind(symbol)) != 0 && coin->inactive == 0 ) |
|||
{ |
|||
coin->goal = goal; |
|||
printf("set %s goal %f\n",coin->symbol,goal); |
|||
return(LP_portfolio()); |
|||
} else return(clonestr("{\"error\":\"cant set goal for inactive coin\"}")); |
|||
} |
|||
|
|||
int32_t LP_autoprices; |
|||
|
|||
/*int32_t LP_autofill(char *base,char *rel,double maxprice,double totalrelvolume)
|
|||
{ |
|||
struct LP_priceinfo *basepp,*relpp; |
|||
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) |
|||
{ |
|||
basepp->maxprices[relpp->ind] = maxprice; |
|||
basepp->relvols[relpp->ind] = totalrelvolume; |
|||
LP_autofills++; |
|||
return(0); |
|||
} |
|||
return(-1); |
|||
}*/ |
|||
|
|||
int32_t LP_autoprice(char *base,char *rel,double minprice,double margin,char *type) |
|||
{ |
|||
struct LP_priceinfo *basepp,*relpp; |
|||
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) |
|||
{ |
|||
basepp->minprices[relpp->ind] = minprice; |
|||
basepp->margins[relpp->ind] = margin; |
|||
LP_autoprices++; |
|||
return(0); |
|||
} |
|||
return(-1); |
|||
} |
|||
|
|||
void LP_autopriceset(void *ctx,int32_t dir,struct LP_priceinfo *relpp,struct LP_priceinfo *basepp,double price) |
|||
{ |
|||
double margin,minprice,oppomargin; int32_t changed; |
|||
margin = basepp->margins[relpp->ind]; |
|||
oppomargin = relpp->margins[basepp->ind]; |
|||
if ( margin != 0. || oppomargin != 0. ) |
|||
{ |
|||
if ( margin == 0. ) |
|||
margin = oppomargin; |
|||
//printf("min %.8f %s/%s %.8f dir.%d margin %.8f (%.8f %.8f)\n",basepp->minprices[relpp->ind],relpp->symbol,basepp->symbol,price,dir,margin,1. / (price * (1. - margin)),(price * (1. + margin)));
|
|||
if ( dir > 0 ) |
|||
price = 1. / (price * (1. - margin)); |
|||
else price = (price * (1. + margin)); |
|||
if ( (minprice= basepp->minprices[relpp->ind]) == 0. || price >= minprice ) |
|||
{ |
|||
LP_mypriceset(&changed,relpp->symbol,basepp->symbol,price); |
|||
//printf("changed.%d\n",changed);
|
|||
if ( changed != 0 ) |
|||
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,relpp->symbol,basepp->symbol,price); |
|||
} |
|||
} |
|||
} |
|||
|
|||
double LP_pricesparse(void *ctx,int32_t trexflag,char *retstr,struct LP_priceinfo *btcpp) |
|||
{ |
|||
//{"success":true,"message":"","result":[{"MarketName":"BTC-KMD","High":0.00040840,"Low":0.00034900,"Volume":328042.46061669,"Last":0.00037236,"BaseVolume":123.36439511,"TimeStamp":"2017-07-15T13:50:21.87","Bid":0.00035721,"Ask":0.00037069,"OpenBuyOrders":343,"OpenSellOrders":1690,"PrevDay":0.00040875,"Created":"2017-02-11T23:04:01.853"},
|
|||
//{"TradePairId":4762,"Label":"WAVES/BTC","AskPrice":0.00099989,"BidPrice":0.00097350,"Low":0.00095000,"High":0.00108838,"Volume":6501.24403100,"LastPrice":0.00098028,"BuyVolume":1058994.86554882,"SellVolume":2067.87377158,"Change":-7.46,"Open":0.00105926,"Close":0.00098028,"BaseVolume":6.52057452,"BuyBaseVolume":2.33098660,"SellBaseVolume":1167.77655709},
|
|||
int32_t i,j,n,iter; double price,kmdbtc,bid,ask,nxtkmd=0.; struct LP_priceinfo *coinpp,*refpp; char symbol[16],*name,*refcoin; cJSON *retjson,*array,*item; |
|||
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|||
{ |
|||
//printf("got.(%s)\n",retstr);
|
|||
kmdbtc = 0.; |
|||
refcoin = "BTC"; |
|||
refpp = btcpp; |
|||
if ( (array= jarray(&n,retjson,trexflag != 0 ? "result" : "Data")) != 0 ) |
|||
{ |
|||
for (iter=0; iter<2; iter++) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
if ( (name= jstr(item,trexflag != 0 ? "MarketName" : "Label")) != 0 ) |
|||
{ |
|||
symbol[0] = 0; |
|||
if ( trexflag != 0 ) |
|||
{ |
|||
if ( strncmp("BTC-",name,4) == 0 ) |
|||
{ |
|||
name += 4; |
|||
strcpy(symbol,name); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
for (j=0; j<sizeof(symbol)-1; j++) |
|||
if ( (symbol[j]= name[j]) == '/' ) |
|||
break; |
|||
symbol[j] = 0; |
|||
if ( strcmp(name+j+1,"BTC") != 0 ) |
|||
continue; |
|||
} |
|||
if ( symbol[0] != 0 ) |
|||
{ |
|||
//printf("%s\n",jprint(item,0));
|
|||
bid = jdouble(item,trexflag != 0 ? "Bid" : "BidPrice"); |
|||
ask = jdouble(item,trexflag != 0 ? "Ask" : "AskPrice"); |
|||
if ( iter == 1 && kmdbtc > SMALLVAL && strcmp(symbol,"NXT") == 0 ) |
|||
nxtkmd = 0.5 * (bid + ask) / kmdbtc; |
|||
if ( (coinpp= LP_priceinfofind(symbol)) != 0 ) |
|||
{ |
|||
coinpp->high[trexflag] = jdouble(item,"High"); |
|||
coinpp->low[trexflag] = jdouble(item,"Low"); |
|||
//coinpp->volume = jdouble(item,"Volume");
|
|||
//coinpp->btcvolume = jdouble(item,"BaseVolume");
|
|||
coinpp->last[trexflag] = jdouble(item,trexflag != 0 ? "Last" : "LastPrice"); |
|||
coinpp->bid[trexflag] = bid; |
|||
coinpp->ask[trexflag] = ask; |
|||
//coinpp->prevday = jdouble(item,"PrevDay");
|
|||
//printf("iter.%d trexflag.%d %s high %.8f, low %.8f, last %.8f hbla.(%.8f %.8f)\n",iter,trexflag,symbol,coinpp->high[trexflag],coinpp->low[trexflag],coinpp->last[trexflag],coinpp->bid[trexflag],coinpp->ask[trexflag]);
|
|||
if ( coinpp->bid[trexflag] > SMALLVAL && coinpp->ask[trexflag] > SMALLVAL ) |
|||
{ |
|||
price = 0.5 * (coinpp->bid[trexflag] + coinpp->ask[trexflag]); |
|||
if ( iter == 0 ) |
|||
{ |
|||
if ( strcmp(symbol,"KMD") == 0 ) |
|||
kmdbtc = price; |
|||
} |
|||
else |
|||
{ |
|||
if ( strcmp(symbol,"KMD") == 0 ) |
|||
continue; |
|||
//printf("(%s/%s) iter.%d trexflag.%d %s %.8f %.8f\n",refpp->symbol,coinpp->symbol,iter,trexflag,symbol,price,price/kmdbtc);
|
|||
price /= kmdbtc; |
|||
} |
|||
if ( trexflag == 0 && coinpp->bid[1] > SMALLVAL && coinpp->ask[1] > SMALLVAL ) |
|||
{ |
|||
//printf("have trex: iter.%d trexflag.%d %s %.8f %.8f\n",iter,trexflag,symbol,coinpp->bid[1],coinpp->ask[1]);
|
|||
continue; |
|||
} |
|||
LP_autopriceset(ctx,1,refpp,coinpp,price); |
|||
LP_autopriceset(ctx,-1,coinpp,refpp,price); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
refcoin = "KMD"; |
|||
if ( kmdbtc == 0. || (refpp= LP_priceinfofind("KMD")) == 0 ) |
|||
break; |
|||
} |
|||
} |
|||
free_json(retjson); |
|||
} |
|||
return(nxtkmd); |
|||
} |
|||
|
|||
static char *assetids[][3] = |
|||
{ |
|||
{ "12071612744977229797", "UNITY", "10000" }, |
|||
{ "15344649963748848799", "DEX", "1" }, |
|||
{ "6883271355794806507", "PANGEA", "10000" }, |
|||
{ "17911762572811467637", "JUMBLR", "10000" }, |
|||
{ "17083334802666450484", "BET", "10000" }, |
|||
{ "13476425053110940554", "CRYPTO", "1000" }, |
|||
{ "6932037131189568014", "HODL", "1" }, |
|||
{ "3006420581923704757", "SHARK", "10000" }, |
|||
{ "17571711292785902558", "BOTS", "1" }, |
|||
{ "10524562908394749924", "MGW", "1" }, |
|||
}; |
|||
|
|||
void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|||
{ |
|||
char *retstr; cJSON *retjson,*bid,*ask; uint64_t bidsatoshis,asksatoshis; int32_t i; double nxtkmd,price; struct LP_priceinfo *kmdpp,*fiatpp,*nxtpp; |
|||
if ( (retstr= issue_curlt("https://bittrex.com/api/v1.1/public/getmarketsummaries",LP_HTTP_TIMEOUT*10)) == 0 ) |
|||
{ |
|||
printf("trex error getting marketsummaries\n"); |
|||
sleep(60); |
|||
return; |
|||
} |
|||
nxtkmd = LP_pricesparse(ctx,1,retstr,btcpp); |
|||
free(retstr); |
|||
if ( (retstr= issue_curlt("https://www.cryptopia.co.nz/api/GetMarkets",LP_HTTP_TIMEOUT*10)) == 0 ) |
|||
{ |
|||
printf("cryptopia error getting marketsummaries\n"); |
|||
sleep(60); |
|||
return; |
|||
} |
|||
LP_pricesparse(ctx,0,retstr,btcpp); |
|||
free(retstr); |
|||
if ( (kmdpp= LP_priceinfofind("KMD")) != 0 ) |
|||
{ |
|||
for (i=0; i<32; i++) |
|||
{ |
|||
if ( (fiatpp= LP_priceinfofind(CURRENCIES[i])) != 0 ) |
|||
{ |
|||
if ( (retjson= LP_paxprice(CURRENCIES[i])) != 0 ) |
|||
{ |
|||
//printf("(%s %.8f %.8f) ",CURRENCIES[i],jdouble(retjson,"price"),jdouble(retjson,"invprice"));
|
|||
price = jdouble(retjson,"price"); |
|||
LP_autopriceset(ctx,1,kmdpp,fiatpp,price); |
|||
LP_autopriceset(ctx,-1,fiatpp,kmdpp,price); |
|||
free_json(retjson); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if ( nxtkmd > SMALLVAL ) |
|||
{ |
|||
for (i=0; i<sizeof(assetids)/sizeof(*assetids); i++) |
|||
{ |
|||
if ( (nxtpp= LP_priceinfofind(assetids[i][1])) != 0 ) |
|||
{ |
|||
price = 0.; |
|||
bidsatoshis = asksatoshis = 0; |
|||
if ( (retjson= LP_assethbla(assetids[i][0])) != 0 ) |
|||
{ |
|||
if ( (bid= jobj(retjson,"bid")) != 0 && (ask= jobj(retjson,"ask")) != 0 ) |
|||
{ |
|||
bidsatoshis = j64bits(bid,"priceNQT") * atoi(assetids[i][2]); |
|||
asksatoshis = j64bits(ask,"priceNQT") * atoi(assetids[i][2]); |
|||
if ( bidsatoshis != 0 && asksatoshis != 0 ) |
|||
price = 0.5 * dstr(bidsatoshis + asksatoshis) * nxtkmd; |
|||
} |
|||
LP_autopriceset(ctx,1,kmdpp,nxtpp,price); |
|||
LP_autopriceset(ctx,-1,nxtpp,kmdpp,price); |
|||
//printf("%s %s -> (%s) nxtkmd %.8f %.8f %.8f\n",assetids[i][1],assetids[i][0],jprint(retjson,0),nxtkmd,0.5*dstr(bidsatoshis + asksatoshis),price);
|
|||
free_json(retjson); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,struct iguana_info *buy,struct iguana_info *sell,double relvolume,int32_t setbaserel) |
|||
{ |
|||
char *retstr2; double bid,ask,maxprice; uint32_t requestid,quoteid,iter,i; cJSON *retjson2; |
|||
requestid = quoteid = 0; |
|||
LP_myprice(&bid,&ask,buy->symbol,sell->symbol); |
|||
maxprice = ask; |
|||
if ( setbaserel != 0 ) |
|||
{ |
|||
strcpy(LP_portfolio_base,""); |
|||
strcpy(LP_portfolio_rel,""); |
|||
LP_portfolio_relvolume = 0.; |
|||
} |
|||
printf("pending.%d base buy.%s, rel sell.%s relvolume %f maxprice %.8f (%.8f %.8f)\n",LP_pendingswaps,buy->symbol,sell->symbol,sell->relvolume,maxprice,bid,ask); |
|||
if ( LP_pricevalid(maxprice) > 0 ) |
|||
{ |
|||
relvolume = sell->relvolume; |
|||
for (iter=0; iter<2; iter++) |
|||
{ |
|||
if ( relvolume < dstr(LP_MIN_TXFEE) ) |
|||
break; |
|||
if ( LP_utxo_bestfit(sell->symbol,SATOSHIDEN * relvolume) != 0 ) |
|||
{ |
|||
if ( (retstr2= LP_autotrade(ctx,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600)) != 0 ) |
|||
{ |
|||
if ( (retjson2= cJSON_Parse(retstr2)) != 0 ) |
|||
{ |
|||
if ( (requestid= juint(retjson2,"requestid")) != 0 && (quoteid= juint(retjson2,"quoteid")) != 0 ) |
|||
{ |
|||
|
|||
} |
|||
free_json(retjson2); |
|||
} |
|||
printf("%s relvolume %.8f LP_autotrade.(%s)\n",sell->symbol,relvolume,retstr2); |
|||
free(retstr2); |
|||
} |
|||
if ( requestid != 0 && quoteid != 0 ) |
|||
break; |
|||
} else printf("cant find alice %.8f %s\n",relvolume,sell->symbol); |
|||
if ( iter == 0 ) |
|||
{ |
|||
for (i=0; i<100; i++) |
|||
{ |
|||
relvolume *= .99; |
|||
if ( LP_utxo_bestfit(sell->symbol,SATOSHIDEN * relvolume) != 0 ) |
|||
{ |
|||
printf("i.%d relvolume %.8f from %.8f\n",i,relvolume,sell->relvolume); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
else if ( setbaserel != 0 ) |
|||
{ |
|||
strcpy(LP_portfolio_base,buy->symbol); |
|||
strcpy(LP_portfolio_rel,sell->symbol); |
|||
LP_portfolio_relvolume = sell->relvolume; |
|||
} |
|||
*requestidp = requestid; |
|||
*quoteidp = quoteid; |
|||
if ( requestid != 0 && quoteid != 0 ) |
|||
return(0); |
|||
else return(-1); |
|||
} |
|||
|
|||
struct LP_portfoliotrade { double metric; char buycoin[16],sellcoin[16]; }; |
|||
|
|||
int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *array) |
|||
{ |
|||
int32_t i,j,m,n = 0; cJSON *item; struct LP_portfoliotrade coins[256]; |
|||
memset(coins,0,sizeof(coins)); |
|||
if ( (m= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
for (i=j=0; i<m && i<sizeof(coins)/sizeof(*coins); i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
safecopy(coins[j].buycoin,jstr(item,"coin"),sizeof(coins[j].buycoin)); |
|||
coins[j].metric = jdouble(item,"force"); |
|||
if ( fabs(coins[j].metric) > SMALLVAL && coins[j].buycoin[0] != 0 ) |
|||
j++; |
|||
} |
|||
if ( (m= j) > 1 ) |
|||
{ |
|||
for (i=n=0; i<m-1; i++) |
|||
for (j=i+1; j<m; j++) |
|||
if ( coins[i].metric*coins[j].metric < 0. ) |
|||
{ |
|||
if ( coins[i].metric > 0. ) |
|||
{ |
|||
trades[n].metric = (coins[i].metric - coins[j].metric); |
|||
strcpy(trades[n].buycoin,coins[i].buycoin); |
|||
strcpy(trades[n].sellcoin,coins[j].buycoin); |
|||
printf("buy %s %f, sell %s %f -> %f\n",trades[n].buycoin,coins[i].metric,trades[n].sellcoin,coins[j].metric,trades[n].metric); |
|||
} |
|||
else |
|||
{ |
|||
trades[n].metric = (coins[j].metric - coins[i].metric); |
|||
strcpy(trades[n].buycoin,coins[j].buycoin); |
|||
strcpy(trades[n].sellcoin,coins[i].buycoin); |
|||
printf("buy %s %f, sell %s %f -> %f\n",trades[n].buycoin,coins[j].metric,trades[n].sellcoin,coins[i].metric,trades[n].metric); |
|||
} |
|||
n++; |
|||
if ( n >= max ) |
|||
break; |
|||
} |
|||
revsortds((void *)trades,n,sizeof(*trades)); |
|||
for (i=0; i<n; i++) |
|||
printf("%d: buy %s, sell %s -> %f\n",i,trades[i].buycoin,trades[i].sellcoin,trades[i].metric); |
|||
} |
|||
} |
|||
return(n); |
|||
} |
|||
|
|||
void prices_loop(void *ignore) |
|||
{ |
|||
char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; void *ctx = bitcoin_ctx(); |
|||
while ( 1 ) |
|||
{ |
|||
if ( (btcpp= LP_priceinfofind("BTC")) == 0 ) |
|||
{ |
|||
sleep(60); |
|||
continue; |
|||
} |
|||
if ( LP_autoprices != 0 ) |
|||
LP_autoprice_iter(ctx,btcpp); |
|||
if ( (retstr= LP_portfolio()) != 0 ) |
|||
{ |
|||
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|||
{ |
|||
if ( (buycoin= jstr(retjson,"buycoin")) != 0 && (buy= LP_coinfind(buycoin)) != 0 && (sellcoin= jstr(retjson,"sellcoin")) != 0 && (sell= LP_coinfind(sellcoin)) != 0 && buy->inactive == 0 && sell->inactive == 0 ) |
|||
{ |
|||
if ( LP_portfolio_trade(ctx,&requestid,"eid,buy,sell,sell->relvolume,1) < 0 ) |
|||
{ |
|||
array = jarray(&m,retjson,"portfolio"); |
|||
if ( array != 0 && (n= LP_portfolio_order(trades,(int32_t)(sizeof(trades)/sizeof(*trades)),array)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
if ( strcmp(trades[i].buycoin,buycoin) != 0 || strcmp(trades[i].sellcoin,sellcoin) != 0 ) |
|||
{ |
|||
buy = LP_coinfind(trades[i].buycoin); |
|||
sell = LP_coinfind(trades[i].sellcoin); |
|||
if ( buy != 0 && sell != 0 && LP_portfolio_trade(ctx,&requestid,"eid,buy,sell,sell->relvolume,0) == 0 ) |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
free_json(retjson); |
|||
} |
|||
free(retstr); |
|||
} |
|||
sleep(60); |
|||
} |
|||
} |
|||
|
|||
|
@ -0,0 +1,849 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_prices.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
struct LP_orderbookentry { bits256 txid,txid2,pubkey; double price; uint64_t basesatoshis; int32_t vout,vout2,age; }; |
|||
|
|||
#define LP_MAXPRICEINFOS 256 |
|||
struct LP_priceinfo |
|||
{ |
|||
char symbol[16]; |
|||
uint64_t coinbits; |
|||
int32_t ind,pad; |
|||
double diagval,high[2],low[2],last[2],bid[2],ask[2]; //volume,btcvolume,prevday; // mostly bittrex info
|
|||
double relvals[LP_MAXPRICEINFOS]; |
|||
double myprices[LP_MAXPRICEINFOS]; |
|||
double minprices[LP_MAXPRICEINFOS]; // autoprice
|
|||
double margins[LP_MAXPRICEINFOS]; |
|||
//double maxprices[LP_MAXPRICEINFOS]; // autofill of base/rel
|
|||
//double relvols[LP_MAXPRICEINFOS];
|
|||
FILE *fps[LP_MAXPRICEINFOS]; |
|||
} LP_priceinfos[LP_MAXPRICEINFOS]; |
|||
int32_t LP_numpriceinfos; |
|||
|
|||
struct LP_cacheinfo |
|||
{ |
|||
UT_hash_handle hh; |
|||
struct LP_quoteinfo Q; |
|||
uint8_t key[sizeof(bits256)+sizeof(uint64_t)*2+sizeof(int32_t)]; |
|||
double price; |
|||
uint32_t timestamp; |
|||
} *LP_cacheinfos; |
|||
|
|||
struct LP_pubkeyinfo |
|||
{ |
|||
UT_hash_handle hh; |
|||
bits256 pubkey; |
|||
double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; |
|||
uint32_t timestamp,istrusted,numerrors; |
|||
} *LP_pubkeyinfos; |
|||
|
|||
int32_t LP_pricevalid(double price) |
|||
{ |
|||
if ( price > SMALLVAL && isnan(price) == 0 && price < SATOSHIDEN ) |
|||
return(1); |
|||
else return(0); |
|||
} |
|||
|
|||
struct LP_priceinfo *LP_priceinfofind(char *symbol) |
|||
{ |
|||
int32_t i; struct LP_priceinfo *pp; uint64_t coinbits; |
|||
if ( symbol == 0 || symbol[0] == 0 ) |
|||
return(0); |
|||
if ( LP_numpriceinfos > 0 ) |
|||
{ |
|||
coinbits = stringbits(symbol); |
|||
pp = LP_priceinfos; |
|||
for (i=0; i<LP_numpriceinfos; i++,pp++) |
|||
if ( pp->coinbits == coinbits ) |
|||
return(pp); |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
struct LP_priceinfo *LP_priceinfoptr(int32_t *indp,char *base,char *rel) |
|||
{ |
|||
struct LP_priceinfo *basepp,*relpp; |
|||
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) |
|||
{ |
|||
*indp = relpp->ind; |
|||
return(basepp); |
|||
} |
|||
else |
|||
{ |
|||
*indp = -1; |
|||
return(0); |
|||
} |
|||
} |
|||
|
|||
int32_t LP_cachekey(uint8_t *key,char *base,char *rel,bits256 txid,int32_t vout) |
|||
{ |
|||
uint64_t basebits,relbits; int32_t offset = 0; |
|||
basebits = stringbits(base); |
|||
relbits = stringbits(rel); |
|||
memcpy(&key[offset],&basebits,sizeof(basebits)), offset += sizeof(basebits); |
|||
memcpy(&key[offset],&relbits,sizeof(relbits)), offset += sizeof(relbits); |
|||
memcpy(&key[offset],&txid,sizeof(txid)), offset += sizeof(txid); |
|||
memcpy(&key[offset],&vout,sizeof(vout)), offset += sizeof(vout); |
|||
return(offset); |
|||
} |
|||
|
|||
struct LP_cacheinfo *LP_cachefind(char *base,char *rel,bits256 txid,int32_t vout) |
|||
{ |
|||
struct LP_cacheinfo *ptr=0; uint8_t key[sizeof(bits256)+sizeof(uint64_t)*2+sizeof(vout)]; |
|||
if ( base == 0 || rel == 0 ) |
|||
return(0); |
|||
if ( LP_cachekey(key,base,rel,txid,vout) == sizeof(key) ) |
|||
{ |
|||
portable_mutex_lock(&LP_cachemutex); |
|||
HASH_FIND(hh,LP_cacheinfos,key,sizeof(key),ptr); |
|||
portable_mutex_unlock(&LP_cachemutex); |
|||
} else printf("LP_cachefind keysize mismatch?\n"); |
|||
if ( 0 && ptr != 0 && ptr->timestamp != 0 && ptr->timestamp < time(NULL)-LP_CACHEDURATION ) |
|||
{ |
|||
printf("expire price %.8f\n",ptr->price); |
|||
ptr->price = 0.; |
|||
ptr->timestamp = 0; |
|||
memset(&ptr->Q,0,sizeof(ptr->Q)); |
|||
} |
|||
return(ptr); |
|||
} |
|||
|
|||
struct LP_pubkeyinfo *LP_pubkeyfind(bits256 pubkey) |
|||
{ |
|||
struct LP_pubkeyinfo *pubp=0; |
|||
portable_mutex_lock(&LP_pubkeymutex); |
|||
HASH_FIND(hh,LP_pubkeyinfos,&pubkey,sizeof(pubkey),pubp); |
|||
portable_mutex_unlock(&LP_pubkeymutex); |
|||
return(pubp); |
|||
} |
|||
|
|||
struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey) |
|||
{ |
|||
struct LP_pubkeyinfo *pubp=0; |
|||
if ( (pubp= LP_pubkeyfind(pubkey)) == 0 ) |
|||
{ |
|||
portable_mutex_lock(&LP_pubkeymutex); |
|||
pubp = calloc(1,sizeof(*pubp)); |
|||
pubp->pubkey = pubkey; |
|||
HASH_ADD_KEYPTR(hh,LP_pubkeyinfos,&pubp->pubkey,sizeof(pubp->pubkey),pubp); |
|||
portable_mutex_unlock(&LP_pubkeymutex); |
|||
if ( (pubp= LP_pubkeyfind(pubkey)) == 0 ) |
|||
printf("pubkeyadd find error after add\n"); |
|||
} |
|||
return(pubp); |
|||
} |
|||
|
|||
int32_t LP_pubkey_istrusted(bits256 pubkey) |
|||
{ |
|||
struct LP_pubkeyinfo *pubp; |
|||
if ( (pubp= LP_pubkeyfind(pubkey)) != 0 ) |
|||
return(pubp->istrusted != 0); |
|||
return(0); |
|||
} |
|||
|
|||
char *LP_pubkey_trustset(bits256 pubkey,uint32_t trustval) |
|||
{ |
|||
struct LP_pubkeyinfo *pubp; |
|||
if ( (pubp= LP_pubkeyfind(pubkey)) != 0 ) |
|||
{ |
|||
pubp->istrusted = trustval; |
|||
return(clonestr("{\"result\":\"success\"}")); |
|||
} |
|||
return(clonestr("{\"error\":\"pubkey not found\"}")); |
|||
} |
|||
|
|||
cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) |
|||
{ |
|||
int32_t baseid,relid; char *base; double price; cJSON *item,*array,*obj; |
|||
obj = cJSON_CreateObject(); |
|||
array = cJSON_CreateArray(); |
|||
for (baseid=0; baseid<LP_numpriceinfos; baseid++) |
|||
{ |
|||
base = LP_priceinfos[baseid].symbol; |
|||
for (relid=0; relid<LP_numpriceinfos; relid++) |
|||
{ |
|||
price = pubp->matrix[baseid][relid]; |
|||
if ( LP_pricevalid(price) > 0 ) |
|||
{ |
|||
item = cJSON_CreateArray(); |
|||
jaddistr(item,base); |
|||
jaddistr(item,LP_priceinfos[relid].symbol); |
|||
jaddinum(item,price); |
|||
jaddi(array,item); |
|||
} |
|||
} |
|||
} |
|||
jaddbits256(obj,"pubkey",pubp->pubkey); |
|||
jaddnum(obj,"timestamp",pubp->timestamp); |
|||
jadd(obj,"asks",array); |
|||
if ( pubp->istrusted != 0 ) |
|||
jaddnum(obj,"istrusted",pubp->istrusted); |
|||
return(obj); |
|||
} |
|||
|
|||
char *LP_prices() |
|||
{ |
|||
struct LP_pubkeyinfo *pubp,*tmp; cJSON *array = cJSON_CreateArray(); |
|||
HASH_ITER(hh,LP_pubkeyinfos,pubp,tmp) |
|||
{ |
|||
jaddi(array,LP_pubkeyjson(pubp)); |
|||
} |
|||
return(jprint(array,1)); |
|||
} |
|||
|
|||
void LP_prices_parse(cJSON *obj) |
|||
{ |
|||
struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; int32_t i,n,relid; char *base,*rel; double askprice; |
|||
pubkey = jbits256(obj,"pubkey"); |
|||
if ( bits256_nonz(pubkey) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) |
|||
{ |
|||
if ( (timestamp= juint(obj,"timestamp")) > pubp->timestamp && (asks= jarray(&n,obj,"asks")) != 0 ) |
|||
{ |
|||
pubp->timestamp = timestamp; |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(asks,i); |
|||
base = jstri(item,0); |
|||
rel = jstri(item,1); |
|||
askprice = jdoublei(item,2); |
|||
if ( LP_pricevalid(askprice) > 0 ) |
|||
{ |
|||
if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) |
|||
{ |
|||
char str[65]; printf("%s %s/%s (%d/%d) %.8f\n",bits256_str(str,pubkey),base,rel,basepp->ind,relid,askprice); |
|||
pubp->matrix[basepp->ind][relid] = askprice; |
|||
if ( (relpp= LP_priceinfofind(rel)) != 0 ) |
|||
{ |
|||
dxblend(&basepp->relvals[relpp->ind],askprice,0.9); |
|||
dxblend(&relpp->relvals[basepp->ind],1. / askprice,0.9); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
void LP_peer_pricesquery(char *destipaddr,uint16_t destport) |
|||
{ |
|||
char *retstr; cJSON *array; int32_t i,n; |
|||
if ( (retstr= issue_LP_getprices(destipaddr,destport)) != 0 ) |
|||
{ |
|||
if ( (array= cJSON_Parse(retstr)) != 0 ) |
|||
{ |
|||
if ( is_cJSON_Array(array) && (n= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
LP_prices_parse(jitem(array,i)); |
|||
} |
|||
free_json(array); |
|||
} |
|||
free(retstr); |
|||
} |
|||
} |
|||
|
|||
double LP_pricecache(struct LP_quoteinfo *qp,char *base,char *rel,bits256 txid,int32_t vout) |
|||
{ |
|||
struct LP_cacheinfo *ptr; |
|||
if ( (ptr= LP_cachefind(base,rel,txid,vout)) != 0 ) |
|||
{ |
|||
if ( qp != 0 ) |
|||
(*qp) = ptr->Q; |
|||
if ( ptr->price == 0. && ptr->Q.satoshis != 0 ) |
|||
{ |
|||
ptr->price = (double)ptr->Q.destsatoshis / ptr->Q.satoshis; |
|||
if ( LP_pricevalid(ptr->price) <= 0 ) |
|||
ptr->price = 0.; |
|||
//printf("LP_pricecache: set %s/%s ptr->price %.8f\n",base,rel,ptr->price);
|
|||
} |
|||
//printf("found %s/%s %.8f\n",base,rel,ptr->price);
|
|||
return(ptr->price); |
|||
} |
|||
//char str[65]; printf("cachemiss %s/%s %s/v%d\n",base,rel,bits256_str(str,txid),vout);
|
|||
return(0.); |
|||
} |
|||
|
|||
void LP_priceinfoupdate(char *base,char *rel,double price) |
|||
{ |
|||
struct LP_priceinfo *basepp,*relpp; |
|||
if ( LP_pricevalid(price) > 0 ) |
|||
{ |
|||
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) |
|||
{ |
|||
//dxblend(&basepp->relvals[relpp->ind],price,0.9);
|
|||
//dxblend(&relpp->relvals[basepp->ind],1. / price,0.9);
|
|||
basepp->relvals[relpp->ind] = price; |
|||
relpp->relvals[basepp->ind] = 1. / price; |
|||
} |
|||
} |
|||
} |
|||
|
|||
double LP_myprice(double *bidp,double *askp,char *base,char *rel) |
|||
{ |
|||
struct LP_priceinfo *basepp,*relpp; double val; |
|||
*bidp = *askp = 0.; |
|||
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) |
|||
{ |
|||
*askp = basepp->myprices[relpp->ind]; |
|||
if ( LP_pricevalid(*askp) > 0 ) |
|||
{ |
|||
val = relpp->myprices[basepp->ind]; |
|||
if ( LP_pricevalid(val) > 0 ) |
|||
{ |
|||
*bidp = 1. / val; |
|||
return((*askp + *bidp) * 0.5); |
|||
} |
|||
else |
|||
{ |
|||
*bidp = 0.; |
|||
return(*askp); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
val = relpp->myprices[basepp->ind]; |
|||
if ( LP_pricevalid(val) > 0 ) |
|||
{ |
|||
*bidp = 1. / val; |
|||
*askp = 0.; |
|||
return(*bidp); |
|||
} |
|||
} |
|||
} |
|||
return(0.); |
|||
} |
|||
|
|||
char *LP_myprices() |
|||
{ |
|||
int32_t baseid,relid; double bid,ask; char *base,*rel; cJSON *item,*array; |
|||
array = cJSON_CreateArray(); |
|||
for (baseid=0; baseid<LP_numpriceinfos; baseid++) |
|||
{ |
|||
base = LP_priceinfos[baseid].symbol; |
|||
for (relid=0; relid<LP_numpriceinfos; relid++) |
|||
{ |
|||
rel = LP_priceinfos[relid].symbol; |
|||
if ( LP_myprice(&bid,&ask,base,rel) > SMALLVAL ) |
|||
{ |
|||
item = cJSON_CreateObject(); |
|||
jaddstr(item,"base",base); |
|||
jaddstr(item,"rel",rel); |
|||
jaddnum(item,"bid",bid); |
|||
jaddnum(item,"ask",ask); |
|||
jaddi(array,item); |
|||
} |
|||
} |
|||
} |
|||
return(jprint(array,1)); |
|||
} |
|||
|
|||
int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) |
|||
{ |
|||
struct LP_priceinfo *basepp,*relpp; struct LP_pubkeyinfo *pubp; |
|||
*changedp = 0; |
|||
if ( base != 0 && rel != 0 && LP_pricevalid(price) > 0 && (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) |
|||
{ |
|||
if ( fabs(basepp->myprices[relpp->ind] - price) > SMALLVAL ) |
|||
*changedp = 1; |
|||
basepp->myprices[relpp->ind] = price; // ask
|
|||
//printf("LP_mypriceset base.%s rel.%s <- price %.8f\n",base,rel,price);
|
|||
//relpp->myprices[basepp->ind] = (1. / price); // bid
|
|||
if ( (pubp= LP_pubkeyadd(LP_mypub25519)) != 0 ) |
|||
{ |
|||
pubp->matrix[basepp->ind][relpp->ind] = price; |
|||
//pubp->matrix[relpp->ind][basepp->ind] = (1. / price);
|
|||
pubp->timestamp = (uint32_t)time(NULL); |
|||
} |
|||
return(0); |
|||
} else return(-1); |
|||
} |
|||
|
|||
double LP_price(char *base,char *rel) |
|||
{ |
|||
struct LP_priceinfo *basepp; int32_t relind; double price = 0.; |
|||
if ( (basepp= LP_priceinfoptr(&relind,base,rel)) != 0 ) |
|||
{ |
|||
if ( (price= basepp->myprices[relind]) == 0. ) |
|||
price = basepp->relvals[relind]; |
|||
} |
|||
return(price); |
|||
} |
|||
|
|||
cJSON *LP_priceinfomatrix(int32_t usemyprices) |
|||
{ |
|||
int32_t i,j,n,m; double total,sum,val; struct LP_priceinfo *pp; uint32_t now; struct LP_cacheinfo *ptr,*tmp; cJSON *vectorjson = cJSON_CreateObject(); |
|||
now = (uint32_t)time(NULL); |
|||
HASH_ITER(hh,LP_cacheinfos,ptr,tmp) |
|||
{ |
|||
if ( ptr->timestamp < now-3600*2 || ptr->price == 0. ) |
|||
continue; |
|||
LP_priceinfoupdate(ptr->Q.srccoin,ptr->Q.destcoin,ptr->price); |
|||
} |
|||
pp = LP_priceinfos; |
|||
total = m = 0; |
|||
for (i=0; i<LP_numpriceinfos; i++,pp++) |
|||
{ |
|||
pp->diagval = sum = n = 0; |
|||
for (j=0; j<LP_numpriceinfos; j++) |
|||
{ |
|||
if ( usemyprices == 0 || (val= pp->myprices[j]) == 0. ) |
|||
val = pp->relvals[j]; |
|||
if ( val > SMALLVAL ) |
|||
{ |
|||
sum += val; |
|||
n++; |
|||
} |
|||
} |
|||
if ( n > 0 ) |
|||
{ |
|||
pp->diagval = sum / n; |
|||
total += pp->diagval, m++; |
|||
} |
|||
} |
|||
if ( m > 0 ) |
|||
{ |
|||
pp = LP_priceinfos; |
|||
for (i=0; i<LP_numpriceinfos; i++,pp++) |
|||
{ |
|||
if ( pp->diagval > SMALLVAL ) |
|||
{ |
|||
pp->diagval /= total; |
|||
jaddnum(vectorjson,pp->symbol,pp->diagval); |
|||
} |
|||
} |
|||
} |
|||
return(vectorjson); |
|||
} |
|||
|
|||
struct LP_priceinfo *LP_priceinfoadd(char *symbol) |
|||
{ |
|||
struct LP_priceinfo *pp; cJSON *retjson; |
|||
if ( symbol == 0 ) |
|||
return(0); |
|||
if ( LP_numpriceinfos >= sizeof(LP_priceinfos)/sizeof(*LP_priceinfos) ) |
|||
{ |
|||
printf("cant add any more priceinfos\n"); |
|||
return(0); |
|||
} |
|||
pp = &LP_priceinfos[LP_numpriceinfos]; |
|||
memset(pp,0,sizeof(*pp)); |
|||
safecopy(pp->symbol,symbol,sizeof(pp->symbol)); |
|||
pp->coinbits = stringbits(symbol); |
|||
pp->ind = LP_numpriceinfos++; |
|||
LP_numpriceinfos++; |
|||
if ( (retjson= LP_priceinfomatrix(0)) != 0 ) |
|||
free_json(retjson); |
|||
return(pp); |
|||
} |
|||
|
|||
struct LP_cacheinfo *LP_cacheadd(char *base,char *rel,bits256 txid,int32_t vout,double price,struct LP_quoteinfo *qp) |
|||
{ |
|||
char str[65]; struct LP_cacheinfo *ptr=0; |
|||
if ( base == 0 || rel == 0 ) |
|||
return(0); |
|||
if ( LP_pricevalid(price) > 0 ) |
|||
{ |
|||
if ( (ptr= LP_cachefind(base,rel,txid,vout)) == 0 ) |
|||
{ |
|||
ptr = calloc(1,sizeof(*ptr)); |
|||
if ( LP_cachekey(ptr->key,base,rel,txid,vout) == sizeof(ptr->key) ) |
|||
{ |
|||
portable_mutex_lock(&LP_cachemutex); |
|||
HASH_ADD(hh,LP_cacheinfos,key,sizeof(ptr->key),ptr); |
|||
portable_mutex_unlock(&LP_cachemutex); |
|||
} else printf("LP_cacheadd keysize mismatch?\n"); |
|||
} |
|||
ptr->Q = *qp; |
|||
ptr->timestamp = (uint32_t)time(NULL); |
|||
if ( price != ptr->price ) |
|||
{ |
|||
ptr->price = price; |
|||
LP_priceinfoupdate(base,rel,price); |
|||
printf("updated %s/v%d %s/%s %llu price %.8f\n",bits256_str(str,txid),vout,base,rel,(long long)qp->satoshis,price); |
|||
} else ptr->price = price; |
|||
} |
|||
return(ptr); |
|||
} |
|||
|
|||
static int _cmp_orderbook(const void *a,const void *b) |
|||
{ |
|||
int32_t retval = 0; |
|||
#define ptr_a (*(struct LP_orderbookentry **)a)->price |
|||
#define ptr_b (*(struct LP_orderbookentry **)b)->price |
|||
if ( ptr_b > ptr_a ) |
|||
retval = -1; |
|||
else if ( ptr_b < ptr_a ) |
|||
retval = 1; |
|||
else |
|||
{ |
|||
#undef ptr_a |
|||
#undef ptr_b |
|||
#define ptr_a ((struct LP_orderbookentry *)a)->basesatoshis |
|||
#define ptr_b ((struct LP_orderbookentry *)b)->basesatoshis |
|||
if ( ptr_b > ptr_a ) |
|||
return(-1); |
|||
else if ( ptr_b < ptr_a ) |
|||
return(1); |
|||
} |
|||
// printf("%.8f vs %.8f -> %d\n",ptr_a,ptr_b,retval);
|
|||
return(retval); |
|||
#undef ptr_a |
|||
#undef ptr_b |
|||
} |
|||
|
|||
cJSON *LP_orderbookjson(struct LP_orderbookentry *op) |
|||
{ |
|||
cJSON *item = cJSON_CreateObject(); |
|||
if ( LP_pricevalid(op->price) > 0 ) |
|||
{ |
|||
jaddnum(item,"price",op->price); |
|||
jaddnum(item,"volume",dstr(op->basesatoshis)); |
|||
jaddbits256(item,"txid",op->txid); |
|||
jaddnum(item,"vout",op->vout); |
|||
jaddbits256(item,"pubkey",op->pubkey); |
|||
jaddnum(item,"age",op->age); |
|||
} |
|||
return(item); |
|||
} |
|||
|
|||
struct LP_orderbookentry *LP_orderbookentry(char *base,char *rel,bits256 txid,int32_t vout,bits256 txid2,int32_t vout2,double price,uint64_t basesatoshis,bits256 pubkey,int32_t age) |
|||
{ |
|||
struct LP_orderbookentry *op; |
|||
if ( (op= calloc(1,sizeof(*op))) != 0 ) |
|||
{ |
|||
op->txid = txid; |
|||
op->vout = vout; |
|||
op->txid2 = txid2; |
|||
op->vout2 = vout2; |
|||
op->price = price; |
|||
op->basesatoshis = basesatoshis; |
|||
op->pubkey = pubkey; |
|||
op->age = age; |
|||
} |
|||
return(op); |
|||
} |
|||
|
|||
int32_t LP_orderbookfind(struct LP_orderbookentry **array,int32_t num,bits256 txid,int32_t vout) |
|||
{ |
|||
int32_t i; |
|||
for (i=0; i<num; i++) |
|||
if ( (array[i]->vout == vout && bits256_cmp(array[i]->txid,txid) == 0) || (array[i]->vout2 == vout && bits256_cmp(array[i]->txid2,txid) == 0) ) |
|||
return(i); |
|||
return(-1); |
|||
} |
|||
|
|||
int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char *rel,struct LP_orderbookentry *(**arrayp),int32_t num,int32_t cachednum,int32_t duration) |
|||
{ |
|||
struct LP_utxoinfo *utxo,*tmp; struct LP_pubkeyinfo *pubp=0; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; uint32_t oldest; double price; int32_t baseid,relid; uint64_t basesatoshis,val,val2; |
|||
if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) |
|||
baseid = basepp->ind; |
|||
else return(num); |
|||
now = (uint32_t)time(NULL); |
|||
oldest = now - duration; |
|||
HASH_ITER(hh,LP_utxoinfos[1],utxo,tmp) |
|||
{ |
|||
if ( pubp == 0 || bits256_cmp(pubp->pubkey,utxo->pubkey) != 0 ) |
|||
pubp = LP_pubkeyfind(utxo->pubkey); |
|||
if ( pubp != 0 && pubp->numerrors >= LP_MAXPUBKEY_ERRORS ) |
|||
continue; |
|||
//char str[65],str2[65]; printf("check utxo.%s/v%d from %s\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,utxo->pubkey));
|
|||
if ( strcmp(base,utxo->coin) == 0 && LP_isavailable(utxo) > 0 && pubp != 0 && (price= pubp->matrix[baseid][relid]) > SMALLVAL && pubp->timestamp > oldest && pubp->timestamp <= now ) |
|||
{ |
|||
if ( LP_orderbookfind(*arrayp,cachednum,utxo->payment.txid,utxo->payment.vout) < 0 ) |
|||
{ |
|||
if ( LP_iseligible(&val,&val2,utxo->iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->deposit.txid,utxo->deposit.vout) == 0 ) |
|||
continue; |
|||
if ( polarity > 0 ) |
|||
basesatoshis = utxo->S.satoshis; |
|||
else basesatoshis = utxo->S.satoshis * price; |
|||
//char str[65]; printf("found utxo not in orderbook %s/v%d %.8f %.8f\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,dstr(basesatoshis),polarity > 0 ? price : 1./price);
|
|||
if ( (op= LP_orderbookentry(base,rel,utxo->payment.txid,utxo->payment.vout,utxo->deposit.txid,utxo->deposit.vout,polarity > 0 ? price : 1./price,basesatoshis,utxo->pubkey,now - pubp->timestamp)) != 0 ) |
|||
{ |
|||
*arrayp = realloc(*arrayp,sizeof(*(*arrayp)) * (num+1)); |
|||
(*arrayp)[num++] = op; |
|||
if ( LP_ismine(utxo) > 0 && utxo->T.lasttime == 0 ) |
|||
LP_utxo_clientpublish(utxo); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return(num); |
|||
} |
|||
|
|||
char *LP_orderbook(char *base,char *rel,int32_t duration) |
|||
{ |
|||
uint32_t now,i; struct LP_priceinfo *basepp=0,*relpp=0; struct LP_orderbookentry **bids = 0,**asks = 0; cJSON *retjson,*array; int32_t numbids=0,numasks=0,cachenumbids,cachenumasks,baseid,relid; |
|||
if ( (basepp= LP_priceinfofind(base)) == 0 || (relpp= LP_priceinfofind(rel)) == 0 ) |
|||
return(clonestr("{\"error\":\"base or rel not added\"}")); |
|||
if ( duration <= 0 ) |
|||
duration = LP_ORDERBOOK_DURATION; |
|||
baseid = basepp->ind; |
|||
relid = relpp->ind; |
|||
now = (uint32_t)time(NULL); |
|||
cachenumbids = numbids, cachenumasks = numasks; |
|||
//printf("start cache.(%d %d) numbids.%d numasks.%d\n",cachenumbids,cachenumasks,numbids,numasks);
|
|||
numasks = LP_orderbook_utxoentries(now,1,base,rel,&asks,numasks,cachenumasks,duration); |
|||
numbids = LP_orderbook_utxoentries(now,-1,rel,base,&bids,numbids,cachenumbids,duration); |
|||
retjson = cJSON_CreateObject(); |
|||
array = cJSON_CreateArray(); |
|||
if ( numbids > 1 ) |
|||
qsort(bids,numbids,sizeof(*bids),_cmp_orderbook); |
|||
if ( numasks > 1 ) |
|||
{ |
|||
//for (i=0; i<numasks; i++)
|
|||
// printf("%.8f ",asks[i]->price);
|
|||
//printf(" -> ");
|
|||
qsort(asks,numasks,sizeof(*asks),_cmp_orderbook); |
|||
//for (i=0; i<numasks; i++)
|
|||
// printf("%.8f ",asks[i]->price);
|
|||
//printf("sorted asks.%d\n",numasks);
|
|||
} |
|||
for (i=0; i<numbids; i++) |
|||
{ |
|||
jaddi(array,LP_orderbookjson(bids[i])); |
|||
free(bids[i]); |
|||
bids[i] = 0; |
|||
} |
|||
jadd(retjson,"bids",array); |
|||
jaddnum(retjson,"numbids",numbids); |
|||
array = cJSON_CreateArray(); |
|||
for (i=0; i<numasks; i++) |
|||
{ |
|||
jaddi(array,LP_orderbookjson(asks[i])); |
|||
free(asks[i]); |
|||
asks[i] = 0; |
|||
} |
|||
jadd(retjson,"asks",array); |
|||
jaddnum(retjson,"numasks",numasks); |
|||
jaddstr(retjson,"base",base); |
|||
jaddstr(retjson,"rel",rel); |
|||
jaddnum(retjson,"timestamp",now); |
|||
if ( bids != 0 ) |
|||
free(bids); |
|||
if ( asks != 0 ) |
|||
free(asks); |
|||
return(jprint(retjson,1)); |
|||
} |
|||
|
|||
char *LP_pricestr(char *base,char *rel,double origprice) |
|||
{ |
|||
cJSON *retjson; double price = 0.; |
|||
if ( base != 0 && base[0] != 0 && rel != 0 && rel[0] != 0 ) |
|||
{ |
|||
price = LP_price(base,rel); |
|||
if ( origprice > SMALLVAL && origprice < price ) |
|||
price = origprice; |
|||
} |
|||
if ( LP_pricevalid(price) > 0 ) |
|||
{ |
|||
retjson = cJSON_CreateObject(); |
|||
jaddstr(retjson,"result","success"); |
|||
jaddstr(retjson,"method","postprice"); |
|||
jaddbits256(retjson,"pubkey",LP_mypub25519); |
|||
jaddstr(retjson,"base",base); |
|||
jaddstr(retjson,"rel",rel); |
|||
jaddnum(retjson,"price",price); |
|||
jadd(retjson,"theoretical",LP_priceinfomatrix(0)); |
|||
jadd(retjson,"quotes",LP_priceinfomatrix(1)); |
|||
return(jprint(retjson,1)); |
|||
} else return(clonestr("{\"error\":\"cant find baserel pair\"}")); |
|||
} |
|||
|
|||
void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveask,double highbid,double lowask,double PAXPRICES[32]) |
|||
{ |
|||
LP_priceinfoupdate(base,rel,price); |
|||
} |
|||
|
|||
void LP_pricefname(char *fname,char *base,char *rel) |
|||
{ |
|||
sprintf(fname,"%s/PRICES/%s_%s",GLOBAL_DBDIR,base,rel); |
|||
OS_compatible_path(fname); |
|||
} |
|||
|
|||
void LP_priceitemadd(cJSON *retarray,uint32_t timestamp,double avebid,double aveask,double highbid,double lowask) |
|||
{ |
|||
cJSON *item = cJSON_CreateArray(); |
|||
jaddinum(item,timestamp); |
|||
jaddinum(item,avebid); |
|||
jaddinum(item,aveask); |
|||
jaddinum(item,highbid); |
|||
jaddinum(item,lowask); |
|||
jaddi(retarray,item); |
|||
} |
|||
|
|||
cJSON *LP_pricearray(char *base,char *rel,uint32_t firsttime,uint32_t lasttime,int32_t timescale) |
|||
{ |
|||
cJSON *retarray; char askfname[1024],bidfname[1024]; uint64_t bidprice64,askprice64; uint32_t bidnow,asknow,bidi,aski,lastbidi,lastaski; int32_t numbids,numasks; double bidemit,askemit,bidsum,asksum,bid,ask,highbid,lowbid,highask,lowask,bidemit2,askemit2; FILE *askfp=0,*bidfp=0; |
|||
if ( timescale <= 0 ) |
|||
timescale = 60; |
|||
if ( lasttime == 0 ) |
|||
lasttime = (uint32_t)-1; |
|||
LP_pricefname(askfname,base,rel); |
|||
LP_pricefname(bidfname,rel,base); |
|||
retarray = cJSON_CreateArray(); |
|||
lastbidi = lastaski = 0; |
|||
numbids = numasks = 0; |
|||
bidsum = asksum = askemit = bidemit = highbid = lowbid = highask = lowask = 0.; |
|||
if ( (bidfp= fopen(bidfname,"rb")) != 0 && (askfp= fopen(askfname,"rb")) != 0 ) |
|||
{ |
|||
while ( bidfp != 0 || askfp != 0 ) |
|||
{ |
|||
bidi = aski = 0; |
|||
bidemit = askemit = bidemit2 = askemit2 = 0.; |
|||
if ( bidfp != 0 && fread(&bidnow,1,sizeof(bidnow),bidfp) == sizeof(bidnow) && fread(&bidprice64,1,sizeof(bidprice64),bidfp) == sizeof(bidprice64) ) |
|||
{ |
|||
//printf("bidnow.%u %.8f\n",bidnow,dstr(bidprice64));
|
|||
if ( bidnow != 0 && bidprice64 != 0 && bidnow >= firsttime && bidnow <= lasttime ) |
|||
{ |
|||
bidi = bidnow / timescale; |
|||
if ( bidi != lastbidi ) |
|||
{ |
|||
if ( bidsum != 0. && numbids != 0 ) |
|||
{ |
|||
bidemit = bidsum / numbids; |
|||
bidemit2 = highbid; |
|||
} |
|||
bidsum = highbid = lowbid = 0.; |
|||
numbids = 0; |
|||
} |
|||
if ( (bid= 1. / dstr(bidprice64)) != 0. ) |
|||
{ |
|||
if ( bid > highbid ) |
|||
highbid = bid; |
|||
if ( lowbid == 0. || bid < lowbid ) |
|||
lowbid = bid; |
|||
bidsum += bid; |
|||
numbids++; |
|||
//printf("bidi.%u num.%d %.8f [%.8f %.8f]\n",bidi,numbids,bid,lowbid,highbid);
|
|||
} |
|||
} |
|||
} else fclose(bidfp), bidfp = 0; |
|||
if ( askfp != 0 && fread(&asknow,1,sizeof(asknow),askfp) == sizeof(asknow) && fread(&askprice64,1,sizeof(askprice64),askfp) == sizeof(askprice64) ) |
|||
{ |
|||
//printf("asknow.%u %.8f\n",asknow,dstr(askprice64));
|
|||
if ( asknow != 0 && askprice64 != 0 && asknow >= firsttime && asknow <= lasttime ) |
|||
{ |
|||
aski = asknow / timescale; |
|||
if ( aski != lastaski ) |
|||
{ |
|||
if ( asksum != 0. && numasks != 0 ) |
|||
{ |
|||
askemit = asksum / numasks; |
|||
askemit2 = lowask; |
|||
} |
|||
asksum = highask = lowask = 0.; |
|||
numasks = 0; |
|||
} |
|||
if ( (ask= dstr(askprice64)) != 0. ) |
|||
{ |
|||
if ( ask > highask ) |
|||
highask = ask; |
|||
if ( lowask == 0. || ask < lowask ) |
|||
lowask = ask; |
|||
asksum += ask; |
|||
numasks++; |
|||
//printf("aski.%u num.%d %.8f [%.8f %.8f]\n",aski,numasks,ask,lowask,highask);
|
|||
} |
|||
} |
|||
} else fclose(askfp), askfp = 0; |
|||
if ( bidemit != 0. || askemit != 0. ) |
|||
{ |
|||
if ( bidemit != 0. && askemit != 0. && lastbidi == lastaski ) |
|||
{ |
|||
LP_priceitemadd(retarray,lastbidi * timescale,bidemit,askemit,bidemit2,askemit2); |
|||
highbid = lowbid = highask = lowask = 0.; |
|||
} |
|||
else |
|||
{ |
|||
if ( bidemit != 0. ) |
|||
{ |
|||
printf("bidonly %.8f %.8f\n",bidemit,highbid); |
|||
LP_priceitemadd(retarray,lastbidi * timescale,bidemit,0.,bidemit2,0.); |
|||
highbid = lowbid = 0.; |
|||
} |
|||
if ( askemit != 0. ) |
|||
{ |
|||
printf("askonly %.8f %.8f\n",askemit,lowask); |
|||
LP_priceitemadd(retarray,lastaski * timescale,0.,askemit,0.,askemit2); |
|||
highask = lowask = 0.; |
|||
} |
|||
} |
|||
} |
|||
if ( bidi != 0 ) |
|||
lastbidi = bidi; |
|||
if ( aski != 0 ) |
|||
lastaski = aski; |
|||
} |
|||
} else printf("couldnt open either %s %p or %s %p\n",bidfname,bidfp,askfname,askfp); |
|||
if ( bidfp != 0 ) |
|||
fclose(bidfp); |
|||
if ( askfp != 0 ) |
|||
fclose(askfp); |
|||
return(retarray); |
|||
} |
|||
|
|||
void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) |
|||
{ |
|||
struct LP_priceinfo *basepp,*relpp; uint32_t now; uint64_t price64; struct LP_pubkeyinfo *pubp; char str[65],fname[512]; FILE *fp; |
|||
//printf("check PRICEFEED UPDATE.(%s/%s) %.8f %s\n",base,rel,price,bits256_str(str,pubkey));
|
|||
if ( LP_pricevalid(price) > 0 && (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) |
|||
{ |
|||
if ( (fp= basepp->fps[relpp->ind]) == 0 ) |
|||
{ |
|||
LP_pricefname(fname,base,rel); |
|||
fp = basepp->fps[relpp->ind] = OS_appendfile(fname); |
|||
} |
|||
if ( fp != 0 ) |
|||
{ |
|||
now = (uint32_t)time(NULL); |
|||
price64 = price * SATOSHIDEN; |
|||
fwrite(&now,1,sizeof(now),fp); |
|||
fwrite(&price64,1,sizeof(price64),fp); |
|||
fflush(fp); |
|||
} |
|||
if ( (fp= relpp->fps[basepp->ind]) == 0 ) |
|||
{ |
|||
sprintf(fname,"%s/PRICES/%s_%s",GLOBAL_DBDIR,rel,base); |
|||
fp = relpp->fps[basepp->ind] = OS_appendfile(fname); |
|||
} |
|||
if ( fp != 0 ) |
|||
{ |
|||
now = (uint32_t)time(NULL); |
|||
price64 = (1. / price) * SATOSHIDEN; |
|||
fwrite(&now,1,sizeof(now),fp); |
|||
fwrite(&price64,1,sizeof(price64),fp); |
|||
fflush(fp); |
|||
} |
|||
if ( (pubp= LP_pubkeyadd(pubkey)) != 0 ) |
|||
{ |
|||
if ( (rand() % 100) == 0 && fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) |
|||
printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price); |
|||
{ |
|||
pubp->matrix[basepp->ind][relpp->ind] = price; |
|||
dxblend(&basepp->relvals[relpp->ind],price,0.9); |
|||
dxblend(&relpp->relvals[basepp->ind],1. / price,0.9); |
|||
} |
|||
pubp->timestamp = (uint32_t)time(NULL); |
|||
} else printf("error creating pubkey entry\n"); |
|||
} |
|||
else if ( (rand() % 100) == 0 ) |
|||
printf("error finding %s/%s %.8f\n",base,rel,price); |
|||
} |
|||
|
File diff suppressed because it is too large
@ -0,0 +1,412 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_rpc.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
char *LP_issue_curl(char *debugstr,char *destip,uint16_t port,char *url) |
|||
{ |
|||
char *retstr = 0; int32_t maxerrs; struct LP_peerinfo *peer = 0; |
|||
peer = LP_peerfind((uint32_t)calc_ipbits(destip),port); |
|||
maxerrs = LP_MAXPEER_ERRORS; |
|||
if ( peer == 0 || (peer->errors < maxerrs || peer->good >= LP_MINPEER_GOOD) ) |
|||
{ |
|||
if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) == 0 ) |
|||
{ |
|||
if ( peer != 0 ) |
|||
{ |
|||
peer->errors++; |
|||
peer->good *= LP_PEERGOOD_ERRORDECAY; |
|||
} else printf("%s error on (%s:%u) without peer\n",debugstr,destip,port); |
|||
} |
|||
else if ( peer != 0 ) |
|||
peer->good++; |
|||
} |
|||
return(retstr); |
|||
} |
|||
|
|||
char *LP_isitme(char *destip,uint16_t destport) |
|||
{ |
|||
if ( LP_mypeer != 0 && strcmp(destip,LP_mypeer->ipaddr) == 0 && LP_mypeer->port == destport ) |
|||
{ |
|||
//printf("no need to notify ourselves\n");
|
|||
return(clonestr("{\"result\":\"success\"}")); |
|||
} else return(0); |
|||
} |
|||
|
|||
char *issue_LP_getpeers(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos) |
|||
{ |
|||
char url[512],*retstr; |
|||
sprintf(url,"http://%s:%u/api/stats/getpeers?ipaddr=%s&port=%u&numpeers=%d&numutxos=%d",destip,destport,ipaddr,port,numpeers,numutxos); |
|||
retstr = LP_issue_curl("getpeers",destip,port,url); |
|||
//printf("%s -> getpeers.(%s)\n",destip,retstr);
|
|||
return(retstr); |
|||
} |
|||
|
|||
char *issue_LP_numutxos(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos) |
|||
{ |
|||
char url[512],*retstr; |
|||
sprintf(url,"http://%s:%u/api/stats/numutxos?ipaddr=%s&port=%u&numpeers=%d&numutxos=%d",destip,destport,ipaddr,port,numpeers,numutxos); |
|||
retstr = LP_issue_curl("numutxos",destip,port,url); |
|||
//printf("%s -> getpeers.(%s)\n",destip,retstr);
|
|||
return(retstr); |
|||
} |
|||
|
|||
char *issue_LP_getutxos(char *destip,uint16_t destport,char *coin,int32_t lastn,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos) |
|||
{ |
|||
char url[512]; |
|||
sprintf(url,"http://%s:%u/api/stats/getutxos?coin=%s&lastn=%d&ipaddr=%s&port=%u&numpeers=%d&numutxos=%d",destip,destport,coin,lastn,ipaddr,port,numpeers,numutxos); |
|||
return(LP_issue_curl("getutxos",destip,destport,url)); |
|||
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
|
|||
} |
|||
|
|||
char *issue_LP_clientgetutxos(char *destip,uint16_t destport,char *coin,int32_t lastn) |
|||
{ |
|||
char url[512];//,*retstr;
|
|||
sprintf(url,"http://%s:%u/api/stats/getutxos?coin=%s&lastn=%d&ipaddr=127.0.0.1&port=0",destip,destport,coin,lastn); |
|||
return(LP_issue_curl("clientgetutxos",destip,destport,url)); |
|||
//retstr = issue_curlt(url,LP_HTTP_TIMEOUT);
|
|||
//printf("%s clientgetutxos.(%s)\n",url,retstr);
|
|||
//return(retstr);
|
|||
} |
|||
|
|||
char *issue_LP_notify(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos,uint32_t sessionid) |
|||
{ |
|||
char url[512],*retstr; |
|||
if ( (retstr= LP_isitme(destip,destport)) != 0 ) |
|||
return(retstr); |
|||
sprintf(url,"http://%s:%u/api/stats/notify?ipaddr=%s&port=%u&numpeers=%d&numutxos=%d&session=%u",destip,destport,ipaddr,port,numpeers,numutxos,sessionid); |
|||
return(LP_issue_curl("notify",destip,destport,url)); |
|||
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
|
|||
} |
|||
|
|||
char *issue_LP_getprices(char *destip,uint16_t destport) |
|||
{ |
|||
char url[512]; |
|||
sprintf(url,"http://%s:%u/api/stats/getprices",destip,destport); |
|||
//printf("getutxo.(%s)\n",url);
|
|||
return(LP_issue_curl("getprices",destip,destport,url)); |
|||
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
|
|||
} |
|||
|
|||
cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params) |
|||
{ |
|||
char *retstr; cJSON *retjson = 0; |
|||
if ( coin != 0 ) |
|||
{ |
|||
//printf("issue.(%s, %s, %s, %s, %s)\n",coin->symbol,coin->serverport,coin->userpass,method,params);
|
|||
if ( coin->inactive == 0 || strcmp(method,"importprivkey") == 0 || strcmp(method,"validateaddress") == 0 ) |
|||
{ |
|||
retstr = bitcoind_passthru(coin->symbol,coin->serverport,coin->userpass,method,params); |
|||
if ( retstr != 0 && retstr[0] != 0 ) |
|||
{ |
|||
//printf("%s: %s.%s -> (%s)\n",coin->symbol,method,params,retstr);
|
|||
retjson = cJSON_Parse(retstr); |
|||
free(retstr); |
|||
} |
|||
//usleep(100);
|
|||
//printf("dpow_gettxout.(%s)\n",retstr);
|
|||
} else retjson = cJSON_Parse("{\"result\":\"disabled\"}"); |
|||
} else printf("bitcoin_json cant talk to NULL coin\n"); |
|||
return(retjson); |
|||
} |
|||
|
|||
void LP_unspents_mark(char *symbol,cJSON *vins) |
|||
{ |
|||
printf("LOCK (%s)\n",jprint(vins,0)); |
|||
} |
|||
|
|||
char *NXTnodes[] = { "62.75.159.113", "91.44.203.238", "82.114.88.225", "78.63.207.76", "188.174.110.224", "91.235.72.49", "213.144.130.91", "209.222.98.250", "216.155.128.10", "178.33.203.157", "162.243.122.251", "69.163.47.173", "193.151.106.129", "78.94.2.74", "192.3.196.10", "173.33.112.87", "104.198.173.28", "35.184.154.126", "174.140.167.239", "23.88.113.131", "198.71.84.173", "178.150.207.53", "23.88.61.53", "192.157.233.106", "192.157.241.212", "23.89.192.88", "23.89.200.27", "192.157.241.139", "23.89.200.63", "23.89.192.98", "163.172.214.102", "176.9.85.5", "80.150.243.88", "80.150.243.92", "80.150.243.98", "109.70.186.198", "146.148.84.237", "104.155.56.82", "104.197.157.140", "37.48.73.249", "146.148.77.226", "84.57.170.200", "107.161.145.131", "80.150.243.97", "80.150.243.93", "80.150.243.100", "80.150.243.95", "80.150.243.91", "80.150.243.99", "80.150.243.96", "93.231.187.177", "212.237.23.85", "35.158.179.254", "46.36.66.41", "185.170.113.79", "163.172.68.112", "78.47.35.210", "77.90.90.75", "94.177.196.134", "212.237.22.215", "94.177.234.11", "167.160.180.199", "54.68.189.9", "94.159.62.14", "195.181.221.89", "185.33.145.94", "195.181.209.245", "195.181.221.38", "195.181.221.162", "185.33.145.12", "185.33.145.176", "178.79.128.235", "94.177.214.120", "94.177.199.41", "94.177.214.200", "94.177.213.201", "212.237.13.162", "195.181.221.236", "195.181.221.185", "185.28.103.187", "185.33.146.244", "217.61.123.71", "195.181.214.45", "195.181.212.99", "195.181.214.46", "195.181.214.215", "195.181.214.68", "217.61.123.118", "195.181.214.79", "217.61.123.14", "217.61.124.100", "195.181.214.111", "85.255.0.176", "81.2.254.116", "217.61.123.184", "195.181.212.231", "94.177.214.110", "195.181.209.164", "104.129.56.238", "85.255.13.64", "167.160.180.206", "217.61.123.226", "167.160.180.208", "93.186.253.127", "212.237.6.208", "94.177.207.190", "217.61.123.119", "85.255.1.245", "217.61.124.157", "37.59.57.141", "167.160.180.58", "104.223.53.14", "217.61.124.69", "195.181.212.103", "85.255.13.141", "104.207.133.204", "71.90.7.107", "107.150.18.108", "23.94.134.161", "80.150.243.13", "80.150.243.11", "185.81.165.52", "80.150.243.8" }; |
|||
|
|||
|
|||
cJSON *LP_assethbla(char *assetid) |
|||
{ |
|||
char url[1024],*retstr; int32_t n; cJSON *array,*bid=0,*ask=0,*retjson; |
|||
sprintf(url,"http://%s:7876/nxt?=%%2Fnxt&requestType=getBidOrders&asset=%s&firstIndex=0&lastIndex=0",NXTnodes[rand() % (sizeof(NXTnodes)/sizeof(*NXTnodes))],assetid); |
|||
if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 ) |
|||
{ |
|||
bid = cJSON_Parse(retstr); |
|||
free(retstr); |
|||
} |
|||
sprintf(url,"http://%s:7876/nxt?=%%2Fnxt&requestType=getAskOrders&asset=%s&firstIndex=0&lastIndex=0",NXTnodes[rand() % (sizeof(NXTnodes)/sizeof(*NXTnodes))],assetid); |
|||
if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 ) |
|||
{ |
|||
ask = cJSON_Parse(retstr); |
|||
free(retstr); |
|||
} |
|||
retjson = cJSON_CreateObject(); |
|||
if ( bid != 0 && ask != 0 ) |
|||
{ |
|||
if ( (array= jarray(&n,bid,"bidOrders")) != 0 ) |
|||
jadd(retjson,"bid",jduplicate(jitem(array,0))); |
|||
if ( (array= jarray(&n,ask,"askOrders")) != 0 ) |
|||
jadd(retjson,"ask",jduplicate(jitem(array,0))); |
|||
} |
|||
if ( bid != 0 ) |
|||
free_json(bid); |
|||
if ( ask != 0 ) |
|||
free_json(ask); |
|||
return(retjson); |
|||
} |
|||
|
|||
cJSON *LP_getinfo(char *symbol) |
|||
{ |
|||
struct iguana_info *coin = LP_coinfind(symbol); |
|||
return(bitcoin_json(coin,"getinfo","[]")); |
|||
} |
|||
|
|||
cJSON *LP_getmempool(char *symbol) |
|||
{ |
|||
struct iguana_info *coin = LP_coinfind(symbol); |
|||
return(bitcoin_json(coin,"getrawmempool","[]")); |
|||
} |
|||
|
|||
cJSON *LP_paxprice(char *fiat) |
|||
{ |
|||
char buf[128],lfiat[65]; struct iguana_info *coin = LP_coinfind("KMD"); |
|||
strcpy(lfiat,fiat); |
|||
tolowercase(lfiat); |
|||
sprintf(buf,"[\"%s\", \"kmd\"]",lfiat); |
|||
return(bitcoin_json(coin,"paxprice",buf)); |
|||
} |
|||
|
|||
cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) |
|||
{ |
|||
char buf[128],str[65]; struct iguana_info *coin = LP_coinfind(symbol); |
|||
sprintf(buf,"[\"%s\", %d, true]",bits256_str(str,txid),vout); |
|||
return(bitcoin_json(coin,"gettxout",buf)); |
|||
} |
|||
|
|||
cJSON *LP_gettx(char *symbol,bits256 txid) |
|||
{ |
|||
char buf[128],str[65]; struct iguana_info *coin = LP_coinfind(symbol); |
|||
sprintf(buf,"[\"%s\", 1]",bits256_str(str,txid)); |
|||
return(bitcoin_json(coin,"getrawtransaction",buf)); |
|||
} |
|||
|
|||
cJSON *LP_getblock(char *symbol,bits256 txid) |
|||
{ |
|||
char buf[128],str[65]; struct iguana_info *coin = LP_coinfind(symbol); |
|||
sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); |
|||
return(bitcoin_json(coin,"getblock",buf)); |
|||
} |
|||
|
|||
cJSON *LP_getblockhashstr(char *symbol,char *blockhashstr) |
|||
{ |
|||
char buf[128]; struct iguana_info *coin = LP_coinfind(symbol); |
|||
sprintf(buf,"[\"%s\"]",blockhashstr); |
|||
return(bitcoin_json(coin,"getblock",buf)); |
|||
} |
|||
|
|||
cJSON *LP_listunspent(char *symbol,char *coinaddr) |
|||
{ |
|||
char buf[128]; struct iguana_info *coin = LP_coinfind(symbol); |
|||
sprintf(buf,"[0, 99999999, [\"%s\"]]",coinaddr); |
|||
return(bitcoin_json(coin,"listunspent",buf)); |
|||
} |
|||
|
|||
cJSON *LP_listtransactions(char *symbol,char *coinaddr,int32_t count,int32_t skip) |
|||
{ |
|||
char buf[128]; struct iguana_info *coin = LP_coinfind(symbol); |
|||
if ( count == 0 ) |
|||
count = 100; |
|||
sprintf(buf,"[\"%s\", %d, %d, true]",coinaddr,count,skip); |
|||
return(bitcoin_json(coin,"listtransactions",buf)); |
|||
} |
|||
|
|||
cJSON *LP_validateaddress(char *symbol,char *address) |
|||
{ |
|||
char buf[512]; struct iguana_info *coin = LP_coinfind(symbol); |
|||
sprintf(buf,"[\"%s\"]",address); |
|||
return(bitcoin_json(coin,"validateaddress",buf)); |
|||
} |
|||
|
|||
cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag) |
|||
{ |
|||
static void *ctx; |
|||
char buf[512],address[64]; cJSON *retjson; struct iguana_info *coin; int32_t doneflag = 0; |
|||
coin = LP_coinfind(symbol); |
|||
if ( ctx == 0 ) |
|||
ctx = bitcoin_ctx(); |
|||
bitcoin_wif2addr(ctx,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr); |
|||
if ( (retjson= LP_validateaddress(symbol,address)) != 0 ) |
|||
{ |
|||
if ( jobj(retjson,"ismine") != 0 && is_cJSON_True(jobj(retjson,"ismine")) != 0 ) |
|||
{ |
|||
doneflag = 1; |
|||
//printf("%s already ismine\n",address);
|
|||
} |
|||
//printf("%s\n",jprint(retjson,0));
|
|||
free_json(retjson); |
|||
} |
|||
if ( doneflag == 0 ) |
|||
{ |
|||
if ( coin->noimportprivkey_flag != 0 ) |
|||
sprintf(buf,"[\"%s\"]",wifstr); |
|||
else sprintf(buf,"\"%s\", \"%s\", %s",wifstr,label,flag < 0 ? "false" : "true"); |
|||
return(bitcoin_json(coin,"importprivkey",buf)); |
|||
} else return(cJSON_Parse("{\"result\":\"success\"}")); |
|||
} |
|||
|
|||
int32_t LP_importaddress(char *symbol,char *address) |
|||
{ |
|||
char buf[1024],*retstr; cJSON *validatejson; int32_t isvalid=0,doneflag = 0; struct iguana_info *coin = LP_coinfind(symbol); |
|||
if ( coin == 0 ) |
|||
return(-2); |
|||
if ( (validatejson= LP_validateaddress(symbol,address)) != 0 ) |
|||
{ |
|||
if ( (isvalid= is_cJSON_True(jobj(validatejson,"isvalid")) != 0) != 0 ) |
|||
{ |
|||
if ( is_cJSON_True(jobj(validatejson,"iswatchonly")) != 0 || is_cJSON_True(jobj(validatejson,"ismine")) != 0 ) |
|||
doneflag = 1; |
|||
} |
|||
free_json(validatejson); |
|||
} |
|||
if ( isvalid == 0 ) |
|||
return(-1); |
|||
if ( doneflag != 0 ) |
|||
return(0); // success
|
|||
sprintf(buf,"[\"%s\", \"%s\", false]",address,address); |
|||
if ( (retstr= bitcoind_passthru(symbol,coin->serverport,coin->userpass,"importaddress",buf)) != 0 ) |
|||
{ |
|||
//printf("importaddress.(%s %s) -> (%s)\n",symbol,address,retstr);
|
|||
free(retstr); |
|||
} //else printf("importaddress.(%s %s)\n",symbol,address);
|
|||
return(1); |
|||
} |
|||
|
|||
double LP_getestimatedrate(char *symbol) |
|||
{ |
|||
char buf[512],*retstr; double rate = 20; struct iguana_info *coin = LP_coinfind(symbol); |
|||
if ( coin != 0 && (strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0) ) |
|||
{ |
|||
sprintf(buf,"[%d]",3); |
|||
if ( (retstr= bitcoind_passthru(symbol,coin->serverport,coin->userpass,"estimatefee",buf)) != 0 ) |
|||
{ |
|||
if ( retstr[0] != '-' ) |
|||
{ |
|||
rate = atof(retstr) / 1024.; |
|||
//printf("estimated rate.(%s) %s -> %.8f\n",symbol,retstr,rate);
|
|||
} |
|||
free(retstr); |
|||
} |
|||
} else return((double)coin->txfee / LP_AVETXSIZE); |
|||
return(SATOSHIDEN * rate); |
|||
} |
|||
|
|||
uint64_t LP_txfee(char *symbol) |
|||
{ |
|||
uint64_t txfee = 0; |
|||
if ( strcmp(symbol,"BTC") != 0 ) |
|||
txfee = LP_MIN_TXFEE; |
|||
return(txfee); |
|||
} |
|||
|
|||
char *LP_blockhashstr(char *symbol,int32_t height) |
|||
{ |
|||
cJSON *array; char *paramstr,*retstr; struct iguana_info *coin = LP_coinfind(symbol); |
|||
if ( coin == 0 ) |
|||
return(0); |
|||
array = cJSON_CreateArray(); |
|||
jaddinum(array,height); |
|||
paramstr = jprint(array,1); |
|||
retstr = bitcoind_passthru(symbol,coin->serverport,coin->userpass,"getblockhash",paramstr); |
|||
free(paramstr); |
|||
return(retstr); |
|||
} |
|||
|
|||
char *LP_sendrawtransaction(char *symbol,char *signedtx) |
|||
{ |
|||
cJSON *array; char *paramstr,*retstr; struct iguana_info *coin = LP_coinfind(symbol); |
|||
if ( coin == 0 ) |
|||
return(0); |
|||
array = cJSON_CreateArray(); |
|||
jaddistr(array,signedtx); |
|||
paramstr = jprint(array,1); |
|||
retstr = bitcoind_passthru(symbol,coin->serverport,coin->userpass,"sendrawtransaction",paramstr); |
|||
//printf(">>>>>>>>>>> %s dpow_sendrawtransaction.(%s) -> (%s)\n",coin->symbol,paramstr,retstr);
|
|||
free(paramstr); |
|||
return(retstr); |
|||
} |
|||
|
|||
char *LP_signrawtx(char *symbol,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkeys,struct vin_info *V) |
|||
{ |
|||
cJSON *array,*json; int32_t len; uint8_t *data; char *paramstr,*retstr,*hexstr,*signedtx=0; struct iguana_info *coin = LP_coinfind(symbol); |
|||
memset(signedtxidp,0,sizeof(*signedtxidp)); |
|||
*completedp = 0; |
|||
if ( coin == 0 ) |
|||
{ |
|||
printf("LP_signrawtx cant find coin.(%s)\n",symbol); |
|||
return(0); |
|||
} |
|||
array = cJSON_CreateArray(); |
|||
jaddistr(array,rawtx); |
|||
jaddi(array,jduplicate(vins)); |
|||
jaddi(array,jduplicate(privkeys)); |
|||
paramstr = jprint(array,1); |
|||
//printf("signrawtransaction\n");
|
|||
if ( (retstr= bitcoind_passthru(symbol,coin->serverport,coin->userpass,"signrawtransaction",paramstr)) != 0 ) |
|||
{ |
|||
if ( (json= cJSON_Parse(retstr)) != 0 ) |
|||
{ |
|||
if ( (hexstr= jstr(json,"hex")) != 0 ) |
|||
{ |
|||
len = (int32_t)strlen(hexstr); |
|||
signedtx = calloc(1,len+1); |
|||
strcpy(signedtx,hexstr); |
|||
*completedp = is_cJSON_True(jobj(json,"complete")); |
|||
data = malloc(len >> 1); |
|||
decode_hex(data,len>>1,hexstr); |
|||
*signedtxidp = bits256_doublesha256(0,data,len >> 1); |
|||
} |
|||
//else
|
|||
printf("%s signrawtransaction.(%s) params.(%s)\n",coin->symbol,retstr,paramstr); |
|||
free_json(json); |
|||
} |
|||
free(retstr); |
|||
} |
|||
free(paramstr); |
|||
return(signedtx); |
|||
} |
|||
|
|||
cJSON *LP_blockjson(int32_t *heightp,char *symbol,char *blockhashstr,int32_t height) |
|||
{ |
|||
cJSON *json = 0; int32_t flag = 0; |
|||
if ( blockhashstr == 0 ) |
|||
blockhashstr = LP_blockhashstr(symbol,height), flag = 1; |
|||
if ( blockhashstr != 0 ) |
|||
{ |
|||
if ( (json= LP_getblockhashstr(symbol,blockhashstr)) != 0 ) |
|||
{ |
|||
if ( *heightp != 0 ) |
|||
{ |
|||
*heightp = juint(json,"height"); |
|||
if ( height >= 0 && *heightp != height ) |
|||
{ |
|||
printf("unexpected height %d vs %d for %s (%s)\n",*heightp,height,blockhashstr,jprint(json,0)); |
|||
*heightp = -1; |
|||
free_json(json); |
|||
json = 0; |
|||
} |
|||
} |
|||
} |
|||
if ( flag != 0 && blockhashstr != 0 ) |
|||
free(blockhashstr); |
|||
} |
|||
return(json); |
|||
} |
|||
|
@ -0,0 +1,626 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_scan.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
|
|||
struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr) |
|||
{ |
|||
struct LP_address *ap; |
|||
HASH_FIND(hh,coin->addresses,coinaddr,strlen(coinaddr),ap); |
|||
return(ap); |
|||
} |
|||
|
|||
struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr) |
|||
{ |
|||
struct LP_address *ap; |
|||
ap = calloc(1,sizeof(*ap)); |
|||
safecopy(ap->coinaddr,coinaddr,sizeof(ap->coinaddr)); |
|||
HASH_ADD_KEYPTR(hh,coin->addresses,ap->coinaddr,strlen(ap->coinaddr),ap); |
|||
return(ap); |
|||
} |
|||
|
|||
struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) |
|||
{ |
|||
struct LP_address *ap; |
|||
if ( (ap= _LP_addressfind(coin,coinaddr)) == 0 ) |
|||
ap = _LP_addressadd(coin,coinaddr); |
|||
return(ap); |
|||
} |
|||
|
|||
struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid) |
|||
{ |
|||
struct LP_transaction *tx; |
|||
portable_mutex_lock(&coin->txmutex); |
|||
HASH_FIND(hh,coin->transactions,txid.bytes,sizeof(txid),tx); |
|||
portable_mutex_unlock(&coin->txmutex); |
|||
return(tx); |
|||
} |
|||
|
|||
struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,int32_t height,int32_t numvouts,int32_t numvins,uint32_t timestamp) |
|||
{ |
|||
struct LP_transaction *tx; int32_t i; |
|||
if ( (tx= LP_transactionfind(coin,txid)) == 0 ) |
|||
{ |
|||
//char str[65]; printf("%s ht.%d u.%u NEW TXID.(%s) vouts.[%d]\n",coin->symbol,height,timestamp,bits256_str(str,txid),numvouts);
|
|||
//if ( bits256_nonz(txid) == 0 && tx->height == 0 )
|
|||
// getchar();
|
|||
tx = calloc(1,sizeof(*tx) + (sizeof(*tx->outpoints) * numvouts)); |
|||
for (i=0; i<numvouts; i++) |
|||
tx->outpoints[i].spendvini = -1; |
|||
tx->height = height; |
|||
tx->numvouts = numvouts; |
|||
tx->numvins = numvins; |
|||
tx->timestamp = timestamp; |
|||
tx->txid = txid; |
|||
portable_mutex_lock(&coin->txmutex); |
|||
HASH_ADD_KEYPTR(hh,coin->transactions,tx->txid.bytes,sizeof(tx->txid),tx); |
|||
portable_mutex_unlock(&coin->txmutex); |
|||
} // else printf("warning adding already existing txid %s\n",bits256_str(str,tx->txid));
|
|||
return(tx); |
|||
} |
|||
|
|||
int32_t LP_txheight(uint32_t *timestampp,uint32_t *blocktimep,struct iguana_info *coin,bits256 txid) |
|||
{ |
|||
bits256 blockhash; cJSON *blockobj,*txobj; int32_t height = 0; |
|||
if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) |
|||
{ |
|||
*timestampp = juint(txobj,"locktime"); |
|||
*blocktimep = juint(txobj,"blocktime"); |
|||
blockhash = jbits256(txobj,"blockhash"); |
|||
if ( bits256_nonz(blockhash) != 0 && (blockobj= LP_getblock(coin->symbol,blockhash)) != 0 ) |
|||
{ |
|||
height = jint(blockobj,"height"); |
|||
//printf("%s LP_txheight.%d\n",coin->symbol,height);
|
|||
free_json(blockobj); |
|||
} //else printf("%s LP_txheight error (%s)\n",coin->symbol,jprint(txobj,0));
|
|||
free_json(txobj); |
|||
} |
|||
return(height); |
|||
} |
|||
|
|||
int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight) |
|||
{ |
|||
int32_t i,ht,num = 0; uint32_t timestamp,blocktime; struct LP_transaction *tx,*tmp; |
|||
HASH_ITER(hh,coin->transactions,tx,tmp) |
|||
{ |
|||
for (i=0; i<tx->numvouts; i++) |
|||
{ |
|||
if ( bits256_nonz(tx->outpoints[i].spendtxid) == 0 ) |
|||
continue; |
|||
if ( (ht= tx->outpoints[i].spendheight) == 0 ) |
|||
{ |
|||
tx->outpoints[i].spendheight = LP_txheight(×tamp,&blocktime,coin,tx->outpoints[i].spendtxid); |
|||
} |
|||
if ( (ht= tx->outpoints[i].spendheight) != 0 && ht > lastheight ) |
|||
{ |
|||
char str[65]; printf("clear spend %s/v%d at ht.%d > lastheight.%d\n",bits256_str(str,tx->txid),i,ht,lastheight); |
|||
tx->outpoints[i].spendheight = 0; |
|||
tx->outpoints[i].spendvini = -1; |
|||
memset(tx->outpoints[i].spendtxid.bytes,0,sizeof(bits256)); |
|||
} |
|||
} |
|||
} |
|||
return(num); |
|||
} |
|||
|
|||
uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_info *coin,bits256 txid,int32_t vout) |
|||
{ |
|||
uint64_t interest,value = 0; cJSON *txobj,*sobj,*array; int32_t n=0; |
|||
*interestp = 0; |
|||
destaddr[0] = 0; |
|||
if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) |
|||
{ |
|||
if ( (value= jdouble(txobj,"amount")*SATOSHIDEN) == 0 && (value= jdouble(txobj,"value")*SATOSHIDEN) == 0 ) |
|||
{ |
|||
char str[65]; printf("%s LP_txvalue.%s strange utxo.(%s) vout.%d\n",coin->symbol,bits256_str(str,txid),jprint(txobj,0),vout); |
|||
} |
|||
else if ( strcmp(coin->symbol,"KMD") == 0 ) |
|||
{ |
|||
if ( (interest= jdouble(txobj,"interest")) != 0. ) |
|||
{ |
|||
//printf("add interest of %.8f to %.8f\n",interest,dstr(value));
|
|||
*interestp = SATOSHIDEN * interest; |
|||
} |
|||
} |
|||
if ( (sobj= jobj(txobj,"scriptPubKey")) != 0 && (array= jarray(&n,sobj,"addresses")) != 0 ) |
|||
{ |
|||
strcpy(destaddr,jstri(array,0)); |
|||
if ( n > 1 ) |
|||
printf("LP_txinterestvalue warning: violation of 1 output assumption n.%d\n",n); |
|||
} else printf("LP_txinterestvalue no addresses found?\n"); |
|||
//char str[65]; printf("%s %.8f <- %s.(%s) txobj.(%s)\n",destaddr,dstr(value),coin->symbol,bits256_str(str,txid),jprint(txobj,0));
|
|||
free_json(txobj); |
|||
} else { char str[65]; printf("null gettxout return %s/v%d\n",bits256_str(str,txid),vout); } |
|||
return(value); |
|||
} |
|||
|
|||
int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) |
|||
{ |
|||
struct LP_transaction *tx; char *address; int32_t i,n,height,numvouts,numvins,spentvout; uint32_t timestamp,blocktime; cJSON *txobj,*vins,*vouts,*vout,*vin,*sobj,*addresses; bits256 spenttxid; char str[65]; |
|||
if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) |
|||
{ |
|||
//printf("TX.(%s)\n",jprint(txobj,0));
|
|||
height = LP_txheight(×tamp,&blocktime,coin,txid); |
|||
if ( timestamp == 0 && height > 0 ) |
|||
timestamp = blocktime; |
|||
vins = jarray(&numvins,txobj,"vin"); |
|||
vouts = jarray(&numvouts,txobj,"vout"); |
|||
if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins,timestamp)) != 0 ) |
|||
{ |
|||
for (i=0; i<numvouts; i++) |
|||
{ |
|||
vout = jitem(vouts,i); |
|||
if ( (tx->outpoints[i].value= SATOSHIDEN * jdouble(vout,"value")) == 0 ) |
|||
tx->outpoints[i].value = SATOSHIDEN * jdouble(vout,"amount"); |
|||
tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest"); |
|||
if ( (sobj= jobj(vout,"scriptPubKey")) != 0 ) |
|||
{ |
|||
if ( (addresses= jarray(&n,sobj,"addresses")) != 0 && n > 0 ) |
|||
{ |
|||
//printf("%s\n",jprint(addresses,0));
|
|||
if ( n > 1 ) |
|||
printf("LP_transactioninit: txid.(%s) multiple addresses.[%s]\n",bits256_str(str,txid),jprint(addresses,0)); |
|||
if ( (address= jstri(addresses,0)) != 0 && strlen(address) < sizeof(tx->outpoints[i].coinaddr) ) |
|||
{ |
|||
strcpy(tx->outpoints[i].coinaddr,address); |
|||
if ( 0 && strcmp(address,"RXzsovGBQ3W97xnVC6JnWxXsV4qb7p7iBi") == 0 ) |
|||
printf("%s %.8f at height.%d\n",address,dstr(tx->outpoints[i].value),height); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if ( iter == 1 && vins != 0 ) |
|||
{ |
|||
for (i=0; i<numvins; i++) |
|||
{ |
|||
vin = jitem(vins,i); |
|||
spenttxid = jbits256(vin,"txid"); |
|||
spentvout = jint(vin,"vout"); |
|||
if ( i == 0 && bits256_nonz(spenttxid) == 0 ) |
|||
continue; |
|||
if ( (tx= LP_transactionfind(coin,spenttxid)) != 0 ) |
|||
{ |
|||
if ( spentvout < tx->numvouts ) |
|||
{ |
|||
tx->outpoints[spentvout].spendtxid = txid; |
|||
tx->outpoints[spentvout].spendvini = i; |
|||
tx->outpoints[spentvout].spendheight = height; |
|||
//printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height);
|
|||
} else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts); |
|||
} //else printf("LP_transactioninit: couldnt find (%s) ht.%d %s\n",bits256_str(str,spenttxid),height,jprint(vin,0));
|
|||
if ( bits256_cmp(spenttxid,txid) == 0 ) |
|||
printf("spending same tx's %p vout ht.%d %s.[%d] s%d\n",tx,height,bits256_str(str,txid),tx!=0?tx->numvouts:0,spentvout); |
|||
} |
|||
} |
|||
free_json(txobj); |
|||
return(0); |
|||
} else printf("LP_transactioninit error for %s %s\n",coin->symbol,bits256_str(str,txid)); |
|||
return(-1); |
|||
} |
|||
|
|||
int32_t LP_blockinit(struct iguana_info *coin,int32_t height) |
|||
{ |
|||
int32_t i,iter,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx; |
|||
if ( (blockobj= LP_blockjson(&checkht,coin->symbol,0,height)) != 0 ) |
|||
{ |
|||
if ( (txs= jarray(&numtx,blockobj,"tx")) != 0 ) |
|||
{ |
|||
for (iter=0; iter<2; iter++) |
|||
for (i=0; i<numtx; i++) |
|||
{ |
|||
txid = jbits256i(txs,i); |
|||
if ( (tx= LP_transactionfind(coin,txid)) != 0 ) |
|||
{ |
|||
if ( tx->height == 0 ) |
|||
tx->height = height; |
|||
else if ( tx->height != height ) |
|||
{ |
|||
printf("LP_blockinit: tx->height %d != %d\n",tx->height,height); |
|||
tx->height = height; |
|||
} |
|||
if ( iter == 1 ) |
|||
LP_transactioninit(coin,txid,iter); |
|||
} else LP_transactioninit(coin,txid,iter); |
|||
} |
|||
} |
|||
free_json(blockobj); |
|||
} |
|||
if ( checkht == height ) |
|||
return(0); |
|||
else return(-1); |
|||
} |
|||
|
|||
int32_t LP_scanblockchain(struct iguana_info *coin,int32_t startheight,int32_t endheight) |
|||
{ |
|||
int32_t ht,n = 0; |
|||
for (ht=startheight; ht<=endheight; ht++) |
|||
{ |
|||
if ( LP_blockinit(coin,ht) < 0 ) |
|||
{ |
|||
printf("error loading block.%d of (%d, %d)\n",ht,startheight,endheight); |
|||
return(ht-1); |
|||
} |
|||
n++; |
|||
if ( (n % 1000) == 0 ) |
|||
fprintf(stderr,"%.1f%% ",100. * (double)n/(endheight-startheight+1)); |
|||
} |
|||
return(endheight); |
|||
} |
|||
|
|||
int sort_balance(void *a,void *b) |
|||
{ |
|||
int64_t aval,bval; |
|||
/* compare a to b (cast a and b appropriately)
|
|||
* return (int) -1 if (a < b) |
|||
* return (int) 0 if (a == b) |
|||
* return (int) 1 if (a > b) |
|||
*/ |
|||
aval = ((struct LP_address *)a)->balance; |
|||
bval = ((struct LP_address *)b)->balance; |
|||
//printf("%.8f vs %.8f -> %d\n",dstr(aval),dstr(bval),(int32_t)(bval - aval));
|
|||
return((aval == bval) ? 0 : ((aval < bval) ? 1 : -1)); |
|||
} |
|||
|
|||
cJSON *LP_snapshot(struct iguana_info *coin,int32_t height) |
|||
{ |
|||
static char lastcoin[16]; static int32_t maxsnapht; |
|||
struct LP_transaction *tx,*tmp; struct LP_address *ap,*atmp; int32_t i,n,skipflag=0,startht,endht,ht; uint64_t balance=0,noaddr_balance=0; cJSON *retjson,*array,*item; |
|||
//LP_blockinit(coin,421011);
|
|||
startht = 1; |
|||
endht = height-1; |
|||
if ( strcmp(coin->symbol,lastcoin) == 0 ) |
|||
{ |
|||
if ( maxsnapht > height ) |
|||
skipflag = 1; |
|||
else startht = maxsnapht+1; |
|||
} |
|||
else |
|||
{ |
|||
maxsnapht = 0; |
|||
strcpy(lastcoin,coin->symbol); |
|||
} |
|||
retjson = cJSON_CreateObject(); |
|||
if ( skipflag == 0 && startht < endht ) |
|||
{ |
|||
if ( (ht= LP_scanblockchain(coin,startht,endht)) < endht ) |
|||
{ |
|||
if ( ht > maxsnapht ) |
|||
{ |
|||
maxsnapht = ht; |
|||
printf("maxsnapht.%d for %s\n",maxsnapht,coin->symbol); |
|||
} |
|||
sleep(10); |
|||
if ( (ht= LP_scanblockchain(coin,maxsnapht+1,endht)) < endht ) |
|||
{ |
|||
if ( ht > maxsnapht ) |
|||
{ |
|||
maxsnapht = ht; |
|||
printf("maxsnapht.%d for %s\n",maxsnapht,coin->symbol); |
|||
} |
|||
jaddstr(retjson,"error","blockchain scan error"); |
|||
return(retjson); |
|||
} |
|||
} |
|||
if ( ht > maxsnapht ) |
|||
{ |
|||
maxsnapht = ht; |
|||
printf("maxsnapht.%d for %s\n",maxsnapht,coin->symbol); |
|||
} |
|||
} |
|||
portable_mutex_lock(&coin->txmutex); |
|||
HASH_ITER(hh,coin->addresses,ap,atmp) |
|||
{ |
|||
ap->balance = 0; |
|||
} |
|||
HASH_ITER(hh,coin->transactions,tx,tmp) |
|||
{ |
|||
if ( tx->height < height ) |
|||
{ |
|||
for (i=0; i<tx->numvouts; i++) |
|||
{ |
|||
if ( (ht=tx->outpoints[i].spendheight) > 0 && ht < height ) |
|||
continue; |
|||
if ( tx->outpoints[i].coinaddr[0] != 0 && (ap= _LP_address(coin,tx->outpoints[i].coinaddr)) != 0 ) |
|||
{ |
|||
balance += tx->outpoints[i].value; |
|||
ap->balance += tx->outpoints[i].value; |
|||
//printf("(%s/%s) %.8f %.8f\n",tx->outpoints[i].coinaddr,ap->coinaddr,dstr(tx->outpoints[i].value),dstr(ap->balance));
|
|||
} else noaddr_balance += tx->outpoints[i].value; |
|||
} |
|||
} |
|||
} |
|||
HASH_SORT(coin->addresses,sort_balance); |
|||
portable_mutex_unlock(&coin->txmutex); |
|||
printf("%s balance %.8f at height.%d\n",coin->symbol,dstr(balance),height); |
|||
array = cJSON_CreateArray(); |
|||
n = 0; |
|||
HASH_ITER(hh,coin->addresses,ap,atmp) |
|||
{ |
|||
if ( ap->balance != 0 ) |
|||
{ |
|||
item = cJSON_CreateObject(); |
|||
jaddnum(item,ap->coinaddr,dstr(ap->balance)); |
|||
jaddi(array,item); |
|||
n++; |
|||
} |
|||
} |
|||
jadd(retjson,"balances",array); |
|||
jaddnum(retjson,"numaddresses",n); |
|||
jaddnum(retjson,"total",dstr(balance)); |
|||
jaddnum(retjson,"noaddr_total",dstr(noaddr_balance)); |
|||
return(retjson); |
|||
} |
|||
|
|||
char *LP_dividends(struct iguana_info *coin,int32_t height,cJSON *argjson) |
|||
{ |
|||
cJSON *array,*retjson,*item,*child,*exclude=0; int32_t i,j,emitted=0,dusted=0,n,execflag=0,flag,iter,numexcluded=0; char buf[1024],*field,*prefix="",*suffix=""; uint64_t dustsum=0,excluded=0,total=0,dividend=0,value,val,emit=0,dust=0; double ratio = 1.; |
|||
if ( (retjson= LP_snapshot(coin,height)) != 0 ) |
|||
{ |
|||
//printf("SNAPSHOT.(%s)\n",retstr);
|
|||
if ( (array= jarray(&n,retjson,"balances")) != 0 ) |
|||
{ |
|||
if ( (n= cJSON_GetArraySize(array)) != 0 ) |
|||
{ |
|||
if ( argjson != 0 ) |
|||
{ |
|||
exclude = jarray(&numexcluded,argjson,"exclude"); |
|||
dust = (uint64_t)(jdouble(argjson,"dust") * SATOSHIDEN); |
|||
dividend = (uint64_t)(jdouble(argjson,"dividend") * SATOSHIDEN); |
|||
if ( jstr(argjson,"prefix") != 0 ) |
|||
prefix = jstr(argjson,"prefix"); |
|||
if ( jstr(argjson,"suffix") != 0 ) |
|||
suffix = jstr(argjson,"suffix"); |
|||
execflag = jint(argjson,"system"); |
|||
} |
|||
for (iter=0; iter<2; iter++) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
flag = 0; |
|||
item = jitem(array,i); |
|||
if ( (child= item->child) != 0 ) |
|||
{ |
|||
value = (uint64_t)(child->valuedouble * SATOSHIDEN); |
|||
if ( (field= get_cJSON_fieldname(child)) != 0 ) |
|||
{ |
|||
for (j=0; j<numexcluded; j++) |
|||
if ( strcmp(field,jstri(exclude,j)) == 0 ) |
|||
{ |
|||
flag = 1; |
|||
break; |
|||
} |
|||
} |
|||
//printf("(%s %s %.8f) ",jprint(item,0),field,dstr(value));
|
|||
if ( iter == 0 ) |
|||
{ |
|||
if ( flag != 0 ) |
|||
excluded += value; |
|||
else total += value; |
|||
} |
|||
else |
|||
{ |
|||
if ( flag == 0 ) |
|||
{ |
|||
val = ratio * value; |
|||
if ( val >= dust ) |
|||
{ |
|||
sprintf(buf,"%s %s %.8f %s",prefix,field,dstr(val),suffix); |
|||
if ( execflag != 0 ) |
|||
{ |
|||
if ( system(buf) != 0 ) |
|||
printf("error system.(%s)\n",buf); |
|||
} |
|||
else printf("%s\n",buf); |
|||
emit += val; |
|||
emitted++; |
|||
} else dustsum += val, dusted++; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if ( iter == 0 ) |
|||
{ |
|||
if ( total > 0 ) |
|||
{ |
|||
if ( dividend == 0 ) |
|||
dividend = total; |
|||
ratio = (double)dividend / total; |
|||
} else break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
free_json(retjson); |
|||
retjson = cJSON_CreateObject(); |
|||
jaddstr(retjson,"coin",coin->symbol); |
|||
jaddnum(retjson,"height",height); |
|||
jaddnum(retjson,"total",dstr(total)); |
|||
jaddnum(retjson,"emitted",emitted); |
|||
jaddnum(retjson,"excluded",dstr(excluded)); |
|||
if ( dust != 0 ) |
|||
{ |
|||
jaddnum(retjson,"dust",dstr(dust)); |
|||
jaddnum(retjson,"dusted",dusted); |
|||
} |
|||
if ( dustsum != 0 ) |
|||
jaddnum(retjson,"dustsum",dstr(dustsum)); |
|||
jaddnum(retjson,"dividend",dstr(dividend)); |
|||
jaddnum(retjson,"dividends",dstr(emit)); |
|||
jaddnum(retjson,"ratio",ratio); |
|||
if ( execflag != 0 ) |
|||
jaddnum(retjson,"system",execflag); |
|||
/*if ( prefix[0] != 0 )
|
|||
jaddstr(retjson,"prefix",prefix); |
|||
if ( suffix[0] != 0 ) |
|||
jaddstr(retjson,"suffix",suffix);*/ |
|||
return(jprint(retjson,1)); |
|||
} |
|||
return(clonestr("{\"error\":\"symbol not found\"}")); |
|||
} |
|||
|
|||
int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) |
|||
{ |
|||
char destaddr[64]; uint64_t value,interest = 0; struct iguana_info *coin; |
|||
if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) |
|||
return(0); |
|||
//char str[65]; printf("%s txvalue.(%s)\n",symbol,bits256_str(str,txid));
|
|||
value = LP_txinterestvalue(&interest,destaddr,coin,txid,vout); |
|||
return(value + interest); |
|||
} |
|||
|
|||
uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) |
|||
{ |
|||
struct LP_transaction *tx; char _coinaddr[64]; uint64_t interest = 0,value = 0; struct iguana_info *coin; |
|||
if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) |
|||
return(0); |
|||
if ( coinaddr != 0 ) |
|||
coinaddr[0] = 0; |
|||
if ( (tx= LP_transactionfind(coin,txid)) != 0 ) |
|||
{ |
|||
if ( vout < tx->numvouts ) |
|||
{ |
|||
if ( bits256_nonz(tx->outpoints[vout].spendtxid) != 0 ) |
|||
{ |
|||
//char str[65]; printf("%s/v%d is spent\n",bits256_str(str,txid),vout);
|
|||
return(0); |
|||
} |
|||
else |
|||
{ |
|||
if ( coinaddr != 0 ) |
|||
value = LP_txinterestvalue(&tx->outpoints[vout].interest,coinaddr,coin,txid,vout); |
|||
//printf("return value %.8f + interest %.8f\n",dstr(tx->outpoints[vout].value),dstr(tx->outpoints[vout].interest));
|
|||
return(tx->outpoints[vout].value + tx->outpoints[vout].interest); |
|||
} |
|||
} else printf("vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts); |
|||
} |
|||
if ( tx == 0 ) |
|||
{ |
|||
LP_transactioninit(coin,txid,0); |
|||
LP_transactioninit(coin,txid,1); |
|||
} |
|||
if ( coinaddr == 0 ) |
|||
coinaddr = _coinaddr; |
|||
value = LP_txinterestvalue(&interest,coinaddr,coin,txid,vout); |
|||
//printf("coinaddr.(%s) value %.8f interest %.8f\n",coinaddr,dstr(value),dstr(interest));
|
|||
return(value + interest); |
|||
} |
|||
|
|||
int32_t LP_spendsearch(bits256 *spendtxidp,int32_t *indp,char *symbol,bits256 searchtxid,int32_t searchvout) |
|||
{ |
|||
struct LP_transaction *tx; struct iguana_info *coin; |
|||
*indp = -1; |
|||
if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) |
|||
return(-1); |
|||
memset(spendtxidp,0,sizeof(*spendtxidp)); |
|||
if ( (tx= LP_transactionfind(coin,searchtxid)) != 0 ) |
|||
{ |
|||
if ( searchvout < tx->numvouts && tx->outpoints[searchvout].spendvini >= 0 ) |
|||
{ |
|||
*spendtxidp = tx->outpoints[searchvout].spendtxid; |
|||
*indp = tx->outpoints[searchvout].spendvini; |
|||
return(tx->outpoints[searchvout].spendheight); |
|||
} |
|||
} |
|||
return(-1); |
|||
} |
|||
|
|||
int32_t LP_mempoolscan(char *symbol,bits256 searchtxid) |
|||
{ |
|||
int32_t i,n; cJSON *array; bits256 txid; struct iguana_info *coin; struct LP_transaction *tx; |
|||
if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) |
|||
return(-1); |
|||
if ( (array= LP_getmempool(symbol)) != 0 ) |
|||
{ |
|||
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
txid = jbits256i(array,i); |
|||
if ( (tx= LP_transactionfind(coin,txid)) == 0 ) |
|||
{ |
|||
LP_transactioninit(coin,txid,0); |
|||
LP_transactioninit(coin,txid,1); |
|||
} |
|||
if ( bits256_cmp(txid,searchtxid) == 0 ) |
|||
{ |
|||
char str[65]; printf("found %s tx.(%s) in mempool slot.%d\n",symbol,bits256_str(str,txid),i); |
|||
return(i); |
|||
} |
|||
} |
|||
} |
|||
free_json(array); |
|||
} |
|||
return(-1); |
|||
} |
|||
|
|||
int32_t LP_numconfirms(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,int32_t mempool) |
|||
{ |
|||
struct iguana_info *coin; int32_t numconfirms = 100; |
|||
//#ifndef BASILISK_DISABLEWAITTX
|
|||
cJSON *txobj; |
|||
if ( (coin= LP_coinfind(rawtx->coin->symbol)) == 0 || coin->inactive != 0 ) |
|||
return(-1); |
|||
numconfirms = -1; |
|||
if ( (txobj= LP_gettx(rawtx->coin->symbol,rawtx->I.signedtxid)) != 0 ) |
|||
{ |
|||
numconfirms = jint(txobj,"confirmations"); |
|||
free_json(txobj); |
|||
} |
|||
else if ( mempool != 0 && LP_mempoolscan(rawtx->coin->symbol,rawtx->I.signedtxid) >= 0 ) |
|||
numconfirms = 0; |
|||
//#endif
|
|||
return(numconfirms); |
|||
} |
|||
|
|||
int32_t LP_waitmempool(char *symbol,bits256 txid,int32_t duration) |
|||
{ |
|||
uint32_t expiration = (uint32_t)time(NULL) + duration; |
|||
while ( time(NULL) < expiration ) |
|||
{ |
|||
if ( LP_mempoolscan(symbol,txid) >= 0 ) |
|||
return(0); |
|||
usleep(500000); |
|||
} |
|||
return(-1); |
|||
} |
|||
|
|||
int32_t LP_mempool_vinscan(bits256 *spendtxidp,int32_t *spendvinp,char *symbol,bits256 searchtxid,int32_t searchvout,bits256 searchtxid2,int32_t searchvout2) |
|||
{ |
|||
struct iguana_info *coin; int32_t selector; cJSON *array; |
|||
if ( symbol == 0 || symbol[0] == 0 || bits256_nonz(searchtxid) == 0 || bits256_nonz(searchtxid2) == 0 ) |
|||
return(-1); |
|||
if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) |
|||
return(-1); |
|||
if ( time(NULL) > coin->lastmempool+LP_MEMPOOL_TIMEINCR ) |
|||
{ |
|||
if ( (array= LP_getmempool(symbol)) != 0 ) |
|||
{ |
|||
free_json(array); |
|||
coin->lastmempool = (uint32_t)time(NULL); |
|||
} |
|||
} |
|||
if ( (selector= LP_spendsearch(spendtxidp,spendvinp,symbol,searchtxid,searchvout)) >= 0 ) |
|||
return(selector); |
|||
else if ( (selector= LP_spendsearch(spendtxidp,spendvinp,symbol,searchtxid2,searchvout2)) >= 0 ) |
|||
return(selector); |
|||
return(-1); |
|||
} |
|||
|
|||
|
@ -0,0 +1,186 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_secp.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
|
|||
#include <ctype.h> |
|||
#include <string.h> |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include "../../includes/curve25519.h" |
|||
#include "../secp256k1/include/secp256k1.h" |
|||
#include "../secp256k1/include/secp256k1_ecdh.h" |
|||
#include "../secp256k1/include/secp256k1_schnorr.h" |
|||
#include "../secp256k1/include/secp256k1_rangeproof.h" |
|||
#include "../secp256k1/include/secp256k1_recovery.h" |
|||
|
|||
SECP256K1_API extern const secp256k1_nonce_function secp256k1_nonce_function_rfc6979; |
|||
|
|||
#define bits256_nonz(a) (((a).ulongs[0] | (a).ulongs[1] | (a).ulongs[2] | (a).ulongs[3]) != 0) |
|||
|
|||
#define SECP_ENSURE_CTX int32_t flag = 0; if ( ctx == 0 ) { ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); secp256k1_pedersen_context_initialize(ctx); secp256k1_rangeproof_context_initialize(ctx); flag++; } else flag = 0; if ( ctx != 0 ) |
|||
#define ENDSECP_ENSURE_CTX if ( flag != 0 ) secp256k1_context_destroy(ctx); |
|||
|
|||
void *bitcoin_ctx() |
|||
{ |
|||
void *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); |
|||
secp256k1_pedersen_context_initialize(ctx); |
|||
secp256k1_rangeproof_context_initialize(ctx); |
|||
return(ctx); |
|||
} |
|||
|
|||
bits256 bitcoin_pubkey33(void *ctx,uint8_t *data,bits256 privkey) |
|||
{ |
|||
size_t plen; bits256 pubkey; secp256k1_pubkey secppub; |
|||
memset(pubkey.bytes,0,sizeof(pubkey)); |
|||
SECP_ENSURE_CTX |
|||
{ |
|||
if ( secp256k1_ec_seckey_verify(ctx,privkey.bytes) == 0 ) |
|||
{ |
|||
//printf("bitcoin_sign illegal privkey\n");
|
|||
return(pubkey); |
|||
} |
|||
if ( secp256k1_ec_pubkey_create(ctx,&secppub,privkey.bytes) != 0 ) |
|||
{ |
|||
plen = 33; |
|||
secp256k1_ec_pubkey_serialize(ctx,data,&plen,&secppub,SECP256K1_EC_COMPRESSED); |
|||
if ( plen == 33 ) |
|||
memcpy(pubkey.bytes,data+1,sizeof(pubkey)); |
|||
} |
|||
ENDSECP_ENSURE_CTX |
|||
} |
|||
return(pubkey); |
|||
} |
|||
|
|||
bits256 bitcoin_pub256(void *ctx,bits256 *privkeyp,uint8_t odd_even) |
|||
{ |
|||
bits256 pub256; uint8_t pubkey[33]; int32_t i; |
|||
for (i=0; i<100; i++) |
|||
{ |
|||
*privkeyp = rand256(0); |
|||
pub256 = bitcoin_pubkey33(ctx,pubkey,*privkeyp); |
|||
if ( pubkey[0] == odd_even+2 ) |
|||
return(pub256); |
|||
} |
|||
printf("bitcoin_pub256 couldnt generate pubkey.%d\n",odd_even+2); |
|||
memset(pub256.bytes,0,sizeof(pub256)); |
|||
return(pub256); |
|||
} |
|||
|
|||
int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256 privkey,int32_t recoverflag) |
|||
{ |
|||
int32_t fCompressed = 1; |
|||
secp256k1_ecdsa_signature SIG; secp256k1_ecdsa_recoverable_signature rSIG; bits256 extra_entropy,seed; int32_t recid,retval = -1; size_t siglen = 72; secp256k1_pubkey SECPUB,CHECKPUB; |
|||
seed = rand256(0); |
|||
extra_entropy = rand256(0); |
|||
SECP_ENSURE_CTX |
|||
{ |
|||
if ( secp256k1_ec_seckey_verify(ctx,privkey.bytes) == 0 ) |
|||
{ |
|||
//printf("bitcoin_sign illegal privkey\n");
|
|||
return(-1); |
|||
} |
|||
if ( secp256k1_context_randomize(ctx,seed.bytes) != 0 ) |
|||
{ |
|||
if ( recoverflag != 0 ) |
|||
{ |
|||
if ( secp256k1_ecdsa_sign_recoverable(ctx,&rSIG,txhash2.bytes,privkey.bytes,secp256k1_nonce_function_rfc6979,extra_entropy.bytes) != 0 ) |
|||
{ |
|||
recid = -1; |
|||
secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx,sig+1,&recid,&rSIG); |
|||
if ( secp256k1_ecdsa_recover(ctx,&SECPUB,&rSIG,txhash2.bytes) != 0 ) |
|||
{ |
|||
if ( secp256k1_ec_pubkey_create(ctx,&CHECKPUB,privkey.bytes) != 0 ) |
|||
{ |
|||
if ( memcmp(&SECPUB,&CHECKPUB,sizeof(SECPUB)) == 0 ) |
|||
{ |
|||
sig[0] = 27 + recid + (fCompressed != 0 ? 4 : 0); |
|||
retval = 64 + 1; |
|||
//size_t i,plen = 33; uint8_t pubkey[33];
|
|||
//secp256k1_ec_pubkey_serialize(ctx,pubkey,&plen,&CHECKPUB,SECP256K1_EC_COMPRESSED);
|
|||
//for (i=0; i<33; i++)
|
|||
// printf("%02x",pubkey[i]);
|
|||
//printf(" bitcoin_sign's pubkey\n");
|
|||
|
|||
} //else printf("secpub mismatch\n");
|
|||
} else printf("pubkey create error\n"); |
|||
} //else printf("recover error\n");
|
|||
} else printf("secp256k1_ecdsa_sign_recoverable error\n"); |
|||
} |
|||
else |
|||
{ |
|||
if ( secp256k1_ecdsa_sign(ctx,&SIG,txhash2.bytes,privkey.bytes,secp256k1_nonce_function_rfc6979,extra_entropy.bytes) != 0 ) |
|||
{ |
|||
if ( secp256k1_ecdsa_signature_serialize_der(ctx,sig,&siglen,&SIG) != 0 ) |
|||
retval = (int32_t)siglen; |
|||
} |
|||
} |
|||
} |
|||
ENDSECP_ENSURE_CTX |
|||
} |
|||
return(retval); |
|||
} |
|||
|
|||
int32_t bitcoin_recoververify(void *ctx,char *symbol,uint8_t *sig,bits256 messagehash2,uint8_t *pubkey,size_t plen) |
|||
{ |
|||
int32_t retval = -1; secp256k1_pubkey PUB; secp256k1_ecdsa_signature SIG; secp256k1_ecdsa_recoverable_signature rSIG; |
|||
pubkey[0] = 0; |
|||
SECP_ENSURE_CTX |
|||
{ |
|||
if ( plen == 0 ) |
|||
{ |
|||
plen = (sig[0] <= 31) ? 65 : 33; |
|||
sig++; |
|||
} |
|||
secp256k1_ecdsa_recoverable_signature_parse_compact(ctx,&rSIG,sig,0); |
|||
secp256k1_ecdsa_recoverable_signature_convert(ctx,&SIG,&rSIG); |
|||
if ( secp256k1_ecdsa_recover(ctx,&PUB,&rSIG,messagehash2.bytes) != 0 ) |
|||
{ |
|||
plen = 33; |
|||
memset(pubkey,0,33); |
|||
secp256k1_ec_pubkey_serialize(ctx,pubkey,&plen,&PUB,SECP256K1_EC_COMPRESSED);//plen == 65 ? SECP256K1_EC_UNCOMPRESSED : SECP256K1_EC_COMPRESSED);
|
|||
if ( secp256k1_ecdsa_verify(ctx,&SIG,messagehash2.bytes,&PUB) != 0 ) |
|||
{ |
|||
retval = 0; |
|||
/*if ( pubkey[0] == 4 ) // experimentally looks like 04 is set
|
|||
pubkey[0] = 2; |
|||
else if ( pubkey[0] != 2 ) |
|||
pubkey[0] = 3;*/ |
|||
} else printf("secp256k1_ecdsa_verify error\n"); |
|||
} else printf("secp256k1_ecdsa_recover error\n"); |
|||
ENDSECP_ENSURE_CTX |
|||
} |
|||
return(retval); |
|||
} |
|||
|
|||
int32_t bitcoin_verify(void *ctx,uint8_t *sig,int32_t siglen,bits256 txhash2,uint8_t *pubkey,int32_t plen) |
|||
{ |
|||
int32_t retval = -1; secp256k1_pubkey PUB; secp256k1_ecdsa_signature SIG; |
|||
SECP_ENSURE_CTX |
|||
{ |
|||
if ( secp256k1_ec_pubkey_parse(ctx,&PUB,pubkey,plen) != 0 ) |
|||
{ |
|||
secp256k1_ecdsa_signature_parse_der(ctx,&SIG,sig,siglen); |
|||
if ( secp256k1_ecdsa_verify(ctx,&SIG,txhash2.bytes,&PUB) != 0 ) |
|||
retval = 0; |
|||
} |
|||
ENDSECP_ENSURE_CTX |
|||
} |
|||
return(retval); |
|||
} |
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,980 @@ |
|||
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2017 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. * |
|||
* * |
|||
******************************************************************************/ |
|||
//
|
|||
// LP_utxos.c
|
|||
// marketmaker
|
|||
//
|
|||
|
|||
int32_t LP_ismine(struct LP_utxoinfo *utxo) |
|||
{ |
|||
if ( utxo != 0 && bits256_cmp(utxo->pubkey,LP_mypub25519) == 0 ) |
|||
return(1); |
|||
else return(0); |
|||
} |
|||
|
|||
int32_t LP_isavailable(struct LP_utxoinfo *utxo) |
|||
{ |
|||
if ( time(NULL) > utxo->T.swappending ) |
|||
utxo->T.swappending = 0; |
|||
if ( utxo != 0 && utxo->T.swappending == 0 && utxo->S.swap == 0 ) |
|||
return(1); |
|||
else return(0); |
|||
} |
|||
|
|||
int32_t LP_isunspent(struct LP_utxoinfo *utxo) |
|||
{ |
|||
if ( utxo != 0 && utxo->T.spentflag == 0 && LP_isavailable(utxo) > 0 ) |
|||
return(1); |
|||
else return(0); |
|||
} |
|||
|
|||
void LP_utxosetkey(uint8_t *key,bits256 txid,int32_t vout) |
|||
{ |
|||
memcpy(key,txid.bytes,sizeof(txid)); |
|||
memcpy(&key[sizeof(txid)],&vout,sizeof(vout)); |
|||
} |
|||
|
|||
struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) |
|||
{ |
|||
struct LP_utxoinfo *utxo=0; uint8_t key[sizeof(txid) + sizeof(vout)]; |
|||
LP_utxosetkey(key,txid,vout); |
|||
HASH_FIND(hh,LP_utxoinfos[iambob],key,sizeof(key),utxo); |
|||
return(utxo); |
|||
} |
|||
|
|||
struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) |
|||
{ |
|||
struct LP_utxoinfo *utxo=0; uint8_t key2[sizeof(txid2) + sizeof(vout2)]; |
|||
LP_utxosetkey(key2,txid2,vout2); |
|||
HASH_FIND(hh2,LP_utxoinfos2[iambob],key2,sizeof(key2),utxo); |
|||
return(utxo); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) |
|||
{ |
|||
struct LP_utxoinfo *utxo=0; |
|||
portable_mutex_lock(&LP_utxomutex); |
|||
utxo = _LP_utxofind(iambob,txid,vout); |
|||
portable_mutex_unlock(&LP_utxomutex); |
|||
return(utxo); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxopairfind(int32_t iambob,bits256 txid,int32_t vout,bits256 txid2,int32_t vout2) |
|||
{ |
|||
struct LP_utxoinfo *utxo=0; struct _LP_utxoinfo u; |
|||
if ( (utxo= LP_utxofind(iambob,txid,vout)) != 0 ) |
|||
{ |
|||
u = (iambob != 0) ? utxo->deposit : utxo->fee; |
|||
if (vout2 == u.vout && bits256_cmp(u.txid,txid2) == 0 ) |
|||
return(utxo); |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) |
|||
{ |
|||
struct LP_utxoinfo *utxo=0; |
|||
portable_mutex_lock(&LP_utxomutex); |
|||
utxo = _LP_utxo2find(iambob,txid2,vout2); |
|||
portable_mutex_unlock(&LP_utxomutex); |
|||
return(utxo); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxofinds(int32_t iambob,bits256 txid,int32_t vout,bits256 txid2,int32_t vout2) |
|||
{ |
|||
struct LP_utxoinfo *utxo; |
|||
if ( (utxo= LP_utxofind(iambob,txid,vout)) != 0 || (utxo= LP_utxofind(iambob,txid2,vout2)) != 0 || (utxo= LP_utxo2find(iambob,txid,vout)) != 0 || (utxo= LP_utxo2find(iambob,txid2,vout2)) != 0 ) |
|||
return(utxo); |
|||
else return(0); |
|||
} |
|||
|
|||
int32_t LP_utxoaddptrs(struct LP_utxoinfo *ptrs[],int32_t n,struct LP_utxoinfo *utxo) |
|||
{ |
|||
int32_t i; |
|||
for (i=0; i<n; i++) |
|||
if ( ptrs[i] == utxo ) |
|||
return(n); |
|||
ptrs[n++] = utxo; |
|||
return(n); |
|||
} |
|||
|
|||
int32_t LP_utxocollisions(struct LP_utxoinfo *ptrs[],struct LP_utxoinfo *refutxo) |
|||
{ |
|||
int32_t iambob,n = 0; struct LP_utxoinfo *utxo; struct _LP_utxoinfo u; |
|||
if ( refutxo == 0 ) |
|||
return(0); |
|||
portable_mutex_lock(&LP_utxomutex); |
|||
for (iambob=0; iambob<=1; iambob++) |
|||
{ |
|||
if ( (utxo= _LP_utxofind(iambob,refutxo->payment.txid,refutxo->payment.vout)) != 0 && utxo != refutxo ) |
|||
n = LP_utxoaddptrs(ptrs,n,utxo); |
|||
if ( (utxo= _LP_utxo2find(iambob,refutxo->payment.txid,refutxo->payment.vout)) != 0 && utxo != refutxo ) |
|||
n = LP_utxoaddptrs(ptrs,n,utxo); |
|||
u = (refutxo->iambob != 0) ? refutxo->deposit : refutxo->fee; |
|||
if ( (utxo= _LP_utxofind(iambob,u.txid,u.vout)) != 0 && utxo != refutxo ) |
|||
n = LP_utxoaddptrs(ptrs,n,utxo); |
|||
if ( (utxo= _LP_utxo2find(iambob,u.txid,u.vout)) != 0 && utxo != refutxo ) |
|||
n = LP_utxoaddptrs(ptrs,n,utxo); |
|||
} |
|||
portable_mutex_unlock(&LP_utxomutex); |
|||
if ( 0 && n > 0 ) |
|||
printf("LP_utxocollisions n.%d\n",n); |
|||
return(n); |
|||
} |
|||
|
|||
int32_t _LP_availableset(struct LP_utxoinfo *utxo) |
|||
{ |
|||
int32_t flag = 0; |
|||
if ( utxo != 0 ) |
|||
{ |
|||
if ( bits256_nonz(utxo->S.otherpubkey) != 0 ) |
|||
flag = 1, memset(&utxo->S.otherpubkey,0,sizeof(utxo->S.otherpubkey)); |
|||
if ( utxo->S.swap != 0 ) |
|||
flag = 1, utxo->S.swap = 0; |
|||
if ( utxo->T.swappending != 0 ) |
|||
flag = 1, utxo->T.swappending = 0; |
|||
return(flag); |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
void _LP_unavailableset(struct LP_utxoinfo *utxo,bits256 otherpubkey) |
|||
{ |
|||
if ( utxo != 0 ) |
|||
{ |
|||
utxo->T.swappending = (uint32_t)(time(NULL) + LP_RESERVETIME); |
|||
utxo->S.otherpubkey = otherpubkey; |
|||
} |
|||
} |
|||
|
|||
void LP_unavailableset(struct LP_utxoinfo *utxo,bits256 otherpubkey) |
|||
{ |
|||
struct LP_utxoinfo *ptrs[8]; int32_t i,n; struct _LP_utxoinfo u; |
|||
memset(ptrs,0,sizeof(ptrs)); |
|||
if ( (n= LP_utxocollisions(ptrs,utxo)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
_LP_unavailableset(ptrs[i],otherpubkey); |
|||
} |
|||
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; |
|||
char str[65],str2[65]; printf("UTXO.[%d] RESERVED %s/v%d %s/v%d collisions.%d\n",utxo->iambob,bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,u.txid),u.vout,n); |
|||
_LP_unavailableset(utxo,otherpubkey); |
|||
} |
|||
|
|||
void LP_availableset(struct LP_utxoinfo *utxo) |
|||
{ |
|||
struct LP_utxoinfo *ptrs[8]; int32_t i,n,count = 0; struct _LP_utxoinfo u; |
|||
if ( utxo != 0 ) |
|||
{ |
|||
memset(ptrs,0,sizeof(ptrs)); |
|||
if ( (n= LP_utxocollisions(ptrs,utxo)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
count += _LP_availableset(ptrs[i]); |
|||
} |
|||
count += _LP_availableset(utxo); |
|||
if ( count > 0 ) |
|||
{ |
|||
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; |
|||
char str[65],str2[65]; printf("UTXO.[%d] AVAIL %s/v%d %s/v%d collisions.%d\n",utxo->iambob,bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,u.txid),u.vout,n); |
|||
} |
|||
} |
|||
} |
|||
|
|||
int32_t LP_utxopurge(int32_t allutxos) |
|||
{ |
|||
char str[65]; struct LP_utxoinfo *utxo,*tmp; int32_t iambob,n = 0; |
|||
printf("LP_utxopurge mypub.(%s)\n",bits256_str(str,LP_mypub25519)); |
|||
portable_mutex_lock(&LP_utxomutex); |
|||
for (iambob=0; iambob<=1; iambob++) |
|||
{ |
|||
HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) |
|||
{ |
|||
if ( LP_isavailable(utxo) > 0 ) |
|||
{ |
|||
if ( allutxos != 0 || LP_ismine(utxo) > 0 ) |
|||
{ |
|||
printf("iambob.%d delete.(%s)\n",iambob,bits256_str(str,utxo->payment.txid)); |
|||
HASH_DELETE(hh,LP_utxoinfos[iambob],utxo); |
|||
//free(utxo); let the LP_utxoinfos2 free the utxo, should be 1:1
|
|||
} else n++; |
|||
} else n++; |
|||
} |
|||
HASH_ITER(hh,LP_utxoinfos2[iambob],utxo,tmp) |
|||
{ |
|||
if ( LP_isavailable(utxo) > 0 ) |
|||
{ |
|||
if ( allutxos != 0 || LP_ismine(utxo) > 0 ) |
|||
{ |
|||
printf("iambob.%d delete2.(%s)\n",iambob,bits256_str(str,utxo->payment.txid)); |
|||
HASH_DELETE(hh2,LP_utxoinfos2[iambob],utxo); |
|||
free(utxo); |
|||
} else n++; |
|||
} else n++; |
|||
} |
|||
} |
|||
portable_mutex_unlock(&LP_utxomutex); |
|||
return(n); |
|||
} |
|||
|
|||
cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo) |
|||
{ |
|||
struct _LP_utxoinfo u; |
|||
jaddstr(item,"method","utxo"); |
|||
if ( utxo == 0 ) |
|||
return(item); |
|||
if ( utxo->gui[0] != 0 ) |
|||
jaddstr(item,"gui",utxo->gui); |
|||
jaddstr(item,"coin",utxo->coin); |
|||
//jaddnum(item,"now",time(NULL));
|
|||
jaddnum(item,"iambob",utxo->iambob); |
|||
jaddstr(item,"address",utxo->coinaddr); |
|||
jaddbits256(item,"txid",utxo->payment.txid); |
|||
jaddnum(item,"vout",utxo->payment.vout); |
|||
jadd64bits(item,"value",utxo->payment.value); |
|||
jadd64bits(item,"satoshis",utxo->S.satoshis); |
|||
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; |
|||
if ( bits256_nonz(u.txid) != 0 ) |
|||
{ |
|||
jaddbits256(item,"txid2",u.txid); |
|||
jaddnum(item,"vout2",u.vout); |
|||
jadd64bits(item,"value2",u.value); |
|||
} |
|||
if ( utxo->T.swappending != 0 ) |
|||
jaddnum(item,"pending",utxo->T.swappending); |
|||
if ( utxo->iambob != 0 ) |
|||
{ |
|||
jaddbits256(item,"srchash",utxo->pubkey);//LP_mypub25519);
|
|||
if ( bits256_nonz(utxo->S.otherpubkey) != 0 ) |
|||
jaddbits256(item,"desthash",utxo->S.otherpubkey); |
|||
} |
|||
else |
|||
{ |
|||
jaddbits256(item,"desthash",utxo->pubkey);//LP_mypub25519);
|
|||
if ( bits256_nonz(utxo->S.otherpubkey) != 0 ) |
|||
jaddbits256(item,"srchash",utxo->S.otherpubkey); |
|||
} |
|||
if ( utxo->S.swap != 0 ) |
|||
jaddstr(item,"swap","in progress"); |
|||
if ( utxo->T.spentflag != 0 ) |
|||
jaddnum(item,"spent",utxo->T.spentflag); |
|||
jaddnum(item,"session",utxo->T.sessionid); |
|||
return(item); |
|||
} |
|||
|
|||
cJSON *LP_utxojson(struct LP_utxoinfo *utxo) |
|||
{ |
|||
cJSON *item = cJSON_CreateObject(); |
|||
item = LP_inventoryjson(item,utxo); |
|||
jaddbits256(item,"pubkey",utxo->pubkey); |
|||
//jaddnum(item,"profit",utxo->S.profitmargin);
|
|||
jaddstr(item,"base",utxo->coin); |
|||
jaddstr(item,"script",utxo->spendscript); |
|||
return(item); |
|||
} |
|||
|
|||
int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2) |
|||
{ |
|||
//struct LP_utxoinfo *utxo;
|
|||
uint64_t val,val2=0,txfee,threshold=0; int32_t bypass = 0; char destaddr[64],destaddr2[64]; struct iguana_info *coin = LP_coinfind(symbol); |
|||
destaddr[0] = destaddr2[0] = 0; |
|||
if ( coin != 0 && IAMLP != 0 && coin->inactive != 0 ) |
|||
bypass = 1; |
|||
if ( bypass != 0 ) |
|||
val = satoshis; |
|||
else val = LP_txvalue(destaddr,symbol,txid,vout); |
|||
txfee = LP_txfeecalc(symbol,0); |
|||
if ( val >= satoshis && val > (1+LP_MINSIZE_TXFEEMULT)*txfee ) |
|||
{ |
|||
threshold = (iambob != 0) ? LP_DEPOSITSATOSHIS(satoshis) : (LP_DEXFEE(satoshis) + txfee); |
|||
if ( bypass != 0 ) |
|||
val2 = threshold; |
|||
else val2 = LP_txvalue(destaddr2,symbol,txid2,vout2); |
|||
if ( val2 >= threshold ) |
|||
{ |
|||
if ( bypass == 0 && strcmp(destaddr,destaddr2) != 0 ) |
|||
printf("mismatched %s destaddr (%s) vs (%s)\n",symbol,destaddr,destaddr2); |
|||
else if ( bypass == 0 && ((iambob == 0 && val2 > val) || (iambob != 0 && val2 <= satoshis)) ) |
|||
printf("iambob.%d ineligible due to offsides: val %.8f and val2 %.8f vs %.8f diff %lld\n",iambob,dstr(val),dstr(val2),dstr(satoshis),(long long)(val2 - val)); |
|||
else |
|||
{ |
|||
*valp = val; |
|||
*val2p = val2; |
|||
return(1); |
|||
} |
|||
} // else printf("no val2\n");
|
|||
} |
|||
// char str[65],str2[65]; printf("spent.%d %s txid or value %.8f < %.8f or val2 %.8f < %.8f, %s/v%d %s/v%d or < 10x txfee %.8f\n",iambob,symbol,dstr(val),dstr(satoshis),dstr(val2),dstr(threshold),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2,dstr(txfee));
|
|||
/*for (iter=0; iter<2; iter++)
|
|||
{ |
|||
if ( (utxo= LP_utxofind(iter,txid,vout)) != 0 ) |
|||
{ |
|||
//printf("iambob.%d case 00\n",iter);
|
|||
if ( utxo->T.spentflag == 0 ) |
|||
utxo->T.spentflag = (uint32_t)time(NULL); |
|||
} |
|||
if ( (utxo= LP_utxo2find(iter,txid,vout)) != 0 ) |
|||
{ |
|||
//printf("iambob.%d case 01\n",iter);
|
|||
if ( utxo->T.spentflag == 0 ) |
|||
utxo->T.spentflag = (uint32_t)time(NULL); |
|||
} |
|||
if ( (utxo= LP_utxofind(iter,txid2,vout2)) != 0 ) |
|||
{ |
|||
//printf("iambob.%d case 10\n",iter);
|
|||
if ( utxo->T.spentflag == 0 ) |
|||
utxo->T.spentflag = (uint32_t)time(NULL); |
|||
} |
|||
if ( (utxo= LP_utxo2find(iter,txid2,vout2)) != 0 ) |
|||
{ |
|||
//printf("iambob.%d case 11\n",iter);
|
|||
if ( utxo->T.spentflag == 0 ) |
|||
utxo->T.spentflag = (uint32_t)time(NULL); |
|||
} |
|||
}*/ |
|||
*valp = val; |
|||
*val2p = val2; |
|||
return(0); |
|||
} |
|||
|
|||
char *LP_utxos(int32_t iambob,struct LP_peerinfo *mypeer,char *symbol,int32_t lastn) |
|||
{ |
|||
int32_t i,n,m; uint64_t val,val2; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo,*tmp; cJSON *utxosjson = cJSON_CreateArray(); |
|||
//n = mypeer != 0 ? mypeer->numutxos : 0;
|
|||
if ( lastn <= 0 ) |
|||
lastn = LP_PROPAGATION_SLACK * 2; |
|||
HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) |
|||
{ |
|||
//char str[65]; printf("check %s.%s\n",utxo->coin,bits256_str(str,utxo->payment.txid));
|
|||
if ( (symbol == 0 || symbol[0] == 0 || strcmp(symbol,utxo->coin) == 0) && utxo->T.spentflag == 0 ) |
|||
{ |
|||
u = (iambob != 0) ? utxo->deposit : utxo->fee; |
|||
if ( LP_iseligible(&val,&val2,utxo->iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,u.txid,u.vout) == 0 ) |
|||
{ |
|||
char str[65]; printf("iambob.%d not eligible (%.8f %.8f) %s %s/v%d\n",iambob,dstr(val),dstr(val2),utxo->coin,bits256_str(str,utxo->payment.txid),utxo->payment.vout); |
|||
continue; |
|||
} else jaddi(utxosjson,LP_utxojson(utxo)); |
|||
} |
|||
} |
|||
if ( (n= cJSON_GetArraySize(utxosjson)) > lastn ) |
|||
{ |
|||
m = n - lastn; |
|||
for (i=0; i<m; i++) |
|||
cJSON_DeleteItemFromArray(utxosjson,0); |
|||
} |
|||
return(jprint(utxosjson,1)); |
|||
} |
|||
|
|||
int32_t LP_inventory_prevent(int32_t iambob,bits256 txid,int32_t vout) |
|||
{ |
|||
struct LP_utxoinfo *utxo; |
|||
if ( (utxo= LP_utxofind(iambob,txid,vout)) != 0 || (utxo= LP_utxo2find(iambob,txid,vout)) != 0 ) |
|||
{ |
|||
//if ( utxo->T.spentflag != 0 )
|
|||
{ |
|||
//char str[65]; printf("prevent adding %s/v%d to inventory\n",bits256_str(str,txid),vout);
|
|||
return(1); |
|||
} |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) |
|||
{ |
|||
uint64_t srcvalue,srcvalue2; struct LP_utxoinfo *utxo,*tmp,*bestutxo = 0; |
|||
if ( symbol == 0 || destsatoshis == 0 ) |
|||
{ |
|||
printf("LP_utxo_bestfit error symbol.%p %.8f\n",symbol,dstr(destsatoshis)); |
|||
return(0); |
|||
} |
|||
HASH_ITER(hh,LP_utxoinfos[0],utxo,tmp) |
|||
{ |
|||
//char str[65]; printf("s%u %d [%.8f vs %.8f] check %s.%s avail.%d ismine.%d >= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis);
|
|||
if ( strcmp(symbol,utxo->coin) != 0 ) |
|||
continue; |
|||
if ( LP_isavailable(utxo) > 0 && LP_ismine(utxo) > 0 ) |
|||
{ |
|||
if ( utxo->S.satoshis >= destsatoshis/2 && (bestutxo == 0 || (bestutxo->S.satoshis < destsatoshis && utxo->S.satoshis >= destsatoshis) || (bestutxo->S.satoshis >= destsatoshis && utxo->S.satoshis < bestutxo->S.satoshis)) ) |
|||
{ |
|||
if ( LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout) == 0 ) |
|||
{ |
|||
//if ( utxo->T.spentflag == 0 )
|
|||
// utxo->T.spentflag = (uint32_t)time(NULL);
|
|||
continue; |
|||
} |
|||
bestutxo = utxo; |
|||
} //else printf("skip alice utxo %.8f vs dest %.8f\n",dstr(utxo->S.satoshis),dstr(destsatoshis));
|
|||
} |
|||
} |
|||
return(bestutxo); |
|||
} |
|||
|
|||
void LP_spentnotify(struct LP_utxoinfo *utxo,int32_t selector) |
|||
{ |
|||
//cJSON *argjson; struct _LP_utxoinfo u; char *msg;
|
|||
if ( utxo == 0 ) |
|||
return; |
|||
utxo->T.spentflag = (uint32_t)time(NULL); |
|||
if ( LP_mypeer != 0 && LP_mypeer->numutxos > 0 ) |
|||
LP_mypeer->numutxos--; |
|||
/*if ( LP_mypubsock >= 0 )
|
|||
{ |
|||
argjson = cJSON_CreateObject(); |
|||
jaddstr(argjson,"method","checktxid"); |
|||
jaddbits256(argjson,"txid",utxo->payment.txid); |
|||
jaddnum(argjson,"vout",utxo->payment.vout); |
|||
if ( selector != 0 ) |
|||
{ |
|||
if ( bits256_nonz(utxo->deposit.txid) != 0 ) |
|||
u = utxo->deposit; |
|||
else u = utxo->fee; |
|||
jaddbits256(argjson,"checktxid",u.txid); |
|||
jaddnum(argjson,"checkvout",u.vout); |
|||
} |
|||
msg = jprint(argjson,1); |
|||
/LP_send(LP_mypubsock,msg,(int32_t)strlen(msg)+1,1); |
|||
}*/ |
|||
} |
|||
|
|||
char *LP_spentcheck(cJSON *argjson) |
|||
{ |
|||
bits256 txid,checktxid; int32_t vout,checkvout; struct LP_utxoinfo *utxo; int32_t iambob,retval = 0; |
|||
txid = jbits256(argjson,"txid"); |
|||
vout = jint(argjson,"vout"); |
|||
for (iambob=0; iambob<=1; iambob++) |
|||
{ |
|||
if ( (utxo= LP_utxofind(iambob,txid,vout)) != 0 && utxo->T.spentflag == 0 ) |
|||
{ |
|||
if ( jobj(argjson,"check") == 0 ) |
|||
checktxid = txid, checkvout = vout; |
|||
else |
|||
{ |
|||
checktxid = jbits256(argjson,"checktxid"); |
|||
checkvout = jint(argjson,"checkvout"); |
|||
} |
|||
if ( LP_txvalue(0,utxo->coin,checktxid,checkvout) == 0 ) |
|||
{ |
|||
if ( LP_mypeer != 0 && LP_mypeer->numutxos > 0 ) |
|||
LP_mypeer->numutxos--; |
|||
utxo->T.spentflag = (uint32_t)time(NULL); |
|||
retval++; |
|||
//printf("indeed txid was spent\n");
|
|||
} |
|||
} |
|||
} |
|||
if ( retval > 0 ) |
|||
return(clonestr("{\"result\":\"marked as spent\"}")); |
|||
return(clonestr("{\"error\":\"cant find txid to check spent status\"}")); |
|||
} |
|||
|
|||
void LP_utxo_clientpublish(struct LP_utxoinfo *utxo) |
|||
{ |
|||
bits256 zero; char *msg; |
|||
if ( LP_isunspent(utxo) > 0 ) |
|||
{ |
|||
memset(zero.bytes,0,sizeof(zero)); |
|||
msg = jprint(LP_utxojson(utxo),1); |
|||
LP_broadcast_message(LP_mypubsock,utxo->coin,"",zero,msg); |
|||
} |
|||
/*struct LP_peerinfo *peer,*tmp; cJSON *retjson; char *retstr; int32_t n = 0;
|
|||
HASH_ITER(hh,LP_peerinfos,peer,tmp) |
|||
{ |
|||
if ( (retstr= issue_LP_notifyutxo(peer->ipaddr,peer->port,utxo)) != 0 ) |
|||
{ |
|||
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|||
{ |
|||
if ( jobj(retjson,"error") == 0 ) |
|||
{ |
|||
utxo->T.lasttime = (uint32_t)time(NULL); |
|||
n++; |
|||
} |
|||
free_json(retjson); |
|||
} |
|||
free(retstr); |
|||
} |
|||
//if ( utxo->T.lasttime != 0 )
|
|||
// return(0);
|
|||
} |
|||
return(n);*/ |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bits256 txid,int32_t vout,int64_t value,bits256 txid2,int32_t vout2,int64_t value2,char *spendscript,char *coinaddr,bits256 pubkey,char *gui,uint32_t sessionid) |
|||
{ |
|||
uint64_t val,val2=0,tmpsatoshis,txfee; cJSON *txobj; int32_t spendvini,numconfirms,selector; bits256 spendtxid; struct iguana_info *coin; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo = 0; |
|||
if ( symbol == 0 || symbol[0] == 0 || spendscript == 0 || spendscript[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 || vout < 0 || vout2 < 0 || value <= 0 || value2 <= 0 || sessionid == 0 ) |
|||
{ |
|||
printf("session.%u malformed addutxo %d %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,spendscript == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); |
|||
return(0); |
|||
} |
|||
if ( (coin= LP_coinfind(symbol)) == 0 || (IAMLP == 0 && coin->inactive != 0) ) |
|||
{ |
|||
printf("LP_utxoadd reject inactive %s\n",symbol); |
|||
return(0); |
|||
} |
|||
txfee = LP_txfeecalc(coin->symbol,0); |
|||
if ( iambob != 0 && value2 < 9 * (value >> 3) + 2*txfee ) // big txfee padding
|
|||
{ |
|||
if ( value2 > 2*txfee ) |
|||
tmpsatoshis = (((value2 - 2*txfee) / 9) << 3); |
|||
else return(0); |
|||
} else tmpsatoshis = (value - txfee); |
|||
char str[65],str2[65],dispflag = (iambob == 0); |
|||
if ( iambob == 0 && bits256_cmp(pubkey,LP_mypub25519) != 0 ) |
|||
{ |
|||
printf("trying to add Alice utxo when not mine? %s/v%d\n",bits256_str(str,txid),vout); |
|||
return(0); |
|||
} |
|||
if ( LP_iseligible(&val,&val2,iambob,symbol,txid,vout,tmpsatoshis,txid2,vout2) <= 0 ) |
|||
{ |
|||
printf("iambob.%d utxoadd %s inactive.%u got ineligible txid value %.8f, value2 %.8f, tmpsatoshis %.8f\n",iambob,symbol,coin->inactive,dstr(value),dstr(value2),dstr(tmpsatoshis)); |
|||
return(0); |
|||
} |
|||
numconfirms = -1; |
|||
if ( (txobj= LP_gettx(symbol,txid)) != 0 ) |
|||
{ |
|||
numconfirms = jint(txobj,"confirmations"); |
|||
free_json(txobj); |
|||
} |
|||
if ( numconfirms <= 0 ) |
|||
{ |
|||
printf("LP_utxoadd reject numconfirms.%d\n",numconfirms); |
|||
return(0); |
|||
} |
|||
numconfirms = -1; |
|||
if ( (txobj= LP_gettx(symbol,txid2)) != 0 ) |
|||
{ |
|||
numconfirms = jint(txobj,"confirmations"); |
|||
free_json(txobj); |
|||
} |
|||
if ( numconfirms <= 0 ) |
|||
{ |
|||
printf("LP_utxoadd reject2 numconfirms.%d\n",numconfirms); |
|||
return(0); |
|||
} |
|||
if ( dispflag != 0 ) |
|||
printf("%.8f %.8f %s iambob.%d %s utxoadd.(%.8f %.8f) %s %s\n",dstr(val),dstr(val2),coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); |
|||
dispflag = 1; |
|||
if ( (selector= LP_mempool_vinscan(&spendtxid,&spendvini,symbol,txid,vout,txid2,vout2)) >= 0 ) |
|||
{ |
|||
printf("utxoadd selector.%d spent in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); |
|||
return(0); |
|||
} |
|||
if ( (utxo= LP_utxofinds(iambob,txid,vout,txid2,vout2)) != 0 ) |
|||
{ |
|||
if ( 0 && LP_ismine(utxo) == 0 ) |
|||
{ |
|||
char str2[65],str3[65]; printf("iambob.%d %s %s utxoadd.(%.8f %.8f) %s %s\n",iambob,bits256_str(str3,pubkey),symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); |
|||
printf("duplicate %.8f %.8f %.8f vs utxo.(%.8f %.8f %.8f)\n",dstr(value),dstr(value2),dstr(tmpsatoshis),dstr(utxo->payment.value),dstr(utxo->deposit.value),dstr(utxo->S.satoshis)); |
|||
} |
|||
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; |
|||
if ( bits256_cmp(txid,utxo->payment.txid) != 0 || bits256_cmp(txid2,u.txid) != 0 || vout != utxo->payment.vout || value != utxo->payment.value || tmpsatoshis != utxo->S.satoshis || vout2 != u.vout || value2 != u.value || strcmp(symbol,utxo->coin) != 0 || strcmp(spendscript,utxo->spendscript) != 0 || strcmp(coinaddr,utxo->coinaddr) != 0 || bits256_cmp(pubkey,utxo->pubkey) != 0 ) |
|||
{ |
|||
utxo->T.errors++; |
|||
char str[65],str2[65],str3[65],str4[65],str5[65],str6[65]; |
|||
if ( utxo->T.spentflag != 0 || LP_txvalue(0,utxo->coin,utxo->payment.txid,utxo->payment.vout) < utxo->payment.value || LP_txvalue(0,utxo->coin,u.txid,u.vout) < u.value ) |
|||
{ |
|||
if ( utxo->T.spentflag == 0 ) |
|||
utxo->T.spentflag = (uint32_t)time(NULL); |
|||
printf("original utxo pair not valid\n"); |
|||
if ( dispflag != 0 ) |
|||
printf("error on subsequent utxo iambob.%d %.8f %.8f add.(%s %s) when.(%s %s) %d %d %d %d %d %d %d %d %d %d %d pubkeys.(%s vs %s)\n",iambob,dstr(val),dstr(val2),bits256_str(str,txid),bits256_str(str2,txid2),bits256_str(str3,utxo->payment.txid),bits256_str(str4,utxo->deposit.txid),bits256_cmp(txid,utxo->payment.txid) != 0,bits256_cmp(txid2,u.txid) != 0,vout != utxo->payment.vout,tmpsatoshis != utxo->S.satoshis,vout2 != u.vout,value2 != u.value,strcmp(symbol,utxo->coin) != 0,strcmp(spendscript,utxo->spendscript) != 0,strcmp(coinaddr,utxo->coinaddr) != 0,bits256_cmp(pubkey,utxo->pubkey) != 0,value != utxo->payment.value,bits256_str(str5,pubkey),bits256_str(str6,utxo->pubkey)); |
|||
utxo = 0; |
|||
} |
|||
} |
|||
if ( utxo != 0 ) |
|||
{ |
|||
if ( utxo->T.sessionid == 0 ) |
|||
utxo->T.sessionid = sessionid; |
|||
//else if ( profitmargin > SMALLVAL )
|
|||
// utxo->S.profitmargin = profitmargin;
|
|||
utxo->T.lasttime = (uint32_t)time(NULL); |
|||
return(utxo); |
|||
} |
|||
} |
|||
utxo = calloc(1,sizeof(*utxo)); |
|||
//utxo->S.profitmargin = profitmargin;
|
|||
utxo->pubkey = pubkey; |
|||
safecopy(utxo->gui,gui,sizeof(utxo->gui)); |
|||
safecopy(utxo->coin,symbol,sizeof(utxo->coin)); |
|||
safecopy(utxo->coinaddr,coinaddr,sizeof(utxo->coinaddr)); |
|||
safecopy(utxo->spendscript,spendscript,sizeof(utxo->spendscript)); |
|||
utxo->payment.txid = txid; |
|||
utxo->payment.vout = vout; |
|||
utxo->payment.value = value; |
|||
utxo->S.satoshis = tmpsatoshis; |
|||
if ( (utxo->iambob= iambob) != 0 ) |
|||
{ |
|||
utxo->deposit.txid = txid2; |
|||
utxo->deposit.vout = vout2; |
|||
utxo->deposit.value = value2; |
|||
} |
|||
else |
|||
{ |
|||
utxo->fee.txid = txid2; |
|||
utxo->fee.vout = vout2; |
|||
utxo->fee.value = value2; |
|||
} |
|||
LP_utxosetkey(utxo->key,txid,vout); |
|||
LP_utxosetkey(utxo->key2,txid2,vout2); |
|||
if ( LP_ismine(utxo) > 0 ) |
|||
utxo->T.sessionid = LP_sessionid; |
|||
else utxo->T.sessionid = sessionid; |
|||
printf("U.%d %s %.8f %.8f addutxo.%d pubkey.%s session.%u\n",LP_mypeer!=0?LP_mypeer->numutxos:-1,symbol,dstr(value),dstr(value2),LP_ismine(utxo) > 0,bits256_str(str,utxo->pubkey),utxo->T.sessionid); |
|||
portable_mutex_lock(&LP_utxomutex); |
|||
HASH_ADD_KEYPTR(hh,LP_utxoinfos[iambob],utxo->key,sizeof(utxo->key),utxo); |
|||
if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) |
|||
HASH_ADD_KEYPTR(hh2,LP_utxoinfos2[iambob],utxo->key2,sizeof(utxo->key2),utxo); |
|||
portable_mutex_unlock(&LP_utxomutex); |
|||
if ( iambob != 0 ) |
|||
{ |
|||
if ( LP_mypeer != 0 ) |
|||
LP_mypeer->numutxos++; |
|||
if ( LP_ismine(utxo) > 0 ) |
|||
{ |
|||
LP_utxo_clientpublish(utxo); |
|||
if ( LP_mypeer != 0 ) |
|||
utxo->T.lasttime = (uint32_t)time(NULL); |
|||
} |
|||
} |
|||
return(utxo); |
|||
} |
|||
|
|||
struct LP_utxoinfo *LP_utxoaddjson(int32_t iambob,int32_t pubsock,cJSON *argjson) |
|||
{ |
|||
struct LP_utxoinfo *utxo; |
|||
if ( jobj(argjson,"iambob") == 0 || iambob != jint(argjson,"iambob") ) |
|||
{ |
|||
printf("LP_utxoaddjson: iambob.%d != arg.%d obj.%p (%s)\n",iambob,jint(argjson,"iambob"),jobj(argjson,"iambob"),jprint(argjson,0)); |
|||
return(0); |
|||
} |
|||
portable_mutex_lock(&LP_UTXOmutex); |
|||
utxo = LP_utxoadd(iambob,pubsock,jstr(argjson,"coin"),jbits256(argjson,"txid"),jint(argjson,"vout"),j64bits(argjson,"value"),jbits256(argjson,"txid2"),jint(argjson,"vout2"),j64bits(argjson,"value2"),jstr(argjson,"script"),jstr(argjson,"address"),jbits256(argjson,"pubkey"),jstr(argjson,"gui"),juint(argjson,"session")); |
|||
if ( LP_ismine(utxo) > 0 && utxo->T.lasttime == 0 ) |
|||
{ |
|||
utxo->T.lasttime = (uint32_t)time(NULL); |
|||
printf("set lasttime!\n"); |
|||
} |
|||
portable_mutex_unlock(&LP_UTXOmutex); |
|||
return(utxo); |
|||
} |
|||
|
|||
int32_t LP_utxosparse(char *destipaddr,uint16_t destport,char *retstr,uint32_t now) |
|||
{ |
|||
struct LP_peerinfo *destpeer,*peer; uint32_t argipbits; char *argipaddr; uint16_t argport,pushport,subport; cJSON *array,*item; int32_t i,n=0; bits256 txid; struct LP_utxoinfo *utxo; |
|||
//printf("parse.(%s)\n",retstr);
|
|||
if ( (array= cJSON_Parse(retstr)) != 0 ) |
|||
{ |
|||
if ( (n= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
if ( (argipaddr= jstr(item,"ipaddr")) != 0 && (argport= juint(item,"port")) != 0 ) |
|||
{ |
|||
if ( (pushport= juint(item,"push")) == 0 ) |
|||
pushport = argport + 1; |
|||
if ( (subport= juint(item,"sub")) == 0 ) |
|||
subport = argport + 2; |
|||
argipbits = (uint32_t)calc_ipbits(argipaddr); |
|||
if ( (peer= LP_peerfind(argipbits,argport)) == 0 ) |
|||
peer = LP_addpeer(0,-1,argipaddr,argport,pushport,subport,jint(item,"numpeers"),jint(item,"numutxos"),juint(item,"session")); |
|||
} |
|||
if ( jobj(item,"txid") != 0 ) |
|||
{ |
|||
txid = jbits256(item,"txid"); |
|||
//printf("parse.(%s)\n",jprint(item,0));
|
|||
if ( (utxo= LP_utxoaddjson(1,-1,item)) != 0 ) |
|||
utxo->T.lasttime = now; |
|||
} |
|||
} |
|||
if ( (destpeer= LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport)) != 0 ) |
|||
{ |
|||
destpeer->numutxos = n; |
|||
} |
|||
} |
|||
free_json(array); |
|||
} |
|||
return(n); |
|||
} |
|||
|
|||
int32_t LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *coin,int32_t lastn,char *myipaddr,uint16_t myport,int32_t maxentries) |
|||
{ |
|||
char *retstr; struct LP_peerinfo *peer; uint32_t now; int32_t retval = -1; |
|||
peer = LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport); |
|||
if ( coin == 0 ) |
|||
coin = ""; |
|||
//printf("utxo query.(%s)\n",destipaddr);
|
|||
if ( IAMLP != 0 ) |
|||
retstr = issue_LP_getutxos(destipaddr,destport,coin,lastn,myipaddr,myport,mypeer != 0 ? mypeer->numpeers : 0,maxentries); |
|||
else retstr = issue_LP_clientgetutxos(destipaddr,destport,coin,maxentries); |
|||
if ( retstr != 0 ) |
|||
{ |
|||
now = (uint32_t)time(NULL); |
|||
retval = LP_utxosparse(destipaddr,destport,retstr,now); |
|||
//printf("got.(%s)\n",retstr);
|
|||
free(retstr); |
|||
/*i = 0;
|
|||
if ( lastn >= mypeer->numutxos ) |
|||
firsti = -1; |
|||
else firsti = (mypeer->numutxos - lastn); |
|||
HASH_ITER(hh,LP_utxoinfos,utxo,tmp) |
|||
{ |
|||
if ( i++ < firsti ) |
|||
continue; |
|||
if ( utxo->lasttime != now && strcmp(utxo->ipaddr,"127.0.0.1") != 0 ) |
|||
{ |
|||
char str[65]; printf("{%s:%u %s} ",utxo->ipaddr,utxo->port,bits256_str(str,utxo->txid)); |
|||
flag++; |
|||
if ( (retstr= issue_LP_notifyutxo(destipaddr,destport,utxo)) != 0 ) |
|||
free(retstr); |
|||
} |
|||
} |
|||
if ( flag != 0 ) |
|||
printf(" <- missing utxos\n");*/ |
|||
} |
|||
return(retval); |
|||
} |
|||
|
|||
cJSON *LP_inventory(char *symbol,int32_t iambob) |
|||
{ |
|||
struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; |
|||
array = cJSON_CreateArray(); |
|||
if ( LP_mypeer != 0 ) |
|||
myipaddr = LP_mypeer->ipaddr; |
|||
else myipaddr = "127.0.0.1"; |
|||
HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) |
|||
{ |
|||
//char str[65]; printf("iambob.%d iterate %s\n",iambob,bits256_str(str,LP_mypub25519));
|
|||
if ( LP_isunspent(utxo) != 0 && strcmp(symbol,utxo->coin) == 0 && utxo->iambob == iambob && LP_ismine(utxo) > 0 ) |
|||
{ |
|||
u = (iambob != 0) ? utxo->deposit : utxo->fee; |
|||
if ( LP_iseligible(&val,&val2,iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,u.txid,u.vout) == 0 ) |
|||
{ |
|||
if ( utxo->T.spentflag == 0 ) |
|||
utxo->T.spentflag = (uint32_t)time(NULL); |
|||
continue; |
|||
} |
|||
if ( iambob != 0 ) |
|||
LP_utxo_clientpublish(utxo); |
|||
jaddi(array,LP_inventoryjson(cJSON_CreateObject(),utxo)); |
|||
} |
|||
//else printf("skip %s %d %d %d %d\n",bits256_str(str,utxo->pubkey),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0);
|
|||
} |
|||
return(array); |
|||
} |
|||
|
|||
int32_t LP_maxvalue(uint64_t *values,int32_t n) |
|||
{ |
|||
int32_t i,maxi = -1; uint64_t maxval = 0; |
|||
for (i=0; i<n; i++) |
|||
if ( values[i] > maxval ) |
|||
{ |
|||
maxi = i; |
|||
maxval = values[i]; |
|||
} |
|||
return(maxi); |
|||
} |
|||
|
|||
int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targetval) |
|||
{ |
|||
int32_t i,mini = -1; int64_t dist; uint64_t mindist = (1 << 31); |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
dist = (values[i] - targetval); |
|||
if ( iambob != 0 && dist < 0 && -dist < values[i]/10 ) |
|||
dist = -dist; |
|||
//printf("(%.8f %.8f %.8f).%d ",dstr(values[i]),dstr(dist),dstr(mindist),mini);
|
|||
if ( dist >= 0 && dist < mindist ) |
|||
{ |
|||
mini = i; |
|||
mindist = dist; |
|||
} |
|||
} |
|||
return(mini); |
|||
} |
|||
|
|||
uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) |
|||
{ |
|||
char *script; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,targetval,value,total = 0; |
|||
if ( coin == 0 ) |
|||
{ |
|||
printf("coin not active\n"); |
|||
return(0); |
|||
} |
|||
//printf("privkey init.(%s) %s\n",coin->symbol,coin->smartaddr);
|
|||
if ( coin->inactive == 0 && (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) |
|||
{ |
|||
txfee = LP_txfeecalc(coin->symbol,0); |
|||
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) |
|||
{ |
|||
for (iambob=0; iambob<=1; iambob++) |
|||
{ |
|||
if ( iambob == 0 ) |
|||
values = calloc(n,sizeof(*values)); |
|||
else memset(values,0,n * sizeof(*values)); |
|||
//if ( iambob == 0 && IAMLP != 0 )
|
|||
// continue;
|
|||
used = 0; |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
item = jitem(array,i); |
|||
satoshis = SATOSHIDEN * jdouble(item,"amount"); |
|||
if ( satoshis == 0 ) |
|||
satoshis = SATOSHIDEN * jdouble(item,"value"); |
|||
if ( LP_inventory_prevent(iambob,jbits256(item,"txid"),juint(item,"vout")) == 0 && jint(item,"confirmations") > 0 ) |
|||
{ |
|||
//printf("%s\n",jprint(item,0));
|
|||
values[i] = satoshis; |
|||
} else used++; |
|||
//printf("%.8f ",dstr(satoshis));
|
|||
} |
|||
//printf("array.%d\n",n);
|
|||
while ( used < n-1 ) |
|||
{ |
|||
//for (i=0; i<n; i++)
|
|||
// printf("%.8f ",dstr(values[i]));
|
|||
//printf("used.%d of n.%d\n",used,n);
|
|||
if ( (i= LP_maxvalue(values,n)) >= 0 ) |
|||
{ |
|||
item = jitem(array,i); |
|||
deposittxid = jbits256(item,"txid"); |
|||
depositvout = juint(item,"vout"); |
|||
script = jstr(item,"scriptPubKey"); |
|||
depositval = values[i]; |
|||
values[i] = 0, used++; |
|||
if ( iambob == 0 ) |
|||
targetval = (depositval / 776) + txfee; |
|||
else targetval = (depositval / 9) * 8 + 2*txfee; |
|||
if ( depositval < (1+LP_MINSIZE_TXFEEMULT)*txfee ) |
|||
continue; |
|||
//printf("iambob.%d i.%d %.8f target %.8f\n",iambob,i,dstr(depositval),dstr(targetval));
|
|||
i = -1; |
|||
if ( iambob != 0 ) |
|||
{ |
|||
if ( (i= LP_nearestvalue(iambob,values,n,targetval)) < 0 ) |
|||
targetval /= 4; |
|||
if ( targetval < txfee*(1+LP_MINSIZE_TXFEEMULT) ) |
|||
continue; |
|||
} |
|||
if ( i >= 0 || (i= LP_nearestvalue(iambob,values,n,targetval)) >= 0 ) |
|||
{ |
|||
item = jitem(array,i); |
|||
txid = jbits256(item,"txid"); |
|||
vout = juint(item,"vout"); |
|||
if ( jstr(item,"scriptPubKey") != 0 && strcmp(script,jstr(item,"scriptPubKey")) == 0 ) |
|||
{ |
|||
value = values[i]; |
|||
values[i] = 0, used++; |
|||
portable_mutex_lock(&LP_UTXOmutex); |
|||
if ( iambob != 0 ) |
|||
{ |
|||
if ( (utxo= LP_utxoadd(1,mypubsock,coin->symbol,txid,vout,value,deposittxid,depositvout,depositval,script,coin->smartaddr,mypub,LP_gui,LP_sessionid)) != 0 ) |
|||
{ |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if ( (utxo= LP_utxoadd(0,mypubsock,coin->symbol,deposittxid,depositvout,depositval,txid,vout,value,script,coin->smartaddr,mypub,LP_gui,LP_sessionid)) != 0 ) |
|||
{ |
|||
} |
|||
} |
|||
portable_mutex_unlock(&LP_UTXOmutex); |
|||
total += value; |
|||
} else printf("scriptmismatch.(%s) vs %s\n",script,jprint(item,0)); |
|||
} //else printf("nothing near i.%d\n",i);
|
|||
} else break; |
|||
} |
|||
if ( iambob == 1 ) |
|||
free(values); |
|||
} |
|||
} |
|||
free_json(array); |
|||
} |
|||
//printf("privkey.%s %.8f\n",symbol,dstr(total));
|
|||
return(total); |
|||
} |
|||
|
|||
bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr) |
|||
{ |
|||
static uint32_t counter; |
|||
bits256 privkey,userpub,userpass,checkkey; char tmpstr[128]; cJSON *retjson; uint8_t tmptype,rmd160[20]; |
|||
if ( passphrase != 0 && passphrase[0] != 0 ) |
|||
conv_NXTpassword(privkey.bytes,pubkeyp->bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); |
|||
else |
|||
{ |
|||
bitcoin_wif2priv(coin->wiftaddr,&tmptype,&privkey,wifstr); |
|||
if ( 0 ) |
|||
{ |
|||
char str[65],str2[65]; |
|||
checkkey = iguana_wif2privkey(wifstr); |
|||
if ( bits256_cmp(checkkey,privkey) != 0 ) |
|||
printf("WIF.(%s) -> %s or %s?\n",wifstr,bits256_str(str,privkey),bits256_str(str2,checkkey)); |
|||
} |
|||
} |
|||
bitcoin_priv2pub(ctx,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype); |
|||
if ( coin->counter == 0 ) |
|||
{ |
|||
coin->counter++; |
|||
bitcoin_priv2wif(coin->wiftaddr,tmpstr,privkey,coin->wiftype); |
|||
bitcoin_addr2rmd160(coin->taddr,&tmptype,rmd160,coin->smartaddr); |
|||
LP_privkeyadd(privkey,rmd160); |
|||
if ( 0 && (coin->pubtype != 60 || strcmp(coin->symbol,"KMD") == 0) ) |
|||
printf("%s (%s) %d wif.(%s) (%s)\n",coin->symbol,coin->smartaddr,coin->pubtype,tmpstr,passphrase); |
|||
if ( counter++ == 0 ) |
|||
{ |
|||
bitcoin_priv2wif(coin->wiftaddr,USERPASS_WIFSTR,privkey,188); |
|||
bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,USERPASS_WIFSTR); |
|||
if ( bits256_cmp(checkkey,privkey) != 0 ) |
|||
{ |
|||
char str[65],str2[65]; |
|||
printf("FATAL ERROR converting USERPASS_WIFSTR %s -> %s != %s\n",USERPASS_WIFSTR,bits256_str(str,checkkey),bits256_str(str2,privkey)); |
|||
exit(-1); |
|||
} |
|||
conv_NXTpassword(userpass.bytes,pubkeyp->bytes,(uint8_t *)USERPASS_WIFSTR,(int32_t)strlen(USERPASS_WIFSTR)); |
|||
userpub = curve25519(userpass,curve25519_basepoint9()); |
|||
printf("userpass.(%s)\n",bits256_str(USERPASS,userpub)); |
|||
} |
|||
if ( (retjson= LP_importprivkey(coin->symbol,tmpstr,coin->smartaddr,-1)) != 0 ) |
|||
{ |
|||
if ( jobj(retjson,"error") != 0 ) |
|||
{ |
|||
printf("cant importprivkey.%s -> (%s), abort session\n",coin->symbol,jprint(retjson,1)); |
|||
exit(-1); |
|||
} |
|||
} |
|||
} |
|||
LP_mypub25519 = *pubkeyp = curve25519(privkey,curve25519_basepoint9()); |
|||
LP_mypriv25519 = privkey; |
|||
//printf("privkey.(%s) -> LP_mypub25519.(%s)\n",bits256_str(str,privkey),bits256_str(str2,LP_mypub25519));
|
|||
return(privkey); |
|||
} |
|||
|
|||
void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase,int32_t initonly) |
|||
{ |
|||
struct iguana_info *coin,*tmp; bits256 pubkey,privkey; uint8_t pubkey33[33]; |
|||
memset(privkey.bytes,0,sizeof(privkey)); |
|||
pubkey = privkey; |
|||
HASH_ITER(hh,LP_coins,coin,tmp) |
|||
{ |
|||
//printf("i.%d of %d\n",i,LP_numcoins);
|
|||
if ( bits256_nonz(privkey) == 0 || coin->smartaddr[0] == 0 ) |
|||
privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,coin,passphrase,""); |
|||
if ( coin->inactive == 0 && initonly == 0 ) |
|||
LP_privkey_init(pubsock,coin,privkey,pubkey); |
|||
} |
|||
} |
|||
|
|||
|
@ -0,0 +1,77 @@ |
|||
Latest Readme is at http://pad.supernet.org/barterdex-readme |
|||
|
|||
DEPENDENCIES |
|||
First of all you are going to need to have the komodod daemon and the assetchains running. |
|||
Install dependency packages: |
|||
sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool libncurses5-dev unzip git python zlib1g-dev wget bsdmainutils automake libboost-all-dev libssl-dev libprotobuf-dev protobuf-compiler libqt4-dev libqrencode-dev libdb++-dev ntp ntpdate vim software-properties-common curl libcurl4-gnutls-dev cmake clang |
|||
Some Linux machines are now providing nanomsg package version 1.0. If it is available via package manager, you can install it from there. Else, you should use github repo of nanomsg and compile it yourself. |
|||
For Ubuntu 14.04 you need to install it yourself |
|||
cd /tmp |
|||
wget https://github.com/nanomsg/nanomsg/archive/1.0.0.tar.gz -O nanomsg-1.0.0.tar.gz |
|||
tar -xzvf nanomsg-1.0.0.tar.gz |
|||
cd nanomsg-1.0.0 |
|||
mkdir build |
|||
cd build |
|||
cmake .. -DCMAKE_INSTALL_PREFIX=/usr |
|||
cmake --build . |
|||
sudo cmake --build . --target install |
|||
sudo ldconfig |
|||
Or the following for 16.04 |
|||
git clone https://github.com/nanomsg/nanomsg |
|||
cd nanomsg |
|||
cmake . |
|||
make |
|||
sudo make install |
|||
sudo ldconfig |
|||
COMPILE LP NODE |
|||
To compile the BarterDEX you need to build iguana one time: |
|||
cd ~ |
|||
git clone https://github.com/jl777/SuperNET |
|||
cd SuperNET/iguana |
|||
git checkout dev |
|||
./m_LP |
|||
IGUANA DAEMON STARTUP |
|||
Then launch the iguana daemon by executing: |
|||
../agents/iguana & |
|||
Now iguana should be running and providing port 7778 API: 127.0.0.1:7778 page in the browser will show the API testpage, but for marketmaker these functions are not used very much. it is port 7779 that is used and the marketmaker program is what provides those functions. |
|||
BarterDEX EXCHANGE INSTALL |
|||
cd ~/SuperNET/iguana/exchanges |
|||
./install |
|||
Now, move to ~/SuperNET/iguana/dexscripts: |
|||
cd ~/SuperNET/iguana/dexscripts |
|||
Now in the ~/SuperNET/iguana/dexscripts directory you will have example scripts that you can change without new git updates overwriting them. These scripts will have example commands that you will need to customize to work with the coins you want to trade. Of course, if a new update to a script is made and you dont run install again then you wont have the latest versions. |
|||
For example: if you want to enable the JUMBLR coin, you need to edit the enable file: |
|||
nano ~SuperNET/iguana/dexscripts/enable |
|||
copy the default command and paste it below but with the coin edited to JUMBLR in this case: |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"JUMBLR\"}" |
|||
The same will happen for any other script in the dexscripts directory. You will need to edit the scripts to include or exclude the coins you want to trade. |
|||
IMPORTANT: All these scripts are expecting a userpass file, which contains the definition of the $userpass variable to authenticate API access. This avoids evil webpages that try to issue port 7779 calls to steal your money. At first you wont know the value of userpass. To find out, just run any API script. The first one will return all the required data, the "userpass" field is first and you can copy that value and put it into ~/SuperNET/iguana/dexscripts/userpass file. If you dont, all subsequent API calls will get authorization errors.The userpass variable is linked to each passphrase and that is defined in the passphrase file. Put your passphrase in that file. You can find templates for these two files in the iguana/exchanges dir. (you need to copy the edited version of these files to ~/SuperNET/iguana/dexscripts). |
|||
cd ~/SuperNET/iguana/dexscripts |
|||
./enable |
|||
(look for the userpass passphrase that will be generated and copy it) |
|||
Now you have to paste the passphrase in both userpass and passphrase files: |
|||
nano ./userpass |
|||
nano ./passphrase |
|||
( paste the passphrase generated into the files where it says: “<put the userpass value from the first API call here>”) |
|||
EXCHANGE CLIENT STARTUP |
|||
Next step is to actually start the marketmaker from ~/SuperNET/iguana/dexscripts. |
|||
cd ~/SuperNET/iguana/dexscripts |
|||
./client (for client mode) or |
|||
./run (for LPnode mode) |
|||
Assuming you created the userpass file properly, you can now issue barterDEX api calls using all the scripts in the dexscripts dir. Please look at these scripts, they are simple curl invocations of a couple lines. Nothing scary and should be self explanatory. |
|||
The help script displays all the api endpoints you should need. You can customize any of the dexscripts for your desired usage, make sure you edit them with the right coins, as if you issue a script for BTC it will do it for BTC instead of the coin you wanted. These scripts wont read your mind, they just do what is in them |
|||
FUNDING SMARTADDRESS |
|||
In order to start trading, you need to fund your smartaddress (as listed on the first API call return) from the getcoins API call. |
|||
To see which is your smart address go to ~/SuperNET/iguana/dexscritps and execute: |
|||
./getcoins |
|||
To make sure you have utxo pairs for both the bob and alice usage, it is best to send utxo in triplets of X, 1.2 X and 0.01 X. So if X is 10, send 10, 12, and 0.1 coins using sendtoaddress to your smartaddress. This means you will have to send 3 different transactions to the same address with 3 different quantities |
|||
for example: |
|||
If i want to fund my komodo smartaddress with 100 komodo i need to first send a tx with 100kmd then another tx with 120kmd and a third tx with only 10kmd |
|||
After this, it should appear in the inventory. To see the inventory you need to execute: |
|||
./inv |
|||
SETTING PRICE |
|||
To set price you need to edit the ./setprice script in the dexscripts folder. This scripts contains a curl command that looks like this: |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"setprice\",\"base\":\"REVS\",\"rel\":\"KMD\",\"price\":1.234}" |
|||
In this command you should edit the coin (in this case is REVS) and then set the price per coin based in Komodo. In the command above we are setting a price of 1.23KMD per REVS. |
|||
After you setprice (./setprice), then it will appear in orderbooks with that coin in either the base or rel. |
|||
|
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autofill\",\"base\":\"KMD\",\"rel\":\"BTC\",\"price\":0.0005,\"relvolume\":0.1}" |
@ -0,0 +1,9 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTC\",\"margin\":0.0001}" |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BTC\",\"rel\":\"KMD\",\"margin\":0.0001}" |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"HUSH\",\"margin\":0.01}" |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"HUSH\",\"rel\":\"KMD\",\"margin\":0.01}" |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"USD\",\"margin\":0.01}" |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"USD\",\"rel\":\"KMD\",\"margin\":0.01}" |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"JUMBLR\",\"margin\":0.01}" |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"JUMBLR\",\"rel\":\"KMD\",\"margin\":0.01}" |
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autotrade\",\"base\":\"REVS\",\"rel\":\"KMD\",\"relvolume\":1.01,\"price\":1.234}" |
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"bestfit\",\"rel\":\"KMD\",\"relvolume\":1.01}" |
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"setprice\",\"base\":\"REVS\",\"rel\":\"KMD\",\"price\":9999999.99}" |
@ -0,0 +1,8 @@ |
|||
source passphrase |
|||
source coins |
|||
pkill -15 marketmaker; |
|||
git pull; |
|||
cd ..; |
|||
./m_mm; |
|||
./marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" & |
|||
|
@ -0,0 +1,8 @@ |
|||
source passphrase |
|||
source coins |
|||
pkill -15 marketmaker; |
|||
git pull; |
|||
cd ..; |
|||
./m_mm; |
|||
./marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"/${HOME#"/"}/Library/Application\ Support\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" & |
|||
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,8 @@ |
|||
source passphrase |
|||
source coins |
|||
pkill -15 marketmaker; |
|||
git pull; |
|||
cd ..; |
|||
./m_mm; |
|||
gdb -args ./marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" |
|||
|
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"deletemessages\",\"firsti\":0,\"num\":10}" |
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"disable\",\"coin\":\"REVS\"}" |
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"dividends\",\"coin\":\"KMD\",\"height\":$1,\"prefix\":\"fiat/jumblr sendtoaddress\",\"suffix\":\"\",\"dividend\":50000,\"dust\":1}" |
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BTC\"}" |
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"getcoin\",\"coin\":\"LTC\"}" |
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"getcoins\"}" |
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"getmessages\",\"firsti\":0,\"num\":10}" |
@ -0,0 +1,2 @@ |
|||
source userpass |
|||
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"getpeers\"}" |
@ -0,0 +1,10 @@ |
|||
curl --url "http://5.9.253.195:7779" --data "{\"method\":\"getpeers\"}" |
|||
curl --url "http://5.9.253.196:7779" --data "{\"method\":\"getpeers\"}" |
|||
curl --url "http://5.9.253.197:7779" --data "{\"method\":\"getpeers\"}" |
|||
curl --url "http://5.9.253.198:7779" --data "{\"method\":\"getpeers\"}" |
|||
curl --url "http://5.9.253.199:7779" --data "{\"method\":\"getpeers\"}" |
|||
curl --url "http://5.9.253.200:7779" --data "{\"method\":\"getpeers\"}" |
|||
curl --url "http://5.9.253.201:7779" --data "{\"method\":\"getpeers\"}" |
|||
curl --url "http://5.9.253.202:7779" --data "{\"method\":\"getpeers\"}" |
|||
curl --url "http://5.9.253.203:7779" --data "{\"method\":\"getpeers\"}" |
|||
curl --url "http://5.9.253.204:7779" --data "{\"method\":\"getpeers\"}" |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue