반응형
기본 구문
import requests
import json
import cbor
# Filecoin 노드 RPC endpoint URL
node_url = 'https://api.node.glif.io'
def json_request(method,cid):
# JSON RPC 요청 메시지 구성
rpc_request = {
"jsonrpc": "2.0",
"id": 0,
"method": f"Filecoin.{method}",
"params": [{"/":cid},]
}
return rpc_request
def get_response(method,cid):
# JSON RPC 요청 보내기
response = requests.post(node_url, json=json_request(method,cid))
# JSON RPC 응답 처리
if response.status_code == 200:
rpc_response = json.loads(response.content)
return rpc_response
else:
print("Error: HTTP status code", response.status_code)
return None
- 지정된 Block의 Parent Message 내 존재하는 method 및 amount 수집
cid = "bafy2bzacechvfkkjvjy3xfxntec2u4qgwr4ldcbedbpzw4w3d7tkdruwrqorw"
message_result = get_response("ChainGetParentMessages",cid)
print(message_result)
try:
if(message_result):
for message in message_result["result"]:
amount = message["Message"]["Value"]
method = message["Message"]["Method"]
print(message["Message"]["CID"],method, amount)
except:
pass
- 메시지 내 데이터 확인
cid = "bafy2bzacedusu7ogm7roemoyuqdcqol3b7mn6txndcc27plvx7tb5knwxytou" # propose
# cid = "bafy2bzaceatjsbldoavngt5bb2coducplofg4e7xrtcrj33ufdzodrbufa3ce" # approve
message_result = get_response("ChainGetMessage",cid)
if(message_result):
message = message_result["result"]
method = message["Method"]
if(method==0): # Method is Send
print(message)
elif(method==2): # Method is Propose (Multisig Wallet)
cbor_data = cbor.loads(base64.b64decode(message['Params']))
print(message)
to = cbor_data[0]
value = int("0x"+cbor_data[1].hex(),16)
p_method = cbor_data[2]
p_params = cbor_data[3]
print(f"Params : To : {to}, Value : {value}, method : {p_method}, params : {p_params}")
elif(method==3): # Method is Approve
print(message)
cbor_data = cbor.loads(base64.b64decode(message['Params']))
print(f"params : {cbor_data}")
참고 문서
'Hack > Cryptocurrency' 카테고리의 다른 글
[DAO Hacking] Reentrancy Attack 실제 사례 분석 (0) | 2023.04.30 |
---|---|
Reentrancy Attack in Smart Contract (0) | 2023.04.29 |
Python Web3를 통한 FNCY RPC 통신하기 (0) | 2023.03.13 |
Avalanche(AVAX) RPC 사용 방법 (0) | 2023.02.19 |
Hash, Salt, Pepper (0) | 2022.09.06 |
댓글