mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
evmjit: Cleanup calls
This commit is contained in:
parent
07f1584628
commit
10ee998a04
1 changed files with 39 additions and 68 deletions
|
|
@ -338,93 +338,64 @@ func call(result *C.struct_evm_result, pCtx unsafe.Pointer, msg *C.struct_evm_me
|
||||||
addr := *(*common.Address)(unsafe.Pointer(&msg.address))
|
addr := *(*common.Address)(unsafe.Pointer(&msg.address))
|
||||||
value := (*(*common.Hash)(unsafe.Pointer(&msg.value))).Big()
|
value := (*(*common.Hash)(unsafe.Pointer(&msg.value))).Big()
|
||||||
input := GoByteSlice(unsafe.Pointer(msg.input), msg.input_size)
|
input := GoByteSlice(unsafe.Pointer(msg.input), msg.input_size)
|
||||||
// output := GoByteSlice(pOutput, outputSize)
|
|
||||||
gas := int64(msg.gas)
|
gas := int64(msg.gas)
|
||||||
bigGas := new(big.Int).SetInt64(gas)
|
bigGas := new(big.Int).SetInt64(gas)
|
||||||
|
|
||||||
// Prepare result with default values.
|
contract.Gas.SetInt64(0)
|
||||||
result.release = nil
|
|
||||||
result.status_code = C.EVM_FAILURE
|
var output []byte
|
||||||
result.output_data = nil
|
var err error
|
||||||
result.output_size = 0
|
|
||||||
|
|
||||||
switch msg.kind {
|
switch msg.kind {
|
||||||
case C.EVM_CALL:
|
case C.EVM_CALL:
|
||||||
fmt.Printf("CALL(gas %d, %x)\n", bigGas, addr)
|
fmt.Printf("CALL(gas %d, %x)\n", bigGas, addr)
|
||||||
contract.Gas.SetInt64(0)
|
output, err = env.Call(contract, addr, input, bigGas, value)
|
||||||
ret, err := env.Call(contract, addr, input, bigGas, value)
|
|
||||||
gasLeft := contract.Gas.Int64()
|
|
||||||
assert(gasLeft <= gas, fmt.Sprintf("%d <= %d", gasLeft, gas))
|
|
||||||
fmt.Printf("Gas left %d, err: %s\n", gasLeft, err)
|
|
||||||
result.gas_left = C.int64_t(gasLeft)
|
|
||||||
if err == nil {
|
|
||||||
fmt.Printf("Output: %x\n", ret)
|
|
||||||
result.status_code = C.EVM_SUCCESS
|
|
||||||
coutput := C.CBytes(ret)
|
|
||||||
result.output_data = (*C.uint8_t)(coutput)
|
|
||||||
result.output_size = C.size_t(len(ret))
|
|
||||||
// FIXME: free output
|
|
||||||
return
|
|
||||||
}
|
|
||||||
result.status_code = C.EVM_FAILURE
|
|
||||||
return
|
|
||||||
|
|
||||||
case C.EVM_CALLCODE:
|
case C.EVM_CALLCODE:
|
||||||
fmt.Printf("CALLCODE(gas %d, %x, value %d)\n", bigGas, addr, value)
|
fmt.Printf("CALLCODE(gas %d, %x, value %d)\n", bigGas, addr, value)
|
||||||
contract.Gas.SetInt64(0)
|
output, err = env.CallCode(contract, addr, input, bigGas, value)
|
||||||
ret, err := env.CallCode(contract, addr, input, bigGas, value)
|
|
||||||
gasLeft := contract.Gas.Int64()
|
|
||||||
assert(gasLeft <= gas, fmt.Sprintf("%d <= %d", gasLeft, gas))
|
|
||||||
fmt.Printf("Gas left %d, err: %s\n", gasLeft, err)
|
|
||||||
result.gas_left = C.int64_t(gasLeft)
|
|
||||||
if err == nil {
|
|
||||||
result.status_code = C.EVM_SUCCESS
|
|
||||||
coutput := C.CBytes(ret)
|
|
||||||
result.output_data = (*C.uint8_t)(coutput)
|
|
||||||
result.output_size = C.size_t(len(ret))
|
|
||||||
// FIXME: free output
|
|
||||||
return
|
|
||||||
}
|
|
||||||
result.status_code = C.EVM_FAILURE
|
|
||||||
return
|
|
||||||
|
|
||||||
case C.EVM_DELEGATECALL:
|
case C.EVM_DELEGATECALL:
|
||||||
fmt.Printf("DELEGATECALL(gas %d, %x)\n", bigGas, addr)
|
fmt.Printf("DELEGATECALL(gas %d, %x)\n", bigGas, addr)
|
||||||
contract.Gas.SetInt64(0)
|
output, err = env.DelegateCall(contract, addr, input, bigGas)
|
||||||
ret, err := env.DelegateCall(contract, addr, input, bigGas)
|
|
||||||
gasLeft := contract.Gas.Int64()
|
|
||||||
assert(gasLeft <= gas, fmt.Sprintf("%d <= %d", gasLeft, gas))
|
|
||||||
fmt.Printf("Gas left %d, err: %s\n", gasLeft, err)
|
|
||||||
result.gas_left = C.int64_t(gasLeft)
|
|
||||||
if err == nil {
|
|
||||||
result.status_code = C.EVM_SUCCESS
|
|
||||||
coutput := C.CBytes(ret)
|
|
||||||
result.output_data = (*C.uint8_t)(coutput)
|
|
||||||
result.output_size = C.size_t(len(ret))
|
|
||||||
// FIXME: free output
|
|
||||||
return
|
|
||||||
}
|
|
||||||
result.status_code = C.EVM_FAILURE
|
|
||||||
return
|
|
||||||
|
|
||||||
case C.EVM_CREATE:
|
case C.EVM_CREATE:
|
||||||
fmt.Printf("CREATE(gas %d, %x)\n", bigGas, addr)
|
fmt.Printf("CREATE(gas %d, %x)\n", bigGas, addr)
|
||||||
contract.Gas.SetInt64(0)
|
var createAddr common.Address
|
||||||
_, createAddr, err := env.Create(contract, input, bigGas, value)
|
_, createAddr, err = env.Create(contract, input, bigGas, value)
|
||||||
|
isHomestead := env.ChainConfig().IsHomestead(env.BlockNumber)
|
||||||
|
if !isHomestead && err == ErrCodeStoreOutOfGas {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
// Copy create address to result.
|
||||||
|
ca := GoByteSlice(unsafe.Pointer(&result.create_address.bytes), 20)
|
||||||
|
copy(ca, createAddr[:])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gasLeft := contract.Gas.Int64()
|
gasLeft := contract.Gas.Int64()
|
||||||
assert(gasLeft <= gas, fmt.Sprintf("%d <= %d", gasLeft, gas))
|
assert(gasLeft <= gas, fmt.Sprintf("%d <= %d", gasLeft, gas))
|
||||||
fmt.Printf("Gas left %d, err: %s\n", gasLeft, err)
|
fmt.Printf("Gas left %d, err: %s\n", gasLeft, err)
|
||||||
result.gas_left = C.int64_t(gasLeft)
|
result.gas_left = C.int64_t(gasLeft)
|
||||||
result.status_code = C.EVM_FAILURE
|
|
||||||
if (env.ChainConfig().IsHomestead(env.BlockNumber) && err == ErrCodeStoreOutOfGas) ||
|
// Map error to status code.
|
||||||
(err != nil && err != ErrCodeStoreOutOfGas) {
|
if err == nil {
|
||||||
return
|
|
||||||
} else {
|
|
||||||
result.status_code = C.EVM_SUCCESS
|
result.status_code = C.EVM_SUCCESS
|
||||||
ca := GoByteSlice(unsafe.Pointer(&result.create_address.bytes), 20)
|
} else {
|
||||||
copy(ca, createAddr[:])
|
result.status_code = C.EVM_FAILURE
|
||||||
}
|
}
|
||||||
return
|
|
||||||
|
if len(output) > 0 {
|
||||||
|
cOutput := C.CBytes(output)
|
||||||
|
result.output_data = (*C.uint8_t)(cOutput)
|
||||||
|
result.output_size = C.size_t(len(output))
|
||||||
|
// FIXME: free output
|
||||||
|
result.release = nil
|
||||||
|
} else {
|
||||||
|
result.output_data = nil
|
||||||
|
result.output_size = 0
|
||||||
|
result.release = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue