Skip to content

Commit

Permalink
V3 버전 업데이트
Browse files Browse the repository at this point in the history
  • Loading branch information
liw committed Sep 13, 2023
1 parent b266bc4 commit 82cb32c
Show file tree
Hide file tree
Showing 26 changed files with 3,540 additions and 2,305 deletions.
456 changes: 456 additions & 0 deletions Avalanche SDK.md

Large diffs are not rendered by default.

455 changes: 455 additions & 0 deletions BinanceSmart SDK.md

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions BlockSDK/avalanche.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
from BlockSDK.base import Base


class Avalanche(Base):
def GetBlockChainInfo(self):
return self.request("GET", f"/avax/info")

def GetBlock(self, request):
return self.request("GET", f"/avax/block/{request.get('block', '')}", request)

def GetAddresses(self, request):
return self.request("GET", f"/avax/address", request)

def CreateAddress(self, request):
return self.request("POST", f"/avax/address", request)

def GetAddressInfo(self, request):
return self.request("GET", f"/avax/address/{request.get('address', '')}/info", request)

def GetAddressBalance(self, request):
return self.request("GET", f"/avax/address/{request.get('address', '')}/balance")

def Send(self, request):
return self.request("POST", f"/avax/address/{request.get('from', '')}/send", request)

def SendTransaction(self, request):
return self.request("POST", f"/avax/transaction/send", request)

def GetTransaction(self, request):
return self.request("GET", f"/avax/transaction/{request.get('hash', '')}")

def GetTokenInfo(self, request):
return self.request("GET", f"/avax/token/{request.get('contract_address', '')}/info")

def SendToken(self, request):
return self.request("POST", f"/avax/token/{request.get('contract_address', '')}/{request.get('from', '')}/transfer", request)

def GetTokenBalance(self, request):
return self.request("GET", f"/avax/token/{request.get('contract_address', '')}/{request.get('from', '')}/balance")

def GetTokenTxs(self, request):
return self.request("GET", f"/avax/token/{request.get('from_address', '')}/transactions", request)

def GetTokenContractTxs(self, request):
return self.request("GET", f"/avax/token/{request.get('contract_address', '')}/{request.get('from_address', '')}/transactions", request)

def GetTokenAllBalance(self, request):
return self.request("GET", f"/avax/token/{request.get('from_address', '')}/all-balance", request)

def GetSingleNfts(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('contract_address', '')}/nfts", request)

def GetSingleOwnerNfts(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('owner_address', '')}/owner-nfts", request)

def GetSingleCreatorNfts(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('creator_address', '')}/creator-nfts", request)

def GetSingleTxs(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('from_address', '')}/transactions", request)

def GetSingleNftOwnerNfts(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('contract_address', '')}/{request.get('owner_address', '')}/owner-nfts", request)

def GetSingleNftCreatorNfts(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('contract_address', '')}/{request.get('creator_address', '')}/creator-nfts", request)

def GetSingleNftTxs(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('contract_address', '')}/{request.get('from_address', '')}/from-transactions", request)

def GetSingleNftInfo(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('contract_address', '')}/{request.get('token_id', '')}/info", request)

def GetSingleNftTokenTxs(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('contract_address', '')}/{request.get('token_id', '')}/nft-transactions", request)

def GetSingleNftAuctionNfts(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('contract_address', '')}/auction-nfts", request)

def GetSingleNftSellerNfts(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('contract_address', '')}/{request.get('seller_address', '')}/seller-nfts", request)

def GetSingleNftTokenBids(self, request):
return self.request("GET", f"/avax/single-nft/{request.get('contract_address', '')}/{request.get('token_id', '')}/nft-bids", request)

def GetMultiNfts(self, request):
return self.request("GET", f"/avax/multi-nft/{request.get('contract_address', '')}/nfts", request)

def GetMultiOwnerNfts(self, request):
return self.request("GET", f"/avax/multi-nft/{request.get('owner_address', '')}/owner-nfts", request)

def GetMultiCreatorNfts(self, request):
return self.request("GET", f"/avax/multi-nft/{request.get('creator_address', '')}/creator-nfts", request)

def GetMultiTxs(self, request):
return self.request("GET", f"/avax/multi-nft/{request.get('from_address', '')}/transactions", request)

def GetMultiNftOwnerNfts(self, request):
return self.request("GET", f"/avax/multi-nft/{request.get('contract_address', '')}/{request.get('owner_address', '')}/owner-nfts", request)

def GetMultiNftCreatorNfts(self, request):
return self.request("GET", f"/avax/multi-nft/{request.get('contract_address', '')}/{request.get('creator_address', '')}/creator-nfts", request)

def GetMultiNftTxs(self, request):
return self.request("GET", f"/avax/multi-nft/{request.get('contract_address', '')}/{request.get('from_address', '')}/from-transactions", request)

def GetMultiNftInfo(self, request):
return self.request("GET", f"/avax/multi-nft/{request.get('contract_address', '')}/{request.get('token_id', '')}/info", request)

def GetMultiNftTokenTxs(self, request):
return self.request("GET", f"/avax/multi-nft/{request.get('contract_address', '')}/{request.get('token_id', '')}/nft-transactions", request)

def GetMultiNftSellerNfts(self, request):
return self.request("GET", f"/avax/multi-nft/{request.get('contract_address', '')}/{request.get('seller_address', '')}/seller-nfts", request)

def ReadContract(self, request):
return self.request("POST", f"/avax/contract/{request.get('contract_address', '')}/read", request)

def WriteContract(self, request):
return self.request("POST", f"/avax/contract/{request.get('contract_address', '')}/write", request)
93 changes: 30 additions & 63 deletions BlockSDK/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,38 @@
import json

class Base:
def __init__(self, api_token):
self.api_token = api_token
def __init__(self, api_token, endpoint="https://testnet-api.blocksdk.com"):
self.api_token = api_token
self.endpoint = endpoint

def request(self,method,path,data = {}):
url = "https://api.blocksdk.com/v2" + path
def request(self, method, path, data = {}):
url = f"{self.endpoint}/v3{path}"

if method == "GET" and len(data) > 0:
url += "?"
for key in data.keys():
value = data[key];
if value == True:
url += key + "=true&"
elif value == False:
url += key + "=false&"
else:
url += key+ "=" + str(value) + "&"

if method == "POST":
response = requests.post(url = url, json = data, headers = { 'Content-Type': 'application/json','x-api-key': self.api_token})
else:
response = requests.get(url = url, headers = { 'Content-Type': 'application/json','x-api-key': self.api_token})

try:
body = response.json()
except:
body = {}

if method == "POST":
try:
body = json.loads(response.text)
except:
converted_json = response.text.replace(':','":')
converted_json1 = converted_json.split('{\n')
for i in range(len(converted_json1)):
if converted_json1[i] != '':
json2 = converted_json1[i].split('":')[0].split(' ')[-1]
converted_json = converted_json.replace(json2,'"' + json2)
body = json.loads(converted_json)

if response.headers:
headers = response.headers
else:
headers = {}

if response.status_code:
status = response.status_code
else:
status = 0

headers.update({'statusCode' : status})
try:
body.update({'HTTP_HEADER': headers})
except:
body = { i : body[i] for i in range(0, len(body) ) }
body.update({'HTTP_HEADER': headers})

#result_row = body['HTTP_HEADER'];
# for key in result_row.keys():
# if not result_row[key]:
# if key == "statusCode":
# result_row[key] = 0
#body['HTTP_HEADER'] = result_row;

return body
headers = {
'x-api-token': self.api_token
}

baseInstance = Base('B1zZARyW1d2FdqWxPUpB79izHmtAc2Az693WF9DD')
try:
if method == "GET":
params = "&".join([f"{key}={value}" for key, value in data.items()])
full_url = f"{url}?{params}"
response = requests.get(full_url, headers=headers)

elif method == "POST":
headers['Content-Type'] = 'application/json'
response = requests.post(url, json=data, headers=headers)

if response.status_code == 200:
payload = response.json().get('payload', {})
payload['requestData'] = data
return payload
else:
print(f"Error: {response.status_code}")
return False

except Exception as e:
print(url)
print(e)
return False
#print(baseInstance.getUsage({'start_date': '','end_date': ''}))
# print(baseInstance.getHashType({'hash':'000000000000000089d2938df30be807844feea4c3340ad32873bb1b692b7f1a'}))
Loading

0 comments on commit 82cb32c

Please sign in to comment.