package com.izouma.nineth;

import com.alibaba.fastjson.JSON;
import com.alipay.mychain.sdk.domain.transaction.LogEntry;
import com.antfinancial.mychain.baas.tool.restclient.RestClient;
import com.antfinancial.mychain.baas.tool.restclient.model.Method;
import com.antfinancial.mychain.baas.tool.restclient.model.ReceiptDecoration;
import com.antfinancial.mychain.baas.tool.restclient.response.BaseResp;
import com.izouma.nineth.utils.HashUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

public class AntChainTest extends ApplicationTests {
    @Autowired
    private RestClient restClient;

    @Test
    public void testQuery() throws Exception {
        BaseResp queryBaseResp = restClient.chainCall("0xc819a128fa96a71ad6825c2048e2af9dc0ade762bf60e80e83ee3d9e0e1e5b03", "", "", Method.QUERYRECEIPT);
        ReceiptDecoration transaction = JSON.parseObject(queryBaseResp.getData(), ReceiptDecoration.class);
        for (LogEntry log : transaction.getLogs()) {
            if (log.getTopics().get(0).equals(HashUtils.Keccak256("Transfer(identity,identity,uint256)"))) {
                System.out.println("from:" + log.getTopics().get(1));
                System.out.println("to:" + log.getTopics().get(2));
                System.out.println("token:" + log.getTopics().get(3));
            }
        }
    }
}
