Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
a4a16863
Commit
a4a16863
authored
Dec 02, 2020
by
aniket-engg
Committed by
Aniket
Dec 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
txFormat methods export improved
parent
db23f70a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
88 deletions
+86
-88
txFormat.ts
libs/remix-lib/src/execution/txFormat.ts
+86
-88
No files found.
libs/remix-lib/src/execution/txFormat.ts
View file @
a4a16863
...
...
@@ -5,16 +5,14 @@ import { eachOfSeries } from 'async'
import
{
linkBytecode
}
from
'solc/linker'
import
{
isValidAddress
,
addHexPrefix
}
from
'ethereumjs-util'
module
.
exports
=
{
/**
/**
* build the transaction data
*
* @param {Object} function abi
* @param {Object} values to encode
* @param {String} contractbyteCode
*/
encodeData
:
function
(
funABI
,
values
,
contractbyteCode
)
{
export
function
encodeData
(
funABI
,
values
,
contractbyteCode
)
{
let
encoded
let
encodedHex
try
{
...
...
@@ -28,16 +26,16 @@ module.exports = {
}
else
{
return
{
data
:
helper
.
encodeFunctionId
(
funABI
)
+
encodedHex
.
replace
(
'0x'
,
''
)
}
}
},
}
/**
* encode function / constructor parameters
*
* @param {Object} params - input paramater of the function to call
* @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor.
* @param {Function} callback - callback
*/
encodeParams
:
function
(
params
,
funAbi
,
callback
)
{
/**
* encode function / constructor parameters
*
* @param {Object} params - input paramater of the function to call
* @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor.
* @param {Function} callback - callback
*/
export
function
encodeParams
(
params
,
funAbi
,
callback
)
{
let
data
:
any
=
''
let
dataHex
=
''
let
funArgs
...
...
@@ -69,33 +67,33 @@ module.exports = {
}
}
callback
(
null
,
{
data
:
data
,
dataHex
:
dataHex
,
funArgs
:
funArgs
})
},
}
/**
* encode function call (function id + encoded parameters)
*
* @param {Object} params - input paramater of the function to call
* @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor.
* @param {Function} callback - callback
*/
encodeFunctionCall
:
function
(
params
,
funAbi
,
callback
)
{
/**
* encode function call (function id + encoded parameters)
*
* @param {Object} params - input paramater of the function to call
* @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor.
* @param {Function} callback - callback
*/
export
function
encodeFunctionCall
(
params
,
funAbi
,
callback
)
{
this
.
encodeParams
(
params
,
funAbi
,
(
error
,
encodedParam
)
=>
{
if
(
error
)
return
callback
(
error
)
callback
(
null
,
{
dataHex
:
helper
.
encodeFunctionId
(
funAbi
)
+
encodedParam
.
dataHex
,
funAbi
,
funArgs
:
encodedParam
.
funArgs
})
})
},
}
/**
* encode constructor creation and link with provided libraries if needed
*
* @param {Object} contract - input paramater of the function to call
* @param {Object} params - input paramater of the function to call
* @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor.
* @param {Object} linkLibraries - contains {linkReferences} object which list all the addresses to be linked
* @param {Object} linkReferences - given by the compiler, contains the proper linkReferences
* @param {Function} callback - callback
*/
encodeConstructorCallAndLinkLibraries
:
function
(
contract
,
params
,
funAbi
,
linkLibraries
,
linkReferences
,
callback
)
{
/**
* encode constructor creation and link with provided libraries if needed
*
* @param {Object} contract - input paramater of the function to call
* @param {Object} params - input paramater of the function to call
* @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor.
* @param {Object} linkLibraries - contains {linkReferences} object which list all the addresses to be linked
* @param {Object} linkReferences - given by the compiler, contains the proper linkReferences
* @param {Function} callback - callback
*/
export
function
encodeConstructorCallAndLinkLibraries
(
contract
,
params
,
funAbi
,
linkLibraries
,
linkReferences
,
callback
)
{
this
.
encodeParams
(
params
,
funAbi
,
(
error
,
encodedParam
)
=>
{
if
(
error
)
return
callback
(
error
)
let
bytecodeToDeploy
=
contract
.
evm
.
bytecode
.
object
...
...
@@ -115,22 +113,22 @@ module.exports = {
}
return
callback
(
null
,
{
dataHex
:
bytecodeToDeploy
+
encodedParam
.
dataHex
,
funAbi
,
funArgs
:
encodedParam
.
funArgs
,
contractBytecode
:
contract
.
evm
.
bytecode
.
object
})
})
},
}
/**
* encode constructor creation and deploy librairies if needed
*
* @param {String} contractName - current contract name
* @param {Object} contract - input paramater of the function to call
* @param {Object} contracts - map of all compiled contracts.
* @param {Object} params - input paramater of the function to call
* @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor.
* @param {Function} callback - callback
* @param {Function} callbackStep - callbackStep
* @param {Function} callbackDeployLibrary - callbackDeployLibrary
* @param {Function} callback - callback
*/
encodeConstructorCallAndDeployLibraries
:
function
(
contractName
,
contract
,
contracts
,
params
,
funAbi
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
/**
* encode constructor creation and deploy librairies if needed
*
* @param {String} contractName - current contract name
* @param {Object} contract - input paramater of the function to call
* @param {Object} contracts - map of all compiled contracts.
* @param {Object} params - input paramater of the function to call
* @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor.
* @param {Function} callback - callback
* @param {Function} callbackStep - callbackStep
* @param {Function} callbackDeployLibrary - callbackDeployLibrary
* @param {Function} callback - callback
*/
export
function
encodeConstructorCallAndDeployLibraries
(
contractName
,
contract
,
contracts
,
params
,
funAbi
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
this
.
encodeParams
(
params
,
funAbi
,
(
error
,
encodedParam
)
=>
{
if
(
error
)
return
callback
(
error
)
let
dataHex
=
''
...
...
@@ -151,22 +149,22 @@ module.exports = {
}
callback
(
null
,
{
dataHex
:
bytecodeToDeploy
,
funAbi
,
funArgs
:
encodedParam
.
funArgs
,
contractBytecode
,
contractName
:
contractName
})
})
},
}
/**
* (DEPRECATED) build the transaction data
*
* @param {String} contractName
* @param {Object} contract - abi definition of the current contract.
* @param {Object} contracts - map of all compiled contracts.
* @param {Bool} isConstructor - isConstructor.
* @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor.
* @param {Object} params - input paramater of the function to call
* @param {Function} callback - callback
* @param {Function} callbackStep - callbackStep
* @param {Function} callbackDeployLibrary - callbackDeployLibrary
*/
buildData
:
function
(
contractName
,
contract
,
contracts
,
isConstructor
,
funAbi
,
params
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
/**
* (DEPRECATED) build the transaction data
*
* @param {String} contractName
* @param {Object} contract - abi definition of the current contract.
* @param {Object} contracts - map of all compiled contracts.
* @param {Bool} isConstructor - isConstructor.
* @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor.
* @param {Object} params - input paramater of the function to call
* @param {Function} callback - callback
* @param {Function} callbackStep - callbackStep
* @param {Function} callbackDeployLibrary - callbackDeployLibrary
*/
export
function
buildData
(
contractName
,
contract
,
contracts
,
isConstructor
,
funAbi
,
params
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
let
funArgs
=
[]
let
data
:
any
=
''
let
dataHex
=
''
...
...
@@ -217,11 +215,11 @@ module.exports = {
dataHex
=
helper
.
encodeFunctionId
(
funAbi
)
+
dataHex
}
callback
(
null
,
{
dataHex
,
funAbi
,
funArgs
,
contractBytecode
,
contractName
:
contractName
})
},
}
atAddress
:
function
()
{},
export
function
atAddress
()
{}
linkBytecodeStandard
:
function
(
contract
,
contracts
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
export
function
linkBytecodeStandard
(
contract
,
contracts
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
let
contractBytecode
=
contract
.
evm
.
bytecode
.
object
eachOfSeries
(
contract
.
evm
.
bytecode
.
linkReferences
,
(
libs
,
file
,
cbFile
)
=>
{
eachOfSeries
(
contract
.
evm
.
bytecode
.
linkReferences
[
file
],
(
libRef
,
libName
,
cbLibDeployed
)
=>
{
...
...
@@ -250,9 +248,9 @@ module.exports = {
}
callback
(
error
,
contractBytecode
)
})
},
}
linkBytecodeLegacy
:
function
(
contract
,
contracts
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
export
function
linkBytecodeLegacy
(
contract
,
contracts
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
const
libraryRefMatch
=
contract
.
evm
.
bytecode
.
object
.
match
(
/__
([^
_
]{1,36})
__/
)
if
(
!
libraryRefMatch
)
{
return
callback
(
'Invalid bytecode format.'
)
...
...
@@ -282,9 +280,9 @@ module.exports = {
contract
.
evm
.
bytecode
.
object
=
this
.
linkLibrary
(
libraryName
,
hexAddress
,
contract
.
evm
.
bytecode
.
object
)
this
.
linkBytecode
(
contract
,
contracts
,
callback
,
callbackStep
,
callbackDeployLibrary
)
},
callbackStep
,
callbackDeployLibrary
)
},
}
linkBytecode
:
function
(
contract
,
contracts
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
export
function
linkBytecode
(
contract
,
contracts
,
callback
?,
callbackStep
?,
callbackDeployLibrary
?
)
{
if
(
contract
.
evm
.
bytecode
.
object
.
indexOf
(
'_'
)
<
0
)
{
return
callback
(
null
,
contract
.
evm
.
bytecode
.
object
)
}
...
...
@@ -293,9 +291,9 @@ module.exports = {
}
else
{
this
.
linkBytecodeLegacy
(
contract
,
contracts
,
callback
,
callbackStep
,
callbackDeployLibrary
)
}
},
}
deployLibrary
:
function
(
libraryName
,
libraryShortName
,
library
,
contracts
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
export
function
deployLibrary
(
libraryName
,
libraryShortName
,
library
,
contracts
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
const
address
=
library
.
address
if
(
address
)
{
return
callback
(
null
,
address
)
...
...
@@ -321,9 +319,9 @@ module.exports = {
callback
(
err
,
address
)
})
}
},
}
linkLibraryStandardFromlinkReferences
:
function
(
libraryName
,
address
,
bytecode
,
linkReferences
)
{
export
function
linkLibraryStandardFromlinkReferences
(
libraryName
,
address
,
bytecode
,
linkReferences
)
{
for
(
let
file
in
linkReferences
)
{
for
(
let
libName
in
linkReferences
[
file
])
{
if
(
libraryName
===
libName
)
{
...
...
@@ -332,13 +330,13 @@ module.exports = {
}
}
return
bytecode
},
}
linkLibraryStandard
:
function
(
libraryName
,
address
,
bytecode
,
contract
)
{
export
function
linkLibraryStandard
(
libraryName
,
address
,
bytecode
,
contract
)
{
return
this
.
linkLibraryStandardFromlinkReferences
(
libraryName
,
address
,
bytecode
,
contract
.
evm
.
bytecode
.
linkReferences
)
},
}
setLibraryAddress
:
function
(
address
,
bytecodeToLink
,
positions
)
{
export
function
setLibraryAddress
(
address
,
bytecodeToLink
,
positions
)
{
if
(
positions
)
{
for
(
let
pos
of
positions
)
{
const
regpos
=
bytecodeToLink
.
match
(
new
RegExp
(
`(.{
${
2
*
pos
.
start
}
})(.{
${
2
*
pos
.
length
}
})(.*)`
))
...
...
@@ -348,13 +346,13 @@ module.exports = {
}
}
return
bytecodeToLink
},
}
linkLibrary
:
function
(
libraryName
,
address
,
bytecodeToLink
)
{
export
function
linkLibrary
(
libraryName
,
address
,
bytecodeToLink
)
{
return
linkBytecode
(
bytecodeToLink
,
{
[
libraryName
]:
addHexPrefix
(
address
)
})
},
}
decodeResponse
:
function
(
response
,
fnabi
)
{
export
function
decodeResponse
(
response
,
fnabi
)
{
// Only decode if there supposed to be fields
if
(
fnabi
.
outputs
&&
fnabi
.
outputs
.
length
>
0
)
{
try
{
...
...
@@ -383,9 +381,9 @@ module.exports = {
}
}
return
{}
},
}
parseFunctionParams
:
function
(
params
)
{
export
function
parseFunctionParams
(
params
)
{
let
args
=
[]
// Check if parameter string starts with array or string
let
startIndex
=
this
.
isArrayOrStringStart
(
params
,
0
)
?
-
1
:
0
...
...
@@ -445,10 +443,10 @@ module.exports = {
}
})
return
args
},
}
isArrayOrStringStart
:
function
(
str
,
index
)
{
export
function
isArrayOrStringStart
(
str
,
index
)
{
return
str
.
charAt
(
index
)
===
'"'
||
str
.
charAt
(
index
)
===
'['
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment