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
807ffd97
Unverified
Commit
807ffd97
authored
Jan 09, 2020
by
yann300
Committed by
GitHub
Jan 09, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1382 from ethereum/receive-fn-support
receive function support added
parents
74b86f93
8301c88c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
12 deletions
+45
-12
txHelper.js
remix-lib/src/execution/txHelper.js
+11
-3
txListener.js
remix-lib/src/execution/txListener.js
+10
-0
universalDapp.js
remix-lib/src/universalDapp.js
+4
-0
txFormat.js
remix-lib/test/txFormat.js
+10
-7
txHelper.js
remix-lib/test/txHelper.js
+9
-1
types.ts
remix-tests/src/types.ts
+1
-1
No files found.
remix-lib/src/execution/txHelper.js
View file @
807ffd97
...
@@ -34,7 +34,7 @@ module.exports = {
...
@@ -34,7 +34,7 @@ module.exports = {
},
},
encodeFunctionId
:
function
(
funABI
)
{
encodeFunctionId
:
function
(
funABI
)
{
if
(
funABI
.
type
===
'fallback'
)
return
'0x'
if
(
funABI
.
type
===
'fallback'
||
funABI
.
type
===
'receive'
)
return
'0x'
let
abi
=
new
ethers
.
utils
.
Interface
([
funABI
])
let
abi
=
new
ethers
.
utils
.
Interface
([
funABI
])
abi
=
abi
.
functions
[
funABI
.
name
]
abi
=
abi
.
functions
[
funABI
.
name
]
return
abi
.
sighash
return
abi
.
sighash
...
@@ -53,10 +53,10 @@ module.exports = {
...
@@ -53,10 +53,10 @@ module.exports = {
return
-
1
return
-
1
}
}
// If we reach here, either a and b are both constant or both not; sort by name then
// If we reach here, either a and b are both constant or both not; sort by name then
// special case for fallback
and constructor
// special case for fallback
, receive and constructor function
if
(
a
.
type
===
'function'
&&
typeof
a
.
name
!==
'undefined'
)
{
if
(
a
.
type
===
'function'
&&
typeof
a
.
name
!==
'undefined'
)
{
return
a
.
name
.
localeCompare
(
b
.
name
)
return
a
.
name
.
localeCompare
(
b
.
name
)
}
else
if
(
a
.
type
===
'constructor'
||
a
.
type
===
'fallback'
)
{
}
else
if
(
a
.
type
===
'constructor'
||
a
.
type
===
'fallback'
||
a
.
type
===
'receive'
)
{
return
1
return
1
}
}
})
})
...
@@ -124,6 +124,14 @@ module.exports = {
...
@@ -124,6 +124,14 @@ module.exports = {
}
}
},
},
getReceiveInterface
:
function
(
abi
)
{
for
(
let
i
=
0
;
i
<
abi
.
length
;
i
++
)
{
if
(
abi
[
i
].
type
===
'receive'
)
{
return
abi
[
i
]
}
}
},
/**
/**
* return the contract obj of the given @arg name. Uses last compilation result.
* return the contract obj of the given @arg name. Uses last compilation result.
* return null if not found
* return null if not found
...
...
remix-lib/src/execution/txListener.js
View file @
807ffd97
...
@@ -291,6 +291,15 @@ class TxListener {
...
@@ -291,6 +291,15 @@ class TxListener {
return
this
.
_resolvedTransactions
[
tx
.
hash
]
return
this
.
_resolvedTransactions
[
tx
.
hash
]
}
}
}
}
// receive function
if
(
!
inputData
&&
txHelper
.
getReceiveInterface
(
abi
))
{
this
.
_resolvedTransactions
[
tx
.
hash
]
=
{
contractName
:
contractName
,
to
:
tx
.
to
,
fn
:
'(receive)'
,
params
:
null
}
}
else
{
// fallback function
// fallback function
this
.
_resolvedTransactions
[
tx
.
hash
]
=
{
this
.
_resolvedTransactions
[
tx
.
hash
]
=
{
contractName
:
contractName
,
contractName
:
contractName
,
...
@@ -298,6 +307,7 @@ class TxListener {
...
@@ -298,6 +307,7 @@ class TxListener {
fn
:
'(fallback)'
,
fn
:
'(fallback)'
,
params
:
null
params
:
null
}
}
}
}
else
{
}
else
{
const
bytecode
=
contract
.
object
.
evm
.
bytecode
.
object
const
bytecode
=
contract
.
object
.
evm
.
bytecode
.
object
let
params
=
null
let
params
=
null
...
...
remix-lib/src/universalDapp.js
View file @
807ffd97
...
@@ -253,6 +253,10 @@ module.exports = class UniversalDApp {
...
@@ -253,6 +253,10 @@ module.exports = class UniversalDApp {
return
txHelper
.
getFallbackInterface
(
contractABI
)
return
txHelper
.
getFallbackInterface
(
contractABI
)
}
}
getReceiveInterface
(
contractABI
)
{
return
txHelper
.
getReceiveInterface
(
contractABI
)
}
getInputs
(
funABI
)
{
getInputs
(
funABI
)
{
if
(
!
funABI
.
inputs
)
{
if
(
!
funABI
.
inputs
)
{
return
''
return
''
...
...
remix-lib/test/txFormat.js
View file @
807ffd97
...
@@ -243,14 +243,15 @@ function encodeFunctionCallTest (st) {
...
@@ -243,14 +243,15 @@ function encodeFunctionCallTest (st) {
/* *********************************************************** */
/* *********************************************************** */
tape
(
'test fallback function'
,
function
(
t
)
{
tape
(
'test fallback
& receive
function'
,
function
(
t
)
{
t
.
test
(
'(fallback)'
,
function
(
st
)
{
t
.
test
(
'(fallback)'
,
function
(
st
)
{
st
.
plan
(
2
)
st
.
plan
(
3
)
let
output
=
compiler
.
compile
(
compilerInput
(
fallbackFunction
))
let
output
=
compiler
.
compile
(
compilerInput
(
fallback
AndReceive
Function
))
output
=
JSON
.
parse
(
output
)
output
=
JSON
.
parse
(
output
)
const
contract
=
output
.
contracts
[
'test.sol'
][
'fallbackFunctionContract'
]
const
contract
=
output
.
contracts
[
'test.sol'
][
'fallbackAndReceiveFunctionContract'
]
st
.
equal
(
txHelper
.
encodeFunctionId
(
contract
.
abi
[
2
]),
'0x'
)
// for receive function
st
.
equal
(
txHelper
.
encodeFunctionId
(
contract
.
abi
[
1
]),
'0x805da4ad'
)
st
.
equal
(
txHelper
.
encodeFunctionId
(
contract
.
abi
[
1
]),
'0x805da4ad'
)
st
.
equal
(
txHelper
.
encodeFunctionId
(
contract
.
abi
[
0
]),
'0x'
)
st
.
equal
(
txHelper
.
encodeFunctionId
(
contract
.
abi
[
0
]),
'0x'
)
// for fallback function
})
})
})
})
...
@@ -381,13 +382,15 @@ contract testContractLinkLibrary {
...
@@ -381,13 +382,15 @@ contract testContractLinkLibrary {
}
}
}`
}`
const
fallbackFunction
=
`pragma solidity >= 0.5.0 < 0.7.0;
const
fallback
AndReceive
Function
=
`pragma solidity >= 0.5.0 < 0.7.0;
contract fallbackFunctionContract {
contract fallback
AndReceive
FunctionContract {
function get (uint _p, string memory _o) public {
function get (uint _p, string memory _o) public {
}
}
fallback () external {}
fallback () external {}
receive() payable external{}
}`
}`
const
abiEncoderV2
=
`pragma experimental ABIEncoderV2;
const
abiEncoderV2
=
`pragma experimental ABIEncoderV2;
...
...
remix-lib/test/txHelper.js
View file @
807ffd97
...
@@ -3,7 +3,7 @@ const tape = require('tape')
...
@@ -3,7 +3,7 @@ const tape = require('tape')
const
txHelper
=
require
(
'../src/execution/txHelper'
)
const
txHelper
=
require
(
'../src/execution/txHelper'
)
tape
(
'getFunction'
,
function
(
st
)
{
tape
(
'getFunction'
,
function
(
st
)
{
st
.
plan
(
5
)
st
.
plan
(
6
)
let
fn
=
txHelper
.
getFunction
(
JSON
.
parse
(
abi
),
'o((address,uint256))'
)
let
fn
=
txHelper
.
getFunction
(
JSON
.
parse
(
abi
),
'o((address,uint256))'
)
st
.
equal
(
fn
.
name
,
'o'
)
st
.
equal
(
fn
.
name
,
'o'
)
...
@@ -18,6 +18,9 @@ tape('getFunction', function (st) {
...
@@ -18,6 +18,9 @@ tape('getFunction', function (st) {
fn
=
txHelper
.
getFallbackInterface
(
JSON
.
parse
(
abi
))
fn
=
txHelper
.
getFallbackInterface
(
JSON
.
parse
(
abi
))
st
.
equal
(
fn
.
type
,
'fallback'
)
st
.
equal
(
fn
.
type
,
'fallback'
)
fn
=
txHelper
.
getReceiveInterface
(
JSON
.
parse
(
abi
))
st
.
equal
(
fn
.
type
,
'receive'
)
})
})
const
abi
=
`[
const
abi
=
`[
...
@@ -143,5 +146,10 @@ const abi = `[
...
@@ -143,5 +146,10 @@ const abi = `[
"payable": false,
"payable": false,
"stateMutability": "nonpayable",
"stateMutability": "nonpayable",
"type": "fallback"
"type": "fallback"
},
{
"payable": true,
"stateMutability": "payable",
"type": "receive"
}
}
]`
]`
remix-tests/src/types.ts
View file @
807ffd97
...
@@ -150,7 +150,7 @@ export type ABIDescription = FunctionDescription | EventDescription
...
@@ -150,7 +150,7 @@ export type ABIDescription = FunctionDescription | EventDescription
export
interface
FunctionDescription
{
export
interface
FunctionDescription
{
/** Type of the method. default is 'function' */
/** Type of the method. default is 'function' */
type
?:
'function'
|
'constructor'
|
'fallback'
type
?:
'function'
|
'constructor'
|
'fallback'
|
'receive'
/** The name of the function. Constructor and fallback function never have name */
/** The name of the function. Constructor and fallback function never have name */
name
?:
string
name
?:
string
/** List of parameters of the method. Fallback function doesn’t have inputs. */
/** List of parameters of the method. Fallback function doesn’t have inputs. */
...
...
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