Skip to content

Commit

Permalink
fix: not deployed account build token transfer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhangguiguang committed Jan 3, 2024
1 parent a5bbd62 commit befecc7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions core/starknet/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,13 @@ func (c *Chain) SendSignedTransaction(signedTxn base.SignedTransaction) (hash *b
if txn.invokeTxn != nil {
resp, err := c.rpc.AddInvokeTransaction(context.Background(), txn.invokeTxn)
if err != nil {
needDeploy := txn.NeedAutoDeploy && IsNotDeployedError(err)
if !needDeploy {
if !txn.NeedAutoDeploy {
return nil, err
}
deployed, err_ := c.IsContractAddressDeployed(txn.invokeTxn.SenderAddress.String())
if err_ != nil || deployed.Value == true {
return nil, err // if query failed, return the previous error.
}

// we need deploy the account firstly, and resend the original txn with fixed Nonce 1
deployTxn, err := c.BuildDeployAccountTransaction(txn.Account.PublicKeyHex(), "")
Expand Down Expand Up @@ -320,6 +323,6 @@ func (c *Chain) IsContractAddressDeployed(contractAddress string) (b *base.Optio
}
return nil, err
}
deployed := !nonce.IsZero()
deployed := nonce != nil
return base.NewOptionalBool(deployed), nil
}
3 changes: 1 addition & 2 deletions core/starknet/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ func TestNotdeployedAccount(t *testing.T) {
token := chain.MainToken()

txn, err := token.BuildTransfer(acc.Address(), acc.Address(), "100000000")
require.Error(t, err)
return
require.Nil(t, err)

_, err = chain.EstimateTransactionFeeUseAccount(txn, acc)
t.Log(IsNotDeployedError(err))
Expand Down
6 changes: 5 additions & 1 deletion core/starknet/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ func (t *Token) BuildTransfer(sender, receiver, amount string) (txn base.Transac
}
nonce, err := cli.Nonce(context.Background(), latestBlockId, senderFelt)
if err != nil {
return
if err.Error() == rpc.ErrContractNotFound.Error() {
nonce = &felt.Zero
} else {
return nil, err
}
}
invokeTx := rpc.InvokeTxnV1{
MaxFee: new(felt.Felt).SetUint64(uint64(InvokeMaxFee)),
Expand Down

0 comments on commit befecc7

Please sign in to comment.