Skip to content

Commit

Permalink
feat: update cairo version when build token transfer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhangguiguang committed Jan 2, 2024
1 parent a81c3b4 commit 09948aa
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion core/starknet/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (t *Token) BuildTransfer(sender, receiver, amount string) (txn base.Transac
}

cli := t.chain.rpc
cli.CairoVersion = 2
cli.CairoVersion = cairoVersionOf(*senderFelt, cli)
callData, err := cli.FmtCalldata([]rpc.FunctionCall{transferCall})
if err != nil {
return
Expand Down Expand Up @@ -161,3 +161,21 @@ func (t *Token) CanTransferAll() bool {
func (t *Token) BuildTransferAll(sender, receiver string) (txn base.Transaction, err error) {
return nil, base.ErrUnsupportedFunction
}

func cairoVersionOf(contractAddress felt.Felt, cli rpc.RpcProvider) int {
classInfo, err := cli.ClassAt(context.Background(), latestBlockId, &contractAddress)
if err != nil {
return 2 // default
}
switch info := classInfo.(type) {
case rpc.DeprecatedContractClass:
return 0
case rpc.ContractClass:
if info.ContractClassVersion == "0.0.0" {
return 0
}
return 2
default:
return 2
}
}

0 comments on commit 09948aa

Please sign in to comment.