3.1 Contract Sort

Contract is consist of three elements: MainChain gateway contract, SideChain gateway contract, Normal TRC20/TRC721 contract

3.2 MainChain gateway contract and SideChain gateway contract.

3.2.1 TRC20/TRC721 contract mapping:

//use mappingTRC20 for example
//Major-chain gateway contract methodology
operate mappingTRC20(bytes txId) public onlyNotStop onlyNotPause goDelegateCall payable returns (uint256) {
require(msg.worth >= mappingFee, "trc20MappingFee not sufficient");
if (msg.worth > 0) {
bonus += msg.worth;
}
tackle trc20Handle = calcContractAddress(txId, msg.sender);
require(trc20Handle != sunTokenAddress, "mainChainAddress == sunTokenAddress");
require(mainToSideContractMap[trc20Address] != 1, "trc20Handle mapped");
uint256 measurement;
meeting {measurement := extcodesize(trc20Handle)}
require(measurement > 0);
userMappingList.push(MappingMsg(trc20Handle, DataModel.TokenKind.TRC20, DataModel.Standing.SUCCESS));
mainToSideContractMap[trc20Address] = 1;
emit TRC20Mapping(trc20Handle, userMappingList.size - 1);
return userMappingList.size - 1;
}
//Aspect-chain gateway methodology
operate deployDAppTRC20AndMapping(tackle mainChainAddress, string identify, string image, uint8 decimals) inside returns (tackle r) {
tackle sideChainAddress = new DAppTRC20(tackle(this), identify, image, decimals);
mainToSideContractMap[mainChainAddress] = sideChainAddress;
sideToMainContractMap[sideChainAddress] = mainChainAddress;
emit DeployDAppTRC20AndMapping(mainChainAddress, sideChainAddress);
r = sideChainAddress;
}

TRC20/TRC721 contract proprietor has to place their contract deployment transaction id to MainChain gateway contract on main-chain. Gateway contract would confirm the existence of the transaction. A number of oracle will confirm and ensure the mapping operations and generate a corresponding TRC20/TRC721 contract on side-chain.

3.2.2 Asset deposit operation

//use depositTRX for example
//MainChain gateway contract methodology
operate depositTRX() payable public onlyNotStop onlyNotPause goDelegateCall returns (uint256) {
require(msg.worth > 0, "worth have to be > 0");
require(msg.worth >= depositMinTrx, "worth have to be >= depositMinTrx");
require(msg.worth <= uint64Max, "msg.worth should <= uint64Max");
userDepositList.push(DepositMsg(msg.sender, uint64(msg.worth), 0, tackle(0), 0, 0, 0));
emit TRXReceived(msg.sender, uint64(msg.worth), userDepositList.size - 1);
return userDepositList.size - 1;
}
//SideChain gateway contract methodology
operate depositTRX(tackle to, uint256 worth) inside {
mintTRXContract.name(worth);
to.switch(worth);
emit DepositTRX(to, worth);
}

When a person deposit TRX/TRC10/TRC20/TRC721 property, the property will probably be locked in main-chain gateway. On side-chain , a number of oracle will verify deposit operation, and side-chain gateway will mint new asset to person side-chain account.

3.2.Three Asset withdraw operation

//use withdrawTRX for example
//side-chain gateway contract methodology
operate withdrawTRX() payable public onlyNotPause onlyNotStop goDelegateCall returns (uint256 r) {
require(msg.worth >= withdrawMinTrx + withdrawFee, "worth have to be >= withdrawMinTrx+withdrawFee");
if (msg.worth > 0) {
bonus += withdrawFee;
}
uint256 withdrawValue = msg.worth - withdrawFee;
require(withdrawValue > 0, "withdrawValue have to be > 0");
userWithdrawList.push(WithdrawMsg(msg.sender, tackle(0), 0, withdrawValue, DataModel.TokenKind.TRX, DataModel.Standing.SUCCESS));
// burn
tackle(0).switch(withdrawValue);
emit WithdrawTRX(msg.sender, withdrawValue, userWithdrawList.size - 1);
r = userWithdrawList.size - 1;
}
//MainChain gateway contract methodology
operate withdrawTRX(tackle to, uint256 worth, uint256 nonce, bytes[] oracleSigns)
public onlyNotStop onlyOracle goDelegateCall {
require(oracleSigns.size <= numOracles, "withdraw TRX indicators num > oracles num");
bytes32 dataHash = keccak256(abi.encodePacked(to, worth, nonce));
bool needWithdraw = checkOracles(dataHash, nonce, oracleSigns);
if (needWithdraw) {
to.switch(worth);
// guarantee it is not reentrant
emit TRXWithdraw(to, worth, nonce);
}
}

Totally different from deposit and mapping, withdraw operation is triggered on side-chain. Just like deposit operation, person can use gateway contract to set off withdraw operation for his or her TRX/TRC10/TRC20/TRC721 property. Asset on side-chain will probably be destroyed when it leaving side-chain.

3.Three Aspect-chain commonplace

TRC20/TRC721 solely Implement TRON primary interfaces. And add two mint capabilities within the contract. Additionally add two commonplace withdraw operate for TRC20/TRC721 WI.

//Features in commonplace TRC20 contract
operate mint(tackle to, uint256 worth) exterior onlyGateway {
require(to != tackle(0));
_totalSupply = _totalSupply.add(worth);
​ _balances[to] = _balances[to].add(worth);
​ emit Switch(tackle(0), to, worth);
​ }
operate withdrawal(uint256 worth) payable exterior returns (uint256 r) {
​ switch(gateway, worth);
​ r = ITRC20Receiver(gateway).onTRC20Obtained.worth(msg.worth)(msg.sender, worth);
​ }
//Features in commonplace TRC721 contract
operate mint(tackle to, uint256 tokenId) exterior onlyGateway {
​ require(to != tackle(0));
​ require(!_exists(tokenId));
_tokenOwner[tokenId] = to;
​ _ownedTokensCount[to] = _ownedTokensCount[to].add(1);
emit Switch(tackle(0), to, tokenId);
​ }
operate withdrawal(uint256 tokenId) payable exterior returns (uint256 r) {
​ switch(gateway, tokenId);
​ r = ITRC721Receiver(gateway).onTRC721Obtained.worth(msg.worth)(msg.sender, tokenId);
​ }




Supply hyperlink

bitcoinBitcoin
$
10,517.42
$
10,517.42
1.11%
ethereumEthereum
$
177.51
$
177.51
0.15%
rippleXRP
$
0.259247
$
0.259247
0.09%
bitcoin-cashBitcoin Cash
$
297.03
$
297.03
0.49%
litecoinLitecoin
$
67.49
$
67.49
1.48%
tetherTether
$
0.999859
$
0.999859
0.03%
binancecoinBinance Coin
$
21.93
$
21.93
2.14%
eosEOS
$
3.33
$
3.33
0.01%
bitcoin-cash-svBitcoin SV
$
133.21
$
133.21
0.88%
cardanoCardano
$
0.045501
$
0.045501
1.17%