|
| 1 | +packageio.api.core.impl; |
| 2 | + |
| 3 | +importio.api.core.IProxyProvider; |
| 4 | +importio.api.executor.IHttpExecutor; |
| 5 | +importio.api.manager.IQueueManager; |
| 6 | +importio.api.model.proxy.BlockProxy; |
| 7 | +importio.api.model.proxy.TxProxy; |
| 8 | +importio.api.model.proxy.utility.BlockProxyTO; |
| 9 | +importio.api.model.proxy.utility.StringProxyTO; |
| 10 | +importio.api.model.proxy.utility.TxProxyTO; |
| 11 | +importio.api.util.BasicUtils; |
| 12 | +importorg.jetbrains.annotations.NotNull; |
| 13 | + |
| 14 | +importjava.math.BigInteger; |
| 15 | +importjava.util.Optional; |
| 16 | + |
| 17 | +/** |
| 18 | + * ! NO DESCRIPTION ! |
| 19 | + * |
| 20 | + * @author GoodforGod |
| 21 | + * @since 28.10.2018 |
| 22 | + */ |
| 23 | +publicclassProxyProviderextendsBasicProviderimplementsIProxyProvider { |
| 24 | + |
| 25 | +privatestaticfinalStringACT_BLOCKNO_PARAM =ACT_PREFIX +"eth_blockNumber"; |
| 26 | +privatestaticfinalStringACT_BY_BLOCKNO_PARAM =ACT_PREFIX +"eth_getBlockByNumber"; |
| 27 | +privatestaticfinalStringACT_UNCLE_BY_BLOCKNOINDEX_PARAM =ACT_PREFIX +"eth_getUncleByBlockNumberAndIndex"; |
| 28 | +privatestaticfinalStringACT_BLOCKTX_COUNT_PARAM =ACT_PREFIX +"eth_getBlockTransactionCountByNumber"; |
| 29 | +privatestaticfinalStringACT_TX_BY_HASH_PARAM =ACT_PREFIX +"eth_getTransactionByHash"; |
| 30 | +privatestaticfinalStringACT_TX_BY_BLOCKNOINDEX_PARAM =ACT_PREFIX +"eth_getTransactionByBlockNumberAndIndex"; |
| 31 | +privatestaticfinalStringACT_TX_COUNT_PARAM =ACT_PREFIX +"eth_getTransactionCount"; |
| 32 | +privatestaticfinalStringACT_SEND_RAW_TX_PARAM =ACT_PREFIX +"eth_sendRawTransaction"; |
| 33 | +privatestaticfinalStringACT_TX_RECEIPT_PARAM =ACT_PREFIX +"eth_getTransactionReceipt"; |
| 34 | +privatestaticfinalStringACT_CALL_PARAM =ACT_PREFIX +"eth_call"; |
| 35 | +privatestaticfinalStringACT_CODE_PARAM =ACT_PREFIX +"eth_getCode"; |
| 36 | +privatestaticfinalStringACT_STORAGEAT_PARAM =ACT_PREFIX +"eth_getStorageAt"; |
| 37 | +privatestaticfinalStringACT_GASPRICE_PARAM =ACT_PREFIX +"eth_gasPrice"; |
| 38 | +privatestaticfinalStringACT_ESTIMATEGAS_PARAM =ACT_PREFIX +"eth_estimateGas"; |
| 39 | + |
| 40 | +privatestaticfinalStringBOOLEAN_PARAM ="&boolean=true"; |
| 41 | +privatestaticfinalStringTAG_LAST_PARAM ="&tag=lastest"; |
| 42 | +privatestaticfinalStringGASPRICE_PARAM ="&gasPrice="; |
| 43 | +privatestaticfinalStringPOSITION_PARAM ="&position="; |
| 44 | +privatestaticfinalStringADDRESS_PARAM ="&address="; |
| 45 | +privatestaticfinalStringTXHASH_PARAM ="&txhash="; |
| 46 | +privatestaticfinalStringINDEX_PARAM ="&index="; |
| 47 | +privatestaticfinalStringVALUE_PARAM ="&value="; |
| 48 | +privatestaticfinalStringDATA_PARAM ="&data="; |
| 49 | +privatestaticfinalStringGAS_PARAM ="&gas="; |
| 50 | +privatestaticfinalStringTAG_PARAM ="&tag="; |
| 51 | +privatestaticfinalStringHEX_PARAM ="&hex="; |
| 52 | +privatestaticfinalStringTO_PARAM ="&to="; |
| 53 | + |
| 54 | +ProxyProvider(finalIQueueManagerqueue, |
| 55 | +finalStringbaseUrl, |
| 56 | +finalIHttpExecutorexecutor) { |
| 57 | +super(queue,"proxy",baseUrl,executor); |
| 58 | + } |
| 59 | + |
| 60 | +@Override |
| 61 | +publiclongblockNoLast() { |
| 62 | +return0; |
| 63 | + } |
| 64 | + |
| 65 | +@NotNull |
| 66 | +@Override |
| 67 | +publicOptional<BlockProxy>block(finallongblockNo) { |
| 68 | +finallongcompBlockNo =BasicUtils.compensateMinBlock(blockNo); |
| 69 | + |
| 70 | +finalStringurlParams =ACT_BY_BLOCKNO_PARAM +TAG_PARAM +compBlockNo; |
| 71 | +finalBlockProxyTOresponse =getRequest(urlParams,BlockProxyTO.class); |
| 72 | +returnOptional.ofNullable(response.getResult()); |
| 73 | + } |
| 74 | + |
| 75 | +@NotNull |
| 76 | +@Override |
| 77 | +publicOptional<BlockProxy>blockUncle(finallongblockNo,finallongindex) { |
| 78 | +finallongcompBlockNo =BasicUtils.compensateMinBlock(blockNo); |
| 79 | +finallongcompIndex =BasicUtils.compensateMinBlock(index); |
| 80 | + |
| 81 | +finalStringurlParams =ACT_UNCLE_BY_BLOCKNOINDEX_PARAM +TAG_PARAM +compBlockNo +INDEX_PARAM +compIndex; |
| 82 | +finalBlockProxyTOresponse =getRequest(urlParams,BlockProxyTO.class); |
| 83 | +returnOptional.ofNullable(response.getResult()); |
| 84 | + } |
| 85 | + |
| 86 | +@NotNull |
| 87 | +@Override |
| 88 | +publicOptional<TxProxy>tx(finalStringtxhash) { |
| 89 | +BasicUtils.validateTxHash(txhash); |
| 90 | + |
| 91 | +finalStringurlParams =ACT_TX_BY_HASH_PARAM +TXHASH_PARAM +txhash; |
| 92 | +finalTxProxyTOresponse =getRequest(urlParams,TxProxyTO.class); |
| 93 | +returnOptional.ofNullable(response.getResult()); |
| 94 | + } |
| 95 | + |
| 96 | +@NotNull |
| 97 | +@Override |
| 98 | +publicOptional<TxProxy>tx(finallongblockNo,finallongindex) { |
| 99 | +finallongcompBlockNo =BasicUtils.compensateMinBlock(blockNo); |
| 100 | +finallongcompIndex =BasicUtils.compensateMinBlock(index); |
| 101 | + |
| 102 | +finalStringurlParams =ACT_TX_BY_BLOCKNOINDEX_PARAM +TAG_PARAM +compBlockNo +INDEX_PARAM +compIndex; |
| 103 | +finalTxProxyTOresponse =getRequest(urlParams,TxProxyTO.class); |
| 104 | +returnOptional.ofNullable(response.getResult()); |
| 105 | + } |
| 106 | + |
| 107 | +@Override |
| 108 | +publicinttxCount(finallongblockNo) { |
| 109 | +finallongcompensatedBlockNo =BasicUtils.compensateMinBlock(blockNo); |
| 110 | +finalStringurlParams =ACT_TX_COUNT_PARAM +TAG_PARAM +compensatedBlockNo; |
| 111 | +finalStringProxyTOresponse =getRequest(urlParams,StringProxyTO.class); |
| 112 | +returnInteger.valueOf(response.getResult()); |
| 113 | + } |
| 114 | + |
| 115 | +@Override |
| 116 | +publicinttxSendCount(finalStringaddress) { |
| 117 | +BasicUtils.validateAddress(address); |
| 118 | + |
| 119 | +finalStringurlParams =ACT_TX_BY_HASH_PARAM +ADDRESS_PARAM +address +TAG_LAST_PARAM; |
| 120 | +finalStringProxyTOresponse =getRequest(urlParams,StringProxyTO.class); |
| 121 | +return (int)BasicUtils.parseHex(response.getResult()); |
| 122 | + } |
| 123 | + |
| 124 | +//TODO need postRequest executor implementation |
| 125 | +@Override |
| 126 | +publicbooleantxSendRaw(finalStringhexEncodedTx) { |
| 127 | +returnfalse; |
| 128 | + } |
| 129 | + |
| 130 | +@NotNull |
| 131 | +@Override |
| 132 | +publicStringcall(finalStringaddress,finalStringdata) { |
| 133 | +BasicUtils.validateAddress(address); |
| 134 | + |
| 135 | +finalStringurlParams =ACT_CALL_PARAM +TO_PARAM +address +DATA_PARAM +data +TAG_LAST_PARAM; |
| 136 | +finalStringProxyTOresponse =getRequest(urlParams,StringProxyTO.class); |
| 137 | +return (BasicUtils.isEmpty(response.getResult())) |
| 138 | + ?"" |
| 139 | + :response.getResult(); |
| 140 | + } |
| 141 | + |
| 142 | +@NotNull |
| 143 | +@Override |
| 144 | +publicStringcode(finalStringaddress) { |
| 145 | +BasicUtils.validateAddress(address); |
| 146 | + |
| 147 | +finalStringurlParams =ACT_CODE_PARAM +ADDRESS_PARAM +address +TAG_LAST_PARAM; |
| 148 | +finalStringProxyTOresponse =getRequest(urlParams,StringProxyTO.class); |
| 149 | +return (BasicUtils.isEmpty(response.getResult())) |
| 150 | + ?"" |
| 151 | + :response.getResult(); |
| 152 | + } |
| 153 | + |
| 154 | +@NotNull |
| 155 | +@Override |
| 156 | +publicStringstorageAt(finalStringaddress,finallongposition) { |
| 157 | +BasicUtils.validateAddress(address); |
| 158 | +finallongcompPosition =BasicUtils.compensateMinBlock(position); |
| 159 | + |
| 160 | +finalStringurlParams =ACT_STORAGEAT_PARAM +ADDRESS_PARAM +address +POSITION_PARAM +compPosition +TAG_LAST_PARAM; |
| 161 | +finalStringProxyTOresponse =getRequest(urlParams,StringProxyTO.class); |
| 162 | +return (BasicUtils.isEmpty(response.getResult())) |
| 163 | + ?"" |
| 164 | + :response.getResult(); |
| 165 | + } |
| 166 | + |
| 167 | +@NotNull |
| 168 | +@Override |
| 169 | +publicBigIntegergasPrice() { |
| 170 | +finalStringProxyTOresponse =getRequest(ACT_GASPRICE_PARAM,StringProxyTO.class); |
| 171 | +return (BasicUtils.isEmpty(response.getResult())) |
| 172 | + ?BigInteger.valueOf(-1) |
| 173 | + :BigInteger.valueOf(BasicUtils.parseHex(response.getResult())); |
| 174 | + } |
| 175 | + |
| 176 | +@NotNull |
| 177 | +@Override |
| 178 | +publicBigIntegergasEstimated() { |
| 179 | +finalStringurlParams =ACT_STORAGEAT_PARAM +VALUE_PARAM +"0xff22" |
| 180 | + +GAS_PARAM +"0xffffff" +GASPRICE_PARAM +"0x151da038cc"; |
| 181 | +finalStringProxyTOresponse =getRequest(urlParams,StringProxyTO.class); |
| 182 | +return (BasicUtils.isEmpty(response.getResult())) |
| 183 | + ?BigInteger.valueOf(-1) |
| 184 | + :BigInteger.valueOf(BasicUtils.parseHex(response.getResult())); |
| 185 | + } |
| 186 | +} |