Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions examples/operation/BatchSendOperator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pragma solidity 0.4.24;

import { ERC777Token } from "../ERC777/ERC777Token.sol";

// 批量操作
contract BatchSendOperator {
/// @notice Send tokens to multiple recipients.
/// @param _recipients The addresses of the recipients
/// @param _amounts The numbers of tokens to be transferred
function batchSend(address _tokenContract, address[] _recipients, uint256[] _amounts, bytes _userData) external {
require(_recipients.length == _amounts.length, "The lengths of _recipients and _amounts should be the same.");

ERC777Token tokenContract = ERC777Token(_tokenContract);
for (uint256 i = 0; i < _recipients.length; i++) {
tokenContract.operatorSend(msg.sender, _recipients[i], _amounts[i], _userData, "");
}
}
}
57 changes: 57 additions & 0 deletions examples/operation/Coupon.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
pragma solidity ^0.4.13;

// 票卷所有權轉移
contract Coupon {
// Configuration
uint256 public ID;
address public issuer;
address public owner;
uint256 public startTime;
uint256 public endTime;
uint256 public value;

// event
event ChangeOwnerToEvent(address new_owner);

// Functions with this modifier can only be executed by the owner
modifier onlyOwner(){
assert(owner == msg.sender);
_;
}

// Functions with this modifier can only be executed by the issuer
modifier onlyIssuer() {
assert(issuer == msg.sender);
_;
}

// Check whether the redeem time is between the span of startTime and endTime.
modifier isValidRedeemTime(){
require(startTime <= now);
require(endTime >= now);
_;
}

// Constructor
function Coupon(uint256 id, uint256 _startTime, uint256 _endTime, uint256 _value, address _issuer) {
require(_endTime >= _startTime);

ID = id;
issuer = _issuer; // issuer is default to be the owner of the coupon
owner = _issuer;
startTime = _startTime;
endTime = _endTime;
value = _value;
}

// receiver is the owner to be changed to
function changeOwnerTo(address receiver) public onlyOwner {
owner = receiver;
ChangeOwnerToEvent(receiver);
}

// transfer the coupon ownership
function transfer(address receiver) public onlyOwner {
changeOwnerTo(receiver);
}
}