-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from m-Peter/optimize-evm-tx-format
Optimize format for EVM txs & data
- Loading branch information
Showing
8 changed files
with
116 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
import EVM | ||
|
||
access(all) | ||
fun main(data: [UInt8], contractAddress: [UInt8; 20]): [UInt8] { | ||
fun main(hexEncodedData: String, hexEncodedAddress: String): String { | ||
let account = getAuthAccount<auth(Storage) &Account>(Address(0xCOA)) | ||
|
||
let coa = account.storage.borrow<auth(EVM.Call) &EVM.CadenceOwnedAccount>(from: /storage/evm) | ||
?? panic("Could not borrow reference to the COA!") | ||
let coa = account.storage.borrow<auth(EVM.Call) &EVM.CadenceOwnedAccount>( | ||
from: /storage/evm | ||
) ?? panic("Could not borrow reference to the COA!") | ||
let addressBytes = hexEncodedAddress.decodeHex().toConstantSized<[UInt8; 20]>()! | ||
|
||
return coa.call( | ||
to: EVM.EVMAddress(bytes: contractAddress), | ||
data: data, | ||
let callResult = coa.call( | ||
to: EVM.EVMAddress(bytes: addressBytes), | ||
data: hexEncodedData.decodeHex(), | ||
gasLimit: 15000000, // todo make it configurable, max for now | ||
value: EVM.Balance(attoflow: 0) | ||
).data | ||
) | ||
|
||
return String.encodeHex(callResult.data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import EVM | ||
|
||
access(all) | ||
fun main(encodedTx: [UInt8]): [UInt64; 2] { | ||
fun main(hexEncodedTx: String): [UInt64; 2] { | ||
let account = getAuthAccount<auth(Storage) &Account>(Address(0xCOA)) | ||
|
||
let coa = account.storage.borrow<&EVM.CadenceOwnedAccount>( | ||
from: /storage/evm | ||
) ?? panic("Could not borrow reference to the COA!") | ||
let txResult = EVM.run(tx: encodedTx, coinbase: coa.address()) | ||
let txResult = EVM.run(tx: hexEncodedTx.decodeHex(), coinbase: coa.address()) | ||
|
||
return [txResult.errorCode, txResult.gasUsed] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
import EVM | ||
|
||
transaction(encodedTx: [UInt8]) { | ||
transaction(hexEncodedTx: String) { | ||
let coa: &EVM.CadenceOwnedAccount | ||
|
||
prepare(signer: auth(Storage) &Account) { | ||
self.coa = signer.storage.borrow<&EVM.CadenceOwnedAccount>(from: /storage/evm) | ||
?? panic("Could not borrow reference to the bridged account!") | ||
self.coa = signer.storage.borrow<&EVM.CadenceOwnedAccount>( | ||
from: /storage/evm | ||
) ?? panic("Could not borrow reference to the COA!") | ||
} | ||
|
||
execute { | ||
let result = EVM.run(tx: encodedTx, coinbase: self.coa.address()) | ||
let txResult = EVM.run(tx: hexEncodedTx.decodeHex(), coinbase: self.coa.address()) | ||
// todo only temporary until we correctly handle failure events | ||
assert( | ||
result.status == EVM.Status.successful, | ||
message: "failed to execute evm transaction: ".concat(result.errorCode.toString()) | ||
txResult.status == EVM.Status.successful, | ||
message: "failed to execute evm transaction: ".concat(txResult.errorCode.toString()) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters