Flow帐户创建引发异常“密钥的重复签名”。

huangapple go评论78阅读模式
英文:

Flow account creation throws excepcion "duplicated signature for key"

问题

I'm here to provide the translated content:

我正在尝试使用FLOW,并且只需要创建一个帐户并部署一个用于创建新代币的智能合约。

首先,我正在尝试使用此合同创建帐户:

transaction(publicKey: String) {
	prepare(signer: AuthAccount) {
		let account = AuthAccount(payer: signer)
        account.addPublicKey(publicKey.decodeHex())
	}
}

然后,我尝试使用从这里获取的Java方法来创建帐户:

public FlowAddress createAccount(FlowAddress payerAddress, String publicKeyHex) {
        FlowAccountKey payerAccountKey = this.getAccountKey(payerAddress, 0);
        FlowAccountKey newAccountPublicKey = new FlowAccountKey(
                0,
                new FlowPublicKey(publicKeyHex),
                SignatureAlgorithm.ECDSA_P256,
                HashAlgorithm.SHA2_256,
                1,
                0,
                false);

        FlowTransaction tx = new FlowTransaction(
                new FlowScript(loadScript("src/main/resources/cadence/transactions/flow/create_account.cdc")),
                Arrays.asList(new FlowArgument(new StringField(Hex.toHexString(newAccountPublicKey.getEncoded())))),
                this.getLatestBlockID(),
                100L,
                new FlowTransactionProposalKey(
                        payerAddress,
                        payerAccountKey.getId(),
                        payerAccountKey.getSequenceNumber()),
                payerAddress,
                Arrays.asList(payerAddress),
                new ArrayList<>(),
                new ArrayList<>());

        Signer signer = Crypto.getSigner(this.privateKey, payerAccountKey.getHashAlgo());
        tx = tx.addPayloadSignature(payerAddress, 0, signer);
        tx = tx.addEnvelopeSignature(payerAddress, 0, signer);

        FlowId txID = this.accessAPI.sendTransaction(tx);
        FlowTransactionResult txResult = this.waitForSeal(txID);

        return this.getAccountCreatedAddress(txResult);
    }

我发送的参数是用于服务帐户的FlowAddress和模拟器启动时显示的公钥。

并且我收到的错误是:

Exception in thread "main" 09:31:41.659 [grpc-default-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0x2cb4b865, L:/127.0.0.1:60468 - R:localhost/127.0.0.1:3569] OUTBOUND RST_STREAM: streamId=9 errorCode=8
io.grpc.StatusRuntimeException: INTERNAL: duplicated signature for key (address: f8d6e0586b0a20c7, index: 0)

我认为这不是一个“编码”错误,而是一个概念错误。是否有人知道如何创建此帐户?

英文:

I'm trying to get into FLOW and I just need to create an account and deploy a contract for creating a new token.

So, first I'm trying to create an account with this contract:

transaction(publicKey: String) {
	prepare(signer: AuthAccount) {
		let account = AuthAccount(payer: signer)
        account.addPublicKey(publicKey.decodeHex())
	}
}

Then, I try to create it with this java method that I got from here

public FlowAddress createAccount(FlowAddress payerAddress, String publicKeyHex) {
        FlowAccountKey payerAccountKey = this.getAccountKey(payerAddress, 0);
        FlowAccountKey newAccountPublicKey = new FlowAccountKey(
                0,
                new FlowPublicKey(publicKeyHex),
                SignatureAlgorithm.ECDSA_P256,
                HashAlgorithm.SHA2_256,
                1,
                0,
                false);

        FlowTransaction tx = new FlowTransaction(
                new FlowScript(loadScript(&quot;src/main/resources/cadence/transactions/flow/create_account.cdc&quot;)),
                Arrays.asList(new FlowArgument(new StringField(Hex.toHexString(newAccountPublicKey.getEncoded())))),
                this.getLatestBlockID(),
                100L,
                new FlowTransactionProposalKey(
                        payerAddress,
                        payerAccountKey.getId(),
                        payerAccountKey.getSequenceNumber()),
                payerAddress,
                Arrays.asList(payerAddress),
                new ArrayList&lt;&gt;(),
                new ArrayList&lt;&gt;());

        Signer signer = Crypto.getSigner(this.privateKey, payerAccountKey.getHashAlgo());
        tx = tx.addPayloadSignature(payerAddress, 0, signer);
        tx = tx.addEnvelopeSignature(payerAddress, 0, signer);

        FlowId txID = this.accessAPI.sendTransaction(tx);
        FlowTransactionResult txResult = this.waitForSeal(txID);

        return this.getAccountCreatedAddress(txResult);
    }

The params I send are a FlowAddress for the service account and the public key showed up on emulator startup.

Flow帐户创建引发异常“密钥的重复签名”。

And the error I receive is:

io.grpc.StatusRuntimeException: INTERNAL: duplicated signature for key (address: f8d6e0586b0a20c7, index: 0)

I assume it's not a "coding" error but a conceptual error. Does anyone know how can I create the account?

答案1

得分: 0

以下是翻译好的部分:

原来 Flow for Java 的示例代码不起作用。
删除这行代码后就可以工作:

tx = tx.addPayloadSignature(payerAddress, 0, signer);
英文:

It turned out that the example code of Flow for Java doesn't work.
Deleted this line and worked:

tx = tx.addPayloadSignature(payerAddress, 0, signer);

huangapple
  • 本文由 发表于 2023年6月12日 21:39:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457238.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定