Skip to content

Commit

Permalink
Merge pull request #47 from AntChainOpenLabs/fix/bcdns/bif-chain-call…
Browse files Browse the repository at this point in the history
…ing-failed

[fix][*][0.2.3]: fix BIF chain calling problems
  • Loading branch information
zouxyan authored Jul 1, 2024
2 parents 71a6864 + 9f0b3c3 commit 3507e1b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion antchain-bridge-bcdns/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-bcdns</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
public class BifBCDNSClient implements IBlockChainDomainNameService {

private static final String DOMAIN_CALL_GET_CERT_BY_NAME_TEMPLATE
= "{\"function\":\"getCertByName(string)\",\"args\":\"'{}'\",\"return\":\"returns(string)\"}";
= "{\"function\":\"getCertByName(string)\",\"args\":\"'{}'\",\"return\":\"returns(bytes)\"}";

private static final String PTC_CALL_GET_CERT_BY_ID_TEMPLATE
= "{\"function\":\"getCertById(string)\",\"args\":\"'{}'\",\"return\":\"returns(string)\"}";
= "{\"function\":\"getCertById(string)\",\"args\":\"'{}'\",\"return\":\"returns(bytes)\"}";

private static final String RELAY_CALL_BINDING_DOMAIN_NAME_WITH_RELAY_TEMPLATE
= "{\"function\":\"bindingDomainNameWithRelay(string,string,bytes)\",\"args\":\"'{}','{}','{}'\"}";
Expand All @@ -64,13 +64,13 @@ public class BifBCDNSClient implements IBlockChainDomainNameService {
= "{\"function\":\"bindingDomainNameWithTPBTA(string,bytes)\",\"args\":\"'{}','{}'\"}";

private static final String RELAY_CALL_GET_TPBTA_BY_DOMAIN_NAME_TEMPLATE
= "{\"function\":\"getTPBTAByDomainName(string)\",\"args\":\"'{}'\",\"return\":\"returns(string)\"}";
= "{\"function\":\"getTPBTAByDomainName(string)\",\"args\":\"'{}'\",\"return\":\"returns(bytes)\"}";

private static final String RELAY_CALL_GET_CERT_BY_ID_TEMPLATE
= "{\"function\":\"getCertById(string)\",\"args\":\"'{}'\",\"return\":\"returns(string)\"}";
= "{\"function\":\"getCertById(string)\",\"args\":\"'{}'\",\"return\":\"returns(bytes)\"}";

private static final String RELAY_CALL_GET_RELAY_BY_DOMAIN_NAME_TEMPLATE
= "{\"function\":\"getRelayByDomainName(string)\",\"args\":\"'{}'\",\"return\":\"returns(string,string)\"}";
= "{\"function\":\"getRelayByDomainName(string)\",\"args\":\"'{}'\",\"return\":\"returns(bytes,bytes)\"}";

public static BifBCDNSClient generateFrom(byte[] rawConf) {
BifBCNDSConfig config = JSON.parseObject(rawConf, BifBCNDSConfig.class);
Expand Down Expand Up @@ -169,6 +169,11 @@ public QueryRelayerCertificateResponse queryRelayerCertificate(QueryRelayerCerti
request.getRelayerCertId()
)
);
// BIF test net has some problems about gas calculation
// So we just set gas manually here.
// would delete it in the future.
bifContractCallRequest.setGasPrice(1L);

BIFContractCallResponse response = bifsdk.getBIFContractService().contractQuery(bifContractCallRequest);
if (0 != response.getErrorCode()) {
throw new AntChainBridgeBCDNSException(
Expand All @@ -184,7 +189,7 @@ public QueryRelayerCertificateResponse queryRelayerCertificate(QueryRelayerCerti
boolean exist = StrUtil.isNotEmpty(res);
return new QueryRelayerCertificateResponse(
exist,
exist ? CrossChainCertificateFactory.createCrossChainCertificate(Base64.decode(res)) : null
exist ? CrossChainCertificateFactory.createCrossChainCertificate(HexUtil.decodeHex(res)) : null
);
} catch (AntChainBridgeBCDNSException e) {
throw e;
Expand All @@ -211,6 +216,11 @@ public QueryPTCCertificateResponse queryPTCCertificate(QueryPTCCertificateReques
request.getPtcCertId()
)
);
// BIF test net has some problems about gas calculation
// So we just set gas manually here.
// would delete it in the future.
bifContractCallRequest.setGasPrice(1L);

BIFContractCallResponse response = bifsdk.getBIFContractService().contractQuery(bifContractCallRequest);
if (0 != response.getErrorCode()) {
throw new AntChainBridgeBCDNSException(
Expand All @@ -226,7 +236,7 @@ public QueryPTCCertificateResponse queryPTCCertificate(QueryPTCCertificateReques
boolean exist = StrUtil.isNotEmpty(res);
return new QueryPTCCertificateResponse(
exist,
exist ? CrossChainCertificateFactory.createCrossChainCertificate(Base64.decode(res)) : null
exist ? CrossChainCertificateFactory.createCrossChainCertificate(HexUtil.decodeHex(res)) : null
);
} catch (AntChainBridgeBCDNSException e) {
throw e;
Expand All @@ -253,6 +263,11 @@ public QueryDomainNameCertificateResponse queryDomainNameCertificate(QueryDomain
request.getDomain().getDomain()
)
);
// BIF test net has some problems about gas calculation
// So we just set gas manually here.
// would delete it in the future.
bifContractCallRequest.setGasPrice(1L);

BIFContractCallResponse response = bifsdk.getBIFContractService().contractQuery(bifContractCallRequest);
if (0 != response.getErrorCode()) {
throw new AntChainBridgeBCDNSException(
Expand All @@ -268,7 +283,7 @@ public QueryDomainNameCertificateResponse queryDomainNameCertificate(QueryDomain
boolean exist = StrUtil.isNotEmpty(res);
return new QueryDomainNameCertificateResponse(
exist,
exist ? CrossChainCertificateFactory.createCrossChainCertificate(Base64.decode(res)) : null
exist ? CrossChainCertificateFactory.createCrossChainCertificate(HexUtil.decodeHex(res)) : null
);
} catch (AntChainBridgeBCDNSException e) {
throw e;
Expand Down Expand Up @@ -381,6 +396,11 @@ public DomainRouter queryDomainRouter(QueryDomainRouterRequest request) {
request.getDestDomain().getDomain()
)
);
// BIF test net has some problems about gas calculation
// So we just set gas manually here.
// would delete it in the future.
bifContractCallRequest.setGasPrice(1L);

BIFContractCallResponse response = bifsdk.getBIFContractService().contractQuery(bifContractCallRequest);
if (0 != response.getErrorCode() || ObjectUtil.isNull(response.getResult())) {
throw new RuntimeException(StrUtil.format("call BIF chain failed: ( err_code: {}, err_msg: {} )",
Expand All @@ -391,9 +411,9 @@ public DomainRouter queryDomainRouter(QueryDomainRouterRequest request) {
return null;
}
AbstractCrossChainCertificate relayerCert = CrossChainCertificateFactory.createCrossChainCertificate(
Base64.decode(res.get(0))
HexUtil.decodeHex(res.get(0))
);
List<String> netAddresses = StrUtil.split(res.get(1), "^")
List<String> netAddresses = StrUtil.split(HexUtil.decodeHexStr(StrUtil.removePrefix(res.get(1), "0x")), "^")
.stream().map(HexUtil::decodeHexStr).collect(Collectors.toList());
return new DomainRouter(
request.getDestDomain(),
Expand Down Expand Up @@ -428,6 +448,11 @@ public byte[] queryThirdPartyBlockchainTrustAnchor(QueryThirdPartyBlockchainTrus
request.getDomain().getDomain()
)
);
// BIF test net has some problems about gas calculation
// So we just set gas manually here.
// would delete it in the future.
bifContractCallRequest.setGasPrice(1L);

BIFContractCallResponse response = bifsdk.getBIFContractService().contractQuery(bifContractCallRequest);
if (0 != response.getErrorCode()) {
throw new AntChainBridgeBCDNSException(
Expand Down
2 changes: 1 addition & 1 deletion antchain-bridge-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-commons</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion antchain-bridge-plugin-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-plugin-lib</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion antchain-bridge-plugin-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-plugin-manager</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion antchain-bridge-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-spi</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<packaging>pom</packaging>
<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-sdk</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>

<modules>
<module>antchain-bridge-commons</module>
Expand Down

0 comments on commit 3507e1b

Please sign in to comment.