Skip to content

Commit

Permalink
fix run and create
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Gololicic committed Jan 5, 2024
1 parent c7bd77b commit edbadc3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions internal/evm/create.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import FlowToken from 0x0ae53cb6e3f42a79

transaction(amount: UFix64) {
let sentVault: @FlowToken.Vault
let auth: AuthAccount
let auth: auth(Storage) &Account

prepare(signer: auth(Storage) &Account) {
let vaultRef = signer.storage.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdrawable) &FlowToken.Vault>(from: /storage/flowTokenVault)
?? panic("Could not borrow reference to the owner's Vault!")

self.sentVault <- vaultRef.withdraw(amount: amount) as! @FlowToken.Vault
Expand Down
16 changes: 8 additions & 8 deletions internal/evm/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,8 @@ func get(
flow flowkit.Services,
state *flowkit.State,
) (command.Result, error) {
a, err := hex.DecodeString(args[0])
if err != nil {
return nil, err
}

addressBytes := cadenceByteArrayString(a)

val, _ := GetEVMAccountBalance(addressBytes, flow)
val, _ := GetEVMAccountBalance(args[0], flow)

fmt.Printf("\n🔥🔥🔥🔥🔥🔥🔥 EVM Get Balance 🔥🔥🔥🔥🔥🔥🔥\n")
fmt.Println("Balance: ", val)
Expand All @@ -79,8 +73,14 @@ func GetEVMAccountBalance(
address string,
flow flowkit.Services,
) (cadence.Value, error) {
a, err := hex.DecodeString(address)
if err != nil {
return nil, err
}

addressBytes := cadenceByteArrayString(a)

scriptArgs, err := arguments.ParseWithoutType([]string{address}, getCode, "")
scriptArgs, err := arguments.ParseWithoutType([]string{addressBytes}, getCode, "")
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions internal/evm/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,10 @@ func (e *ethAPI) GetBalance(
e.log.Info().Str("address", address.String()).Msg("get balance")

addr := strings.ReplaceAll(address.String(), "0x", "")

val, err := GetEVMAccountBalance(addr, e.flow)
if err != nil {
e.log.Info().Err(err).Str("address", address.String()).Msg("get account balance error")
return nil, err
}

Expand Down
3 changes: 2 additions & 1 deletion internal/evm/run.cdc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import EVM from 0xf8d6e0586b0a20c7 // todo dynamically set
access(all) fun main(caller: Address, contractAddress: [UInt8; 20], data: [UInt8]): [UInt8] {
let bridgedAccount <- EVM.createBridgedAccount()
let flowAccount = getAuthAccount<auth(Storage) &Account>(caller)
let bridgedAccount <- flowAccount.storage.load<@EVM.BridgedAccount>(from: StoragePath(identifier: "evm")!)!
let evmAddress = EVM.EVMAddress(bytes: contractAddress)

let evmResult = bridgedAccount.call(
Expand Down

0 comments on commit edbadc3

Please sign in to comment.