-
[Intern] 해시값 조회 안되는 체인 데이터 조회되도록 구현 / Moralis api 데이터 log분석Intern/Project 2024. 12. 8. 19:36
✏ 근무 내용
- 해시값 조회 안되는 체인 데이터 조회되도록 구현
- log분석
⭐근무 결과
- Moralis api 연동하여 hash값과 체인 종류 정보 넣었을 때 트랜잭션 데이터만 조회되게 구현 (프론트 연동x 데이터 확인용)
//-- api.controller.ts 코드 //해시값과 체인값 넣어 체인 데이터 조회 @Get('/transaction') async getTransactionDetails( @Query('transactionHash') transactionHash: string, @Query('chain') chain: string ) { try { return await this.apiService.getTransactionDetails(transactionHash, chain); } catch (error) { throw new HttpException( { success: false, message: error.message, error: error.stack, }, HttpStatus.BAD_REQUEST ); } }
//-- api.service.ts 코드 // 해시값과 체인종류 넣어 체인 데이터 전체 조회 async getTransactionDetails(transactionHash: string, chain: string) { try { const response = await Moralis.EvmApi.transaction.getTransaction({ chain: chain, transactionHash: transactionHash, }); return response.raw; } catch (error) { console.error(error); throw new Error("Transaction details retrieval failed."); } }
- 체인 정보 안넣고 해시값만 넣었을 때 데이터 조회되게 하기
문제점 : 체인 정보를 안넣은 상태로 url 조회했을 때 데이터 조회 가능한건 출발 체인이 이더리움일 때(기본 체인으로 설정되어 있기에 가능)만 가능하고 나머지는 불가능합니다.
출발체인이 arbitrum, base 일때도 체인정보를 안넣고 해시값만으로 조회가 가능하도록 해야합니다
해결 방법 : 아래 코드처럼 체인 종류에 대한 id값은 따로 저장해두고, 만약 그 체인값에 대한 데이터가 조회가 된다면 그 체인 id 값을 moralis api에 기존해시값과 같이 파라미터로 넣어 반환하면 판별 가능합니다.
// 트랜잭션 해시값만 넣어 출발 체인 종류 판별 async getTransactionChain(transactionHash: string): Promise<string | null> { const chainMapping: { [key: string]: string } = { "0x1": "Ethereum", "0x2105": "Base", "0xa4b1": "Arbitrum", }; const chains = ["0x1", "0x2105", "0xa4b1"]; // 검사할 체인 리스트 for (const chainId of chains) { try { const response = await Moralis.EvmApi.transaction.getTransaction({ chain: chainId, transactionHash, }); if (response?.raw) { // chainMapping에서 해당 체인 ID에 맞는 체인 이름 반환 return chainMapping[chainId] || null; } } catch (error) { console.error(`Transaction not found on chain ${chainMapping[chainId]}.`); } } return null; // 어떤 체인에서도 트랜잭션을 찾지 못한 경우 }
⭕moralis api로 조회 되는 데이터들
: 출발,도착 체인 주소값 / 출발 시간
❌moralis api로 조회 안되는 데이터들
: 도착체인 해시값 / 도착시간 / 가치 : 보낸 토큰과 받는 토큰의 양 ( 100 WNCG Sent to LayerZero)
아래와 같이 토큰의 양도 moralis api 데이터로 조회 가능하지만 정확하지는 않다. 다른 케이스들을 테스트 안해봄
1. 보낸 토큰의 양
- 관련 로그: log_index가 5, 8 등인 경우.
- topic0: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef (Transfer 이벤트).
- data: 전송된 토큰의 양을 포함.
json 코드 복사 { "log_index": "8", "data": "0x00000000000000000000000000000000000000000000c01e582c38efc5eeee34", "topic0": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "topic1": "0x0000000000000000000000005f5089bf60924e8ad4c426fceaeffa3475c202dc", "topic2": "0x0000000000000000000000003a23f943181408eac424116af7b7790c94cb97a5" }
- data 값: 0x00000000000000000000000000000000000000000000c01e582c38efc5eeee34
- 마지막 16진수 부분(c01e582c38efc5eeee34)이 전송된 토큰의 양.
- 이를 10진수로 변환하면 약 10.89 (단위: USDC)임.
- data 값: 0x00000000000000000000000000000000000000000000c01e582c38efc5eeee34
- 예를 들어:
2. 받은 토큰의 양
- 관련 로그: log_index가 25, 26 등인 경우.
- topic0: 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef (Transfer 이벤트).
- data: 수령된 토큰의 양을 포함.
json 코드 복사 { "log_index": "25", "data": "0x000000000000000000000000000000000000000000000000000000000068422c", "topic0": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "topic1": "0x0000000000000000000000003a23f943181408eac424116af7b7790c94cb97a5", "topic2": "0x000000000000000000000000c91e5068968acaec9c8e7c056390d9e3cb34f7fc" }
- data 값: 0x000000000000000000000000000000000000000000000000000000000068422c
- 마지막 16진수 부분(68422c)이 수령된 토큰의 양.
- 이를 10진수로 변환하면 약 10.89 (단위: USDC)임.
- data 값: 0x000000000000000000000000000000000000000000000000000000000068422c
- 예를 들어:
3. 결론
- 보낸 토큰: 약 10.89 USDC.
- 받은 토큰: 약 10.89 USDC.
반응형'Intern > Project' 카테고리의 다른 글
[Intern] Moralis api 데이터 검증 / 대체 api 찾기 (0) 2024.12.09 [Intern] Moralis api로 조회 안되는 데이터들 조회되도록 구현 (토큰의 양) (0) 2024.12.08 [Intern] 로컬 401 에러 해결 / hash로 sender, destination 정보 불러오기 / moralis api 연결 (0) 2024.12.08 [Intern] Moralis API document 호출 확인 / 맥 환경 AWS 배포 (0) 2024.12.07 [Intern] CCTP 조회 가능한 API 찾기 (0) 2024.12.05