forked from ethereum/remix-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move udapp from remix-lib back to remix-ide
- Loading branch information
1 parent
3d426df
commit 2ac2b64
Showing
3 changed files
with
422 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict' | ||
const { bufferToHex, isHexString } = require('ethereumjs-util') | ||
|
||
function convertToPrefixedHex (input) { | ||
if (input === undefined || input === null || isHexString(input)) { | ||
return input | ||
} else if (Buffer.isBuffer(input)) { | ||
return bufferToHex(input) | ||
} | ||
return '0x' + input.toString(16) | ||
} | ||
|
||
/* | ||
txResult.result can be 3 different things: | ||
- VM call or tx: ethereumjs-vm result object | ||
- Node transaction: object returned from eth.getTransactionReceipt() | ||
- Node call: return value from function call (not an object) | ||
Also, VM results use BN and Buffers, Node results use hex strings/ints, | ||
So we need to normalize the values to prefixed hex strings | ||
*/ | ||
function resultToRemixTx (txResult) { | ||
const { result, transactionHash } = txResult | ||
const { status, execResult, gasUsed, createdAddress, contractAddress } = result | ||
let returnValue, errorMessage | ||
|
||
if (isHexString(result)) { | ||
returnValue = result | ||
} else if (execResult !== undefined) { | ||
returnValue = execResult.returnValue | ||
errorMessage = execResult.exceptionError | ||
} | ||
|
||
return { | ||
transactionHash, | ||
status, | ||
gasUsed: convertToPrefixedHex(gasUsed), | ||
error: errorMessage, | ||
return: convertToPrefixedHex(returnValue), | ||
createdAddress: convertToPrefixedHex(createdAddress || contractAddress) | ||
} | ||
} | ||
|
||
module.exports = { | ||
resultToRemixTx | ||
} |
Oops, something went wrong.