Skip to content

Commit

Permalink
rename bcos ledger contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Shareong committed May 14, 2020
1 parent e0de0cb commit bf8fea3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 46 deletions.
8 changes: 4 additions & 4 deletions demo/.prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ prepare_bcos()
LOG_INFO "Download HelloWeCross.sol ..."
cp ${WECROSS_ROOT}/src/main/resources/chains-sample/bcos/HelloWeCross.sol ./

LOG_INFO "Download bactool ..."
git clone --depth 1 https://github.com/Shareong/bactool.git
tar -zcf bactool.tar.gz bactool
rm -rf bactool
LOG_INFO "Download ledger-tool ..."
git clone --depth 1 https://github.com/Shareong/ledger-tool.git
tar -zcf ledger-tool.tar.gz ledger-tool
rm -rf ledger-tool

cd -
}
Expand Down
2 changes: 1 addition & 1 deletion demo/bcos/clear.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
if [ -e nodes/127.0.0.1/stop_all.sh ]; then
bash nodes/127.0.0.1/stop_all.sh
fi
rm -rf console ipconf nodes accounts bactool
rm -rf console ipconf nodes accounts ledger-tool
22 changes: 11 additions & 11 deletions demo/htlc_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ deploy_bcos_htlc()
cd bcos/console
rm -rf deploylog.txt
bash start.sh <<EOF
deploy BACHTLC
deploy LedgerSampleHTLC
EOF
BCOS_HTLC=$(grep 'BACHTLC' deploylog.txt | awk '{print $5}')
BCOS_HTLC=$(grep 'LedgerSampleHTLC' deploylog.txt | awk '{print $5}')
cd -
}

init_bcos_asset()
{
LOG_INFO "Init BCOS ledger ..."

# clone bactool
# clone ledger-tool
cd bcos
if [ -e bactool.tar.gz ]; then
rm -rf bactool
tar -zxf bactool.tar.gz
if [ -e ledger-tool.tar.gz ]; then
rm -rf ledger-tool
tar -zxf ledger-tool.tar.gz
else
git clone --depth 1 https://github.com/Shareong/bactool.git
git clone --depth 1 https://github.com/Shareong/ledger-tool.git
fi

cd bactool
cd ledger-tool
./gradlew build
cp ${ROOT}/bcos/nodes/127.0.0.1/sdk/* ${ROOT}/bcos/bactool/dist/conf
cp ${ROOT}/bcos/nodes/127.0.0.1/sdk/* ${ROOT}/bcos/ledger-tool/dist/conf
cd dist
java -cp 'apps/*:lib/*:conf' Application init 100000000 > tmp.txt
BCOS_LEDGER=$(grep 'assetAddress:' tmp.txt | awk '{print $2}')
Expand All @@ -61,7 +61,7 @@ init_bcos_bcos_htlc()

cd bcos/console
bash start.sh <<EOF
call BACHTLC ${BCOS_HTLC} init ["${BCOS_LEDGER}","${FABRIC_HTLC}"]
call LedgerSampleHTLC ${BCOS_HTLC} init ["${BCOS_LEDGER}","${FABRIC_HTLC}"]
EOF
cd -
}
Expand Down Expand Up @@ -144,7 +144,7 @@ config_bcos_sender_account()
{
LOG_INFO "Config account for BCOS htlc sender ..."
mkdir routers-payment/127.0.0.1-8250-25500/conf/accounts/bcos_sender
cp bcos/bactool/dist/conf/0x55f934bcbe1e9aef8337f5551142a442fdde781c.pem routers-payment/127.0.0.1-8250-25500/conf/accounts/bcos_sender
cp bcos/ledger-tool/dist/conf/0x55f934bcbe1e9aef8337f5551142a442fdde781c.pem routers-payment/127.0.0.1-8250-25500/conf/accounts/bcos_sender
cat << EOF > routers-payment/127.0.0.1-8250-25500/conf/accounts/bcos_sender/account.toml
[account]
type = 'BCOS2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,26 @@ contract Suspendable is SuspenderRole {
}
}

contract IBAC001Receiver {
contract ILedgerSampleReceiver {
/**
* @notice Handle the receipt of an NFT
* @dev The BAC001 smart contract calls this function on the recipient
* @dev The LedgerSample smart contract calls this function on the recipient
*/
function onBAC001Received(address operator, address from, uint256 value, bytes memory data)
function onLedgerSampleReceived(address operator, address from, uint256 value, bytes memory data)
public returns (bytes4);
}

contract BAC001Holder is IBAC001Receiver {
function onBAC001Received(address, address, uint256, bytes memory) public returns (bytes4) {
return this.onBAC001Received.selector;
contract LedgerSampleHolder is ILedgerSampleReceiver {
function onLedgerSampleReceived(address, address, uint256, bytes memory) public returns (bytes4) {
return this.onLedgerSampleReceived.selector;
}
}


/**
* @title Standard BAC001 asset
* @title Standard LedgerSample asset
*/
contract BAC001 is IssuerRole, Suspendable {
contract LedgerSample is IssuerRole, Suspendable {
using SafeMath for uint256;
using Address for address;

Expand All @@ -243,8 +243,8 @@ contract BAC001 is IssuerRole, Suspendable {
string private _shortName;
uint8 private _minUnit;

// Equals to `bytes4(keccak256("onBAC001Received(address,address,uint256,bytes)"))`
bytes4 private constant _BAC001_RECEIVED = 0xc73d16ae;
// Equals to `bytes4(keccak256("onLedgerSampleReceived(address,address,uint256,bytes)"))`
bytes4 private constant _LedgerSample_RECEIVED = 0xc73d16ae;


event Send( address indexed from, address indexed to, uint256 value, bytes data);
Expand Down Expand Up @@ -276,13 +276,13 @@ contract BAC001 is IssuerRole, Suspendable {

function send(address to, uint256 value, bytes data) public whenNotSuspended {
_send(msg.sender, to, value, data);
require(_checkOnBAC001Received(msg.sender, to, value, data), "BAC001: send to non BAC001Receiver implementer");
// require(_checkOnLedgerSampleReceived(msg.sender, to, value, data), "LedgerSample: send to non LedgerSampleReceiver implementer");

}

// function safeSend(address to, uint256 value, bytes data) public whenNotSuspended {
// send(to, value, data);
// require(_checkOnBAC001Received(msg.sender, to, value, data), "BAC001: send to non BAC001Receiver implementer");
// require(_checkOnLedgerSampleReceived(msg.sender, to, value, data), "LedgerSample: send to non LedgerSampleReceiver implementer");
// }


Expand All @@ -301,15 +301,15 @@ contract BAC001 is IssuerRole, Suspendable {
_send(from, to, value, data);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
//add
require(_checkOnBAC001Received(from, to, value, data), "BAC001: send to non BAC001Receiver implementer");
// require(_checkOnLedgerSampleReceived(from, to, value, data), "LedgerSample: send to non LedgerSampleReceiver implementer");


}

//// safe todo
// function safeSendFrom(address from, address to, uint256 value, bytes data) public whenNotSuspended {
// sendFrom(from, to, value, data);
// require(_checkOnBAC001Received(from, to, value, data), "BAC001: send to non BAC001Receiver implementer");
// require(_checkOnLedgerSampleReceived(from, to, value, data), "LedgerSample: send to non LedgerSampleReceiver implementer");
// }


Expand All @@ -327,15 +327,15 @@ contract BAC001 is IssuerRole, Suspendable {
}


function _checkOnBAC001Received(address from, address to, uint256 value, bytes data)
function _checkOnLedgerSampleReceived(address from, address to, uint256 value, bytes data)
internal returns (bool)
{
if (!to.isContract()) {
return true;
}

bytes4 retval = IBAC001Receiver(to).onBAC001Received(from, to, value, data);
return (retval == _BAC001_RECEIVED);
bytes4 retval = ILedgerSampleReceiver(to).onLedgerSampleReceived(from, to, value, data);
return (retval == _LedgerSample_RECEIVED);
}

/**
Expand Down Expand Up @@ -394,7 +394,7 @@ contract BAC001 is IssuerRole, Suspendable {
* @dev Send asset for a specified addresses.
*/
function _send(address from, address to, uint256 value, bytes data) internal {
require(to != address(0), "BAC001: send to the zero address");
require(to != address(0), "LedgerSample: send to the zero address");

_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
Expand All @@ -405,7 +405,7 @@ contract BAC001 is IssuerRole, Suspendable {
* @dev Internal function that issues an amount of the asset and assigns it to
*/
function _issue(address account, uint256 value, bytes data) internal {
require(account != address(0), "BAC001: issue to the zero address");
require(account != address(0), "LedgerSample: issue to the zero address");

_totalAmount = _totalAmount.add(value);
_balances[account] = _balances[account].add(value);
Expand All @@ -416,7 +416,7 @@ contract BAC001 is IssuerRole, Suspendable {
* @dev Internal function that destroys an amount of the asset of a given
*/
function _destroy(address account, uint256 value, bytes data) internal {
require(account != address(0), "BAC001: destroy from the zero address");
require(account != address(0), "LedgerSample: destroy from the zero address");

_totalAmount = _totalAmount.sub(value);
_balances[account] = _balances[account].sub(value);
Expand All @@ -427,8 +427,8 @@ contract BAC001 is IssuerRole, Suspendable {
* @dev Approve an address to spend another addresses' assets.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "BAC001: approve from the zero address");
require(spender != address(0), "BAC001: approve to the zero address");
require(owner != address(0), "LedgerSample: approve from the zero address");
require(spender != address(0), "LedgerSample: approve to the zero address");

_allowed[owner][spender] = value;
emit Approval( owner, spender, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;

import "./BAC001.sol";
import "./LedgerSample.sol";
import "./HTLC.sol";

contract BACHTLC is HTLC, BAC001Holder {
contract LedgerSampleHTLC is HTLC, LedgerSampleHolder {

// bac001 asset contract address
// asset contract address
address assetContract;

function init(string[] _ss)
Expand Down Expand Up @@ -39,14 +39,14 @@ contract BACHTLC is HTLC, BAC001Holder {
string memory _hash = _ss[0];
address sender = getSender(_hash);
uint amount = getAmount(_hash);
if (BAC001(assetContract).allowance(sender, address(this)) < uint(amount))
if (LedgerSample(assetContract).allowance(sender, address(this)) < uint(amount))
{
result[0] = "insufficient authorized assets";
return;
}

// This htlc contract becomes the temporary owner of the assets
BAC001(assetContract).sendFrom(sender, address(this), uint(amount),"");
LedgerSample(assetContract).sendFrom(sender, address(this), uint(amount),"");

setLockStatus(_hash);
result[0] = "success";
Expand All @@ -70,7 +70,7 @@ contract BACHTLC is HTLC, BAC001Holder {
// transfer from htlc contract to receiver
address receiver = getReceiver(_hash);
uint amount = getAmount(_hash);
BAC001(assetContract).send(receiver, uint(amount),"");
LedgerSample(assetContract).send(receiver, uint(amount),"");

setUnlockStatus(_hash);
setSecret(_ss);
Expand All @@ -94,7 +94,7 @@ contract BACHTLC is HTLC, BAC001Holder {
// transfer from htlc contract to sender
address sender = getSender(_hash);
uint amount = getAmount(_hash);
BAC001(assetContract).send(sender, uint(amount),"");
LedgerSample(assetContract).send(sender, uint(amount),"");

setRollbackStatus(_hash);
result[0] = "success";
Expand All @@ -106,7 +106,7 @@ contract BACHTLC is HTLC, BAC001Holder {
returns(string[] result)
{
result = new string[](1);
uint b = BAC001(assetContract).balance(stringToAddress(_ss[0]));
uint b = LedgerSample(assetContract).balance(stringToAddress(_ss[0]));
result[0] = uintToString(b);
}
}

0 comments on commit bf8fea3

Please sign in to comment.