英文:
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("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);
}
The params I send are a FlowAddress for the service account and the public key showed up on emulator startup.
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论