锯齿 java 发送批量请求错误

sawtooth java send batch request error

我正在尝试使用 Sawtooth java SDK 发送批次。

1) - 我通过锯齿 CLI 生成密钥

2) - 我正在使用 processor 处理客户端请求

3) - 我构建了批量查询。

4) - 发送查询后,我的响应总是无效状态。我的处理器日志中也有此消息 ("applicator->Apply errorState Get Authorization error. Check transaction inputs.")。

请帮助我。(下面是我客户的代码)

public class 主 {

public static void main(String[] args) throws UnirestException, NoSuchAlgorithmException {


    ECKey privateKey = Signing.readWif(getWifKey("c1783ac6bf55910ab9bfa6defbd7b819a5b29032dd281fa1976363fd6e08d59d")); //generated pk by sawtooth keygen
    String publicKey = Signing.getPublicKey(privateKey);

    ByteString publicKeyByteString = ByteString.copyFromUtf8(publicKey);

    String payload = "deposit,50,02e664d454c7841ae1e2bd9a597dd12b2fa09f9389b29ab9fda6220674ff7bc7b8";
    String payloadBytes = Utils.hash512(payload.getBytes());
    ByteString payloadByteString = ByteString.copyFrom(payload.getBytes());

    TransactionHeader txnHeader = TransactionHeader.newBuilder()
            .setBatcherPublicKeyBytes(publicKeyByteString)
            .setSignerPublicKeyBytes(publicKeyByteString)
            .setFamilyName("simplewallet")
            .setFamilyVersion("1.0")
            .addInputs(publicKey)
            .setNonce("1")
            .addOutputs("02e664d454c7841ae1e2bd9a597dd12b2fa09f9389b29ab9fda6220674ff7bc7b8")//recipient public key
            .setPayloadSha512(payloadBytes)
            .setSignerPublicKey(publicKey)
            .build();
    ByteString txnHeaderBytes = txnHeader.toByteString();
    String txnHeaderSignature = Signing.sign(privateKey, txnHeaderBytes.toByteArray());

    Transaction txn = Transaction.newBuilder()
            .setHeader(txnHeaderBytes)
            .setPayload(payloadByteString)
            .setHeaderSignature(txnHeaderSignature)
            .build();

    BatchHeader batchHeader = BatchHeader.newBuilder()
            .setSignerPublicKey(publicKey)
            .addTransactionIds(txn.getHeaderSignature())
            .build();
    ByteString batchHeaderBytes = batchHeader.toByteString();
    String batchHeaderSignature = Signing.sign(privateKey, batchHeaderBytes.toByteArray());

    Batch batch = Batch.newBuilder()
            .setHeader(batchHeaderBytes)
            .setHeaderSignature(batchHeaderSignature)
            .addTransactions(txn)
            .build();

    BatchList batchList = BatchList.newBuilder()
            .addBatches(batch)
            .build();
    ByteString batchBytes = batchList.toByteString();

    String serverResponse = Unirest.post("http://localhost:8008/batches")
            .header("Content-Type", "application/octet-stream")
            .body(batchBytes.toByteArray())
            .asString()
            .getBody();

    System.out.println(serverResponse);

}

private static String getWifKey(String sourceKey) throws NoSuchAlgorithmException {

    sourceKey = "80" + sourceKey;

    byte[] pkByteArr = hexStringToByteArray(sourceKey);

    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    byte[] hash = digest.digest(pkByteArr);

    byte[] secondHash = digest.digest(hash);

    byte[] resPkBytes = new byte[pkByteArr.length + 4];

    System.arraycopy(pkByteArr, 0, resPkBytes, 0, pkByteArr.length);

    System.arraycopy(secondHash, 0, resPkBytes, pkByteArr.length, 4);

    return Base58.encode(resPkBytes);
}

private static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                + Character.digit(s.charAt(i + 1), 16));
    }
    return data;
}

}

这意味着交易批次已被交易处理器处理,但交易处理器将其标记为无效。可能是因为序列化或者反序列化的问题。

这是一个使用 Java 客户端(和其他编程语言)的简单 Sawtooth 应用程序示例: https://github.com/danintel/sawtooth-simplewallet