Skip to content

Commit

Permalink
Update CrosschainControl.sol (#127)
Browse files Browse the repository at this point in the history
* Update CrosschainControl.sol

* Update CrosschainControl.sol

* Add itest

* Update config.yml

* Add failure cases

* Update config.yml

* Test using previous blockchain

* Revert "Test using previous blockchain"

This reverts commit dc8ba5b.

* Update CrosschainControl.sol

* Update CrosschainControl.sol

* Update CrosschainControl.sol

* Revert "Update CrosschainControl.sol"

This reverts commit b41a5f2.

* Code refactor, fix logging

* Remove resources + add nft bridge example

* Disable out failure case 2
  • Loading branch information
wcgcyx authored Jun 3, 2022
1 parent 4f83c06 commit 2914e83
Show file tree
Hide file tree
Showing 18 changed files with 2,579 additions and 4,390 deletions.
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,21 @@ jobs:
working_directory: test-blockchains
command: docker-compose stop
when: always
- run:
name: Create environment for testing JS-SDK
working_directory: sdk/js
background: true
command: npm install && docker-compose up
- run: sleep 30
- run:
name: Test JS-SDK
working_directory: sdk/js
command: node ./test.js
- run:
name: Stop environment for testing JS-SDK
working_directory: sdk/js
command: docker-compose stop
when: always
- run:
name: Logs from bc31
working_directory: test-blockchains
Expand Down
24 changes: 19 additions & 5 deletions contracts/contracts/src/functioncall/gpact/CrosschainControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ contract CrosschainControl is
_eventData,
_callPath,
hashOfCallGraph,
crosschainTransactionId
crosschainTransactionId,
false
)
) {
return;
Expand Down Expand Up @@ -328,7 +329,8 @@ contract CrosschainControl is
_eventData,
callPathForStart,
hashOfCallGraph,
crosschainTransactionId
crosschainTransactionId,
true
)
) {
return;
Expand Down Expand Up @@ -710,7 +712,8 @@ contract CrosschainControl is
bytes[] memory _segmentEvents,
uint256[] memory _callPath,
bytes32 _hashOfCallGraph,
uint256 _crosschainTxId
uint256 _crosschainTxId,
bool _asRoot
) private returns (bool) {
// The caller must be a segment that is calling other segments or the
// root call (which also is calling segments). The call path for the
Expand Down Expand Up @@ -784,9 +787,20 @@ contract CrosschainControl is
"Segment events array out of order"
);

// Fail the root transaction is one of the segments failed.
// Fail the root/segment transaction as one of the segments failed.
if (!success) {
failRootTransaction(_crosschainTxId);
if (_asRoot) {
failRootTransaction(_crosschainTxId);
} else {
emit Segment(
_crosschainTxId,
_hashOfCallGraph,
_callPath,
new address[](0),
false,
new bytes(0)
);
}
cleanupAfterCallSegment();
return true;
}
Expand Down
12 changes: 12 additions & 0 deletions examples/gpact/nft/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

task generateSources {
def script = "examples/gpact/nft/gen.sh".execute()
script.waitForProcessOutput(System.out, System.err)
if (script.exitValue() != 0) {
throw new GradleException("Solidity compile error")
}
}

project.afterEvaluate {
build.dependsOn generateSources
}
27 changes: 27 additions & 0 deletions examples/gpact/nft/contracts/src/CoinToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2022 ConsenSys Software Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
pragma solidity ^0.8.0;

import "../../../../../contracts/contracts/src/openzeppelin/token/ERC20/ERC20.sol";

contract CoinToken is ERC20 {
constructor(uint256 initialSupply) ERC20("Coin", "C$") {
_mint(msg.sender, initialSupply);
}

function decimals() public view virtual override returns (uint8) {
return 18;
}
}
98 changes: 98 additions & 0 deletions examples/gpact/nft/contracts/src/GameItem.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2022 ConsenSys Software Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
pragma solidity ^0.8.0;

import "../../../../../contracts/contracts/src/openzeppelin/token/ERC721/ERC721.sol";
import "../../../../../contracts/contracts/src/openzeppelin/token/ERC721/extensions/ERC721URIStorage.sol";
import "../../../../../contracts/contracts/src/openzeppelin/token/ERC721/extensions/ERC721Enumerable.sol";
import "../../../../../contracts/contracts/src/openzeppelin/utils/Counters.sol";

contract GameItem is ERC721URIStorage, ERC721Enumerable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;

// solhint-disable-next-line no-empty-blocks
constructor() ERC721("GameItem", "ITM") {}

function awardItem(address player) public returns (uint256) {
_tokenIds.increment();

uint256 newItemId = _tokenIds.current();
_mint(player, newItemId);

return newItemId;
}

function awardItem(address player, string calldata uri)
public
returns (uint256)
{
_tokenIds.increment();

uint256 newItemId = _tokenIds.current();
_mint(player, newItemId);
_setTokenURI(newItemId, uri);

return newItemId;
}

function findAllNFTsOwnedBy(address account)
public
view
returns (uint256[] memory)
{
uint256 count = balanceOf(account);
uint256[] memory nftIds = new uint256[](count);
for (uint256 i = 0; i < count; i++) {
uint256 id = tokenOfOwnerByIndex(account, i);
nftIds[i] = id;
}

return nftIds;
}

function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal override(ERC721, ERC721Enumerable) {
super._beforeTokenTransfer(from, to, tokenId);
}

function _burn(uint256 tokenId)
internal
override(ERC721, ERC721URIStorage)
{
super._burn(tokenId);
}

function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}

function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
Loading

0 comments on commit 2914e83

Please sign in to comment.