|
| 1 | +from BlockSDK.base import Base |
| 2 | +class Klaytn(Base): |
| 3 | + def getBlockChain(self, request = {}): |
| 4 | + return self.request("GET","/klay/info") |
| 5 | + |
| 6 | + def getBlock(self, request = {}): |
| 7 | + if not('rawtx' in request) or not request['rawtx']: |
| 8 | + request['rawtx'] = False |
| 9 | + if not('offset' in request) or not request['offset']: |
| 10 | + request['offset'] = 0 |
| 11 | + if not('limit' in request) or not request['limit']: |
| 12 | + request['limit'] = 10 |
| 13 | + |
| 14 | + return self.request("GET","/klay/blocks/" + str(request['block']),{"rawtx" : request['rawtx'],"offset": request['offset'],"limit" : request['limit']}) |
| 15 | + |
| 16 | + def getMemPool(self, request = {}): |
| 17 | + if not('rawtx' in request) or not request['rawtx']: |
| 18 | + request['rawtx'] = False |
| 19 | + if not('offset' in request) or not request['offset']: |
| 20 | + request['offset'] = 0 |
| 21 | + if not('limit' in request) or not request['limit']: |
| 22 | + request['limit'] = 10 |
| 23 | + |
| 24 | + return self.request("GET","/klay/mempool",{"rawtx" : request['rawtx'],"offset" : request['offset'],"limit" : request['limit']}) |
| 25 | + |
| 26 | + |
| 27 | + def getAddresses(self, request = {}): |
| 28 | + if not('offset' in request) or not request['offset']: |
| 29 | + request['offset'] = 0 |
| 30 | + if not('limit' in request) or not request['limit']: |
| 31 | + request['limit'] = 10 |
| 32 | + |
| 33 | + return self.request("GET","/klay/addresses",{ |
| 34 | + "offset" : request['offset'], |
| 35 | + "limit" : request['limit'] |
| 36 | + }) |
| 37 | + |
| 38 | + def loadAddress(self, request = {}): |
| 39 | + return self.request("POST","/klay/addresses/" + request['address'] + "/load",{"private_key" : request['private_key'],"password" : request['password']}) |
| 40 | + |
| 41 | + def unloadAddress(self, request = {}): |
| 42 | + return self.request("POST","/klay/addresses/" + request['address'] + "/unload") |
| 43 | + |
| 44 | + def createAddress(self, request = {}): |
| 45 | + if not('name' in request) or not request['name']: |
| 46 | + request['name'] = None |
| 47 | + return self.request("POST","/klay/addresses",{"name" : request['name']}) |
| 48 | + |
| 49 | + |
| 50 | + def getAddressInfo(self, request = {}): |
| 51 | + |
| 52 | + if not('reverse' in request) or not request['reverse']: |
| 53 | + request['reverse'] = True |
| 54 | + if not('rawtx' in request) or not request['rawtx']: |
| 55 | + request['rawtx'] = None |
| 56 | + if not('offset' in request) or not request['offset']: |
| 57 | + request['offset'] = 0 |
| 58 | + if not('limit' in request) or not request['limit']: |
| 59 | + request['limit'] = 10 |
| 60 | + |
| 61 | + return self.request("GET","/klay/addresses/" + request['address'],{"reverse" : request['reverse'],"rawtx" : request['rawtx'],"offset" : request['offset'],"limit" : request['limit']}) |
| 62 | + |
| 63 | + |
| 64 | + def getAddressBalance(self, request = {}): |
| 65 | + return self.request("GET","/klay/addresses/" + request['address'] + "/balance") |
| 66 | + |
| 67 | + def sendToAddress(self, request = {}): |
| 68 | + if not('nonce' in request) or not request['nonce']: |
| 69 | + request['nonce'] = None |
| 70 | + if not('data' in request) or not request['data']: |
| 71 | + request['data'] = None |
| 72 | + if not('private_key' in request) or not request['private_key']: |
| 73 | + request['private_key'] = None |
| 74 | + if not('password' in request) or not request['password']: |
| 75 | + request['password'] = None |
| 76 | + if not('gas_limit' in request) or not request['gas_limit']: |
| 77 | + request['gas_limit'] = None |
| 78 | + |
| 79 | + return self.request("POST","/klay/addresses/" + request['from'] + "/sendtoaddress",{ |
| 80 | + "to" : request['to'], |
| 81 | + "amount" : request['amount'], |
| 82 | + "private_key" : request['private_key'], |
| 83 | + "password" : request['password'], |
| 84 | + "gas_limit" : request['gas_limit'] |
| 85 | + }) |
| 86 | + |
| 87 | + |
| 88 | + def sendTransaction(self, request = {}): |
| 89 | + return self.request("POST","/klay/transactions/send",{ |
| 90 | + "hex" : request['hex'] |
| 91 | + }) |
| 92 | + |
| 93 | + def getTransaction(self, request = {}): |
| 94 | + return self.request("GET","/klay/transactions/" + request['hash']) |
| 95 | + |
| 96 | + def getKIP7(self, request = {}): |
| 97 | + return self.request("GET","/klay/kip7-tokens/" + request['contract_address']) |
| 98 | + |
| 99 | + def getKIP7Balance(self, request = {}): |
| 100 | + return self.request("GET","/klay/kip7-tokens/" + request['contract_address'] + "/" + request['from'] + "/balance") |
| 101 | + |
| 102 | + def getKIP7Transfer(self, request = {}): |
| 103 | + if not('private_key' in request) or not request['private_key']: |
| 104 | + request['private_key'] = None |
| 105 | + if not('password' in request) or not request['password']: |
| 106 | + request['password'] = None |
| 107 | + if not('gas_limit' in request) or not request['gas_limit']: |
| 108 | + request['gas_limit'] = None |
| 109 | + |
| 110 | + return self.request("POST","/klay/kip7-tokens/" + request['contract_address'] + "/" + request['from'] + "/transfer",{ |
| 111 | + "to" : request['to'], |
| 112 | + "amount" : request['amount'], |
| 113 | + "private_key" : request['private_key'], |
| 114 | + "password" : request['password'], |
| 115 | + "gas_limit" : request['gas_limit'] |
| 116 | + }) |
| 117 | + |
| 118 | + def getKIP7Sign(self, request = {}): |
| 119 | + if not('private_key' in request) or not request['private_key']: |
| 120 | + request['private_key'] = None |
| 121 | + if not('password' in request) or not request['password']: |
| 122 | + request['password'] = None |
| 123 | + if not('gas_limit' in request) or not request['gas_limit']: |
| 124 | + request['gas_limit'] = None |
| 125 | + |
| 126 | + return self.request("POST","/klay/kip7-tokens/" + request['contract_address'] + "/" + request['from'] + "/sign",{ |
| 127 | + "to" : request['to'], |
| 128 | + "amount" : request['amount'], |
| 129 | + "private_key" : request['private_key'], |
| 130 | + "password" : request['password'], |
| 131 | + "gas_limit" : request['gas_limit'] |
| 132 | + }) |
| 133 | + |
| 134 | + def getKIP7Feedelegated(self, request = {}): |
| 135 | + if not('private_key' in request) or not request['private_key']: |
| 136 | + request['private_key'] = None |
| 137 | + if not('password' in request) or not request['password']: |
| 138 | + request['password'] = None |
| 139 | + if not('gas_limit' in request) or not request['gas_limit']: |
| 140 | + request['gas_limit'] = None |
| 141 | + |
| 142 | + return self.request("POST","/klay/kip7-tokens/" + request['contract_address'] + "/" + request['fee_payer'] + "/transfer/feedelegated",{ |
| 143 | + "from" : request['from'], |
| 144 | + "to" : request['to'], |
| 145 | + "amount" : request['amount'], |
| 146 | + "private_key" : request['private_key'], |
| 147 | + "password" : request['password'], |
| 148 | + "gwei" : request['gwei'], |
| 149 | + "gas_limit" : request['gas_limit'], |
| 150 | + "nonce" : request['nonce'], |
| 151 | + "v" : request['v'], |
| 152 | + "r" : request['r'], |
| 153 | + "s" : request['s'] |
| 154 | + }) |
| 155 | + |
| 156 | + def getNfts(self, request = {}): |
| 157 | + if not('offset' in request) or not request['offset']: |
| 158 | + request['offset'] = 0 |
| 159 | + if not('limit' in request) or not request['limit']: |
| 160 | + request['limit'] = 10 |
| 161 | + |
| 162 | + return self.request("GET","/klay/kip17-tokens/" + request['contract_address'] + "/tokens",{ |
| 163 | + "offset" : request['offset'], |
| 164 | + "limit" : request['limit'] |
| 165 | + }) |
| 166 | + |
| 167 | + def getOwnerNfts(self, request = {}): |
| 168 | + if not('offset' in request) or not request['offset']: |
| 169 | + request['offset'] = 0 |
| 170 | + if not('limit' in request) or not request['limit']: |
| 171 | + request['limit'] = 10 |
| 172 | + |
| 173 | + return self.request("GET","/klay/kip17-tokens/" + request['contract_address'] + "/" + request['owner_address'] + "/owner",{ |
| 174 | + "offset" : request['offset'], |
| 175 | + "limit" : request['limit'] |
| 176 | + }) |
| 177 | + |
| 178 | + def getCreatorNfts(self, request = {}): |
| 179 | + if not('offset' in request) or not request['offset']: |
| 180 | + request['offset'] = 0 |
| 181 | + if not('limit' in request) or not request['limit']: |
| 182 | + request['limit'] = 10 |
| 183 | + |
| 184 | + return self.request("GET","/klay/kip17-tokens/" + request['contract_address'] + "/" + request['creator_address'] + "/creator",{ |
| 185 | + "offset" : request['offset'], |
| 186 | + "limit" : request['limit'] |
| 187 | + }) |
| 188 | + |
| 189 | + def getAuctionNfts(self, request = {}): |
| 190 | + if not('order_by' in request) or not request['order_by']: |
| 191 | + request['order_by'] = 'end_time' |
| 192 | + if not('order_direction' in request) or not request['order_direction']: |
| 193 | + request['order_direction'] = 'desc' |
| 194 | + if not('offset' in request) or not request['offset']: |
| 195 | + request['offset'] = 0 |
| 196 | + if not('limit' in request) or not request['limit']: |
| 197 | + request['limit'] = 10 |
| 198 | + |
| 199 | + return self.request("GET","/klay/kip17-tokens/" + request['contract_address'] + "/auction",{ |
| 200 | + "order_by" : request['order_by'], |
| 201 | + "order_direction" : request['order_direction'], |
| 202 | + "offset" : request['offset'], |
| 203 | + "limit" : request['limit'] |
| 204 | + }) |
| 205 | + |
| 206 | + def getSaleNfts(self, request = {}): |
| 207 | + if not('order_direction' in request) or not request['order_direction']: |
| 208 | + request['order_direction'] = 'desc' |
| 209 | + if not('offset' in request) or not request['offset']: |
| 210 | + request['offset'] = 0 |
| 211 | + if not('limit' in request) or not request['limit']: |
| 212 | + request['limit'] = 10 |
| 213 | + |
| 214 | + return self.request("GET","/klay/kip17-tokens/" + request['contract_address'] + "/" + request['seller_address'] + "/sale",{ |
| 215 | + "order_direction" : request['order_direction'], |
| 216 | + "offset" : request['offset'], |
| 217 | + "limit" : request['limit'] |
| 218 | + }) |
| 219 | + |
| 220 | + def getNftBids(self, request = {}): |
| 221 | + if not('rawtx' in request) or not request['rawtx']: |
| 222 | + request['rawtx'] = 0 |
| 223 | + if not('order_direction' in request) or not request['order_direction']: |
| 224 | + request['order_direction'] = 'desc' |
| 225 | + if not('offset' in request) or not request['offset']: |
| 226 | + request['offset'] = 0 |
| 227 | + if not('limit' in request) or not request['limit']: |
| 228 | + request['limit'] = 10 |
| 229 | + |
| 230 | + return self.request("GET","/klay/kip17-tokens/" + request['contract_address'] + "/" + request['token_id'] + "/bid",{ |
| 231 | + "order_direction" : request['order_direction'], |
| 232 | + "rawtx" : request['rawtx'], |
| 233 | + "offset" : request['offset'], |
| 234 | + "limit" : request['limit'] |
| 235 | + }) |
| 236 | + |
| 237 | + def getNftInfo(self, request = {}): |
| 238 | + return self.request("GET","/klay/kip17-tokens/" + request['contract_address'] + "/" + request['token_id'] + "/info") |
| 239 | + |
| 240 | + def getNftTransfers(self, request = {}): |
| 241 | + if not('rawtx' in request) or not request['rawtx']: |
| 242 | + request['rawtx'] = 0 |
| 243 | + if not('offset' in request) or not request['offset']: |
| 244 | + request['offset'] = 0 |
| 245 | + if not('limit' in request) or not request['limit']: |
| 246 | + request['limit'] = 10 |
| 247 | + |
| 248 | + return self.request("GET","/klay/kip17-tokens/" + request['contract_address'] + "/" + request['token_id'] + "/transfers",{ |
| 249 | + "rawtx" : request['rawtx'], |
| 250 | + "offset" : request['offset'], |
| 251 | + "limit" : request['limit'] |
| 252 | + }) |
| 253 | + |
| 254 | + def getContractRead(self, request = {}): |
| 255 | + if not('parameter_type' in request) or not request['parameter_type']: |
| 256 | + request['parameter_type'] = None |
| 257 | + if not('parameter_data' in request) or not request['parameter_data']: |
| 258 | + request['parameter_data'] = None |
| 259 | + |
| 260 | + |
| 261 | + return self.request("POST","/klay/contracts/" + request['contract_address'] + "/read",{ |
| 262 | + "method" : request['method'], |
| 263 | + "return_type" : request['return_type'], |
| 264 | + "parameter_type" : request['parameter_type'], |
| 265 | + "parameter_data" : request['parameter_data'] |
| 266 | + }) |
| 267 | + |
| 268 | + def getContractWrite(self, request = {}): |
| 269 | + if not('private_key' in request) or not request['private_key']: |
| 270 | + request['private_key'] = None |
| 271 | + if not('password' in request) or not request['password']: |
| 272 | + request['password'] = None |
| 273 | + if not('gas_limit' in request) or not request['gas_limit']: |
| 274 | + request['gas_limit'] = None |
| 275 | + |
| 276 | + if not('parameter_type' in request) or not request['parameter_type']: |
| 277 | + request['parameter_type'] = None |
| 278 | + if not('parameter_data' in request) or not request['parameter_data']: |
| 279 | + request['parameter_data'] = None |
| 280 | + |
| 281 | + |
| 282 | + return self.request("POST","/klay/contracts/" + request['contract_address'] + "/write",{ |
| 283 | + "method" : request['method'], |
| 284 | + "return_type" : request['return_type'], |
| 285 | + "parameter_type" : request['parameter_type'], |
| 286 | + "parameter_data" : request['parameter_data'], |
| 287 | + "from" : request['from'], |
| 288 | + "private_key" : request['private_key'], |
| 289 | + "password" : request['password'], |
| 290 | + "amount" : request['amount'], |
| 291 | + "gas_limit" : request['gas_limit'] |
| 292 | + }) |
| 293 | + |
| 294 | + def getContractWriteSign(self, request = {}): |
| 295 | + if not('private_key' in request) or not request['private_key']: |
| 296 | + request['private_key'] = None |
| 297 | + if not('password' in request) or not request['password']: |
| 298 | + request['password'] = None |
| 299 | + if not('gas_limit' in request) or not request['gas_limit']: |
| 300 | + request['gas_limit'] = None |
| 301 | + |
| 302 | + if not('parameter_type' in request) or not request['parameter_type']: |
| 303 | + request['parameter_type'] = None |
| 304 | + if not('parameter_data' in request) or not request['parameter_data']: |
| 305 | + request['parameter_data'] = None |
| 306 | + |
| 307 | + |
| 308 | + return self.request("POST","/klay/contracts/" + request['contract_address'] + "/write/sign",{ |
| 309 | + "method" : request['method'], |
| 310 | + "return_type" : request['return_type'], |
| 311 | + "parameter_type" : request['parameter_type'], |
| 312 | + "parameter_data" : request['parameter_data'], |
| 313 | + "from" : request['from'], |
| 314 | + "private_key" : request['private_key'], |
| 315 | + "password" : request['password'], |
| 316 | + "amount" : request['amount'], |
| 317 | + "gas_limit" : request['gas_limit'] |
| 318 | + }) |
| 319 | + |
| 320 | + def getContractWriteFeedelegated(self, request = {}): |
| 321 | + if not('private_key' in request) or not request['private_key']: |
| 322 | + request['private_key'] = None |
| 323 | + if not('password' in request) or not request['password']: |
| 324 | + request['password'] = None |
| 325 | + if not('gas_limit' in request) or not request['gas_limit']: |
| 326 | + request['gas_limit'] = None |
| 327 | + |
| 328 | + if not('parameter_type' in request) or not request['parameter_type']: |
| 329 | + request['parameter_type'] = None |
| 330 | + if not('parameter_data' in request) or not request['parameter_data']: |
| 331 | + request['parameter_data'] = None |
| 332 | + |
| 333 | + |
| 334 | + return self.request("POST","/klay/contracts/" + request['contract_address'] + "/write/feedelegated",{ |
| 335 | + "method" : request['method'], |
| 336 | + "return_type" : request['return_type'], |
| 337 | + "parameter_type" : request['parameter_type'], |
| 338 | + "parameter_data" : request['parameter_data'], |
| 339 | + "from" : request['from'], |
| 340 | + "fee_payer" : request['fee_payer'], |
| 341 | + "private_key" : request['private_key'], |
| 342 | + "password" : request['password'], |
| 343 | + "amount" : request['amount'], |
| 344 | + "gwei" : request['gwei'], |
| 345 | + "gas_limit" : request['gas_limit'] |
| 346 | + }) |
| 347 | + |
| 348 | + def getContractWriteFees(self, request = {}): |
| 349 | + if not('gas_limit' in request) or not request['gas_limit']: |
| 350 | + request['gas_limit'] = None |
| 351 | + |
| 352 | + if not('parameter_type' in request) or not request['parameter_type']: |
| 353 | + request['parameter_type'] = None |
| 354 | + if not('parameter_data' in request) or not request['parameter_data']: |
| 355 | + request['parameter_data'] = None |
| 356 | + |
| 357 | + |
| 358 | + return self.request("POST","/klay/contracts/" + request['contract_address'] + "/write/fees",{ |
| 359 | + "method" : request['method'], |
| 360 | + "return_type" : request['return_type'], |
| 361 | + "parameter_type" : request['parameter_type'], |
| 362 | + "parameter_data" : request['parameter_data'], |
| 363 | + "from" : request['from'], |
| 364 | + "amount" : request['amount'], |
| 365 | + "gas_limit" : request['gas_limit'] |
| 366 | + }) |
0 commit comments