Quorum

使用 Quorum Web3j 響應部署契約:非 200 狀態程式碼

  • March 15, 2019

設想:

我有以下程式碼:

final String hostUrl = this.deployerProperties.getProperty("quorum.host.url");
final String hostPort = this.deployerProperties.getProperty("quorum.host.port");
final String host = hostUrl + ":" + hostPort;
final HttpService httpService = new HttpService(host);

this.admin = Admin.build(httpService);
this.quorum = Quorum.build(httpService);

final EthAccounts ethAccounts = this.quorum.ethAccounts().send();
final String ethFirstAccount = ethAccounts.getAccounts().get(0);
final PersonalUnlockAccount personalUnlockAccount = this.admin.personalUnlockAccount(ethFirstAccount, "").send();
if (!personalUnlockAccount.accountUnlocked()) {
       throw new IllegalStateException("Account " + ethFirstAccount + " can not be unlocked!");
} 

final List<String> privateFor = new ArrayList<>();
final ClientTransactionManager clientTransactionManager = new ClientTransactionManager(this.quorum, ethFirstAccount, ethFirstAccount, privateFor);

final ContractGasProvider contractGasProvider = new DefaultGasProvider();
//final ContractGasProvider contractGasProvider = new DeployGasProvider();

final Tokens tokens = Tokens.deploy(this.quorum, clientTransactionManager, contractGasProvider).send();

當我執行程式碼時。我收到以下錯誤:

引起:java.lang.RuntimeException:處理事務請求時出錯:非200狀態碼:&{Status:400 Bad Request StatusCode:400 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map

$$ Content-Type:[text/plain $$內容長度:$$ 96 $$聯繫:$$ keep-alive $$] 正文:0xc423004080 內容長度:96 傳輸編碼:$$ $$關閉:假未壓縮:假預告片:地圖$$ $$請求:0xc4200ea500 TLS:}

使令牌部署的行中斷了執行。Google搜尋我在這個網站上發現了類似的問題:LINK所以我決定創建自己的 GasProvider。

import org.web3j.tx.gas.StaticGasProvider;
import java.math.BigInteger;
import org.web3j.tx.ManagedTransaction;

@SuppressWarnings("deprecation")
public class DeployGasProvider extends StaticGasProvider{


public static final BigInteger GAS_LIMIT = BigInteger.valueOf(22_000_000_000L);

public static final BigInteger GAS_PRICE = ManagedTransaction.GAS_PRICE;

   public DeployGasProvider() {
       super(GAS_PRICE, GAS_LIMIT);
   }
}

但錯誤仍然存在。環境如下:

  • Web3jQuorum v4.0.6
  • 法定人數 v2.2.21
  • Solcjs v0.4.24

我嘗試使用此文章答案進行修復。但仍然返回相同

這裡的問題是您提供了一個“privateFor”值——因此,quorum 將其視為私人交易;但是您提供的 privateFor 值是一個空列表,因此被拒絕。如果您為 privateFor 提供空值,那麼您會發現它工作正常。

(順便說一句,DeployGasProvider 中的 GASLIMIT 值非常高,因此您可能會發現它由於超出塊氣體限製而失敗。)

引用自:https://ethereum.stackexchange.com/questions/68330