-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/signed-payload-2'
- Loading branch information
Showing
17 changed files
with
1,161 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* This smart contract code is Copyright 2017 TokenMarket Ltd. For more information see https://tokenmarket.net | ||
* | ||
* Licensed under the Apache License, version 2.0: https://github.com/TokenMarketNet/ico/blob/master/LICENSE.txt | ||
*/ | ||
|
||
pragma solidity ^0.4.8; | ||
|
||
import "./CrowdsaleBase.sol"; | ||
|
||
/** | ||
* A mixin that is selling tokens from a preallocated pool | ||
* | ||
* - Tokens have precreated supply "premined" | ||
* | ||
* - Token owner must transfer sellable tokens to the crowdsale contract using ERC20.approve() | ||
* | ||
* - The mixin does not implement buy entry point. | ||
* | ||
*/ | ||
contract AllocatedCrowdsaleMixin is CrowdsaleBase { | ||
|
||
/* The party who holds the full token pool and has approve()'ed tokens for this crowdsale */ | ||
address public beneficiary; | ||
|
||
/** | ||
* @param _beneficiary The account who has performed approve() to allocate tokens for the token sale. | ||
* | ||
*/ | ||
function AllocatedCrowdsaleMixin(address _beneficiary) { | ||
beneficiary = _beneficiary; | ||
} | ||
|
||
/** | ||
* Called from invest() to confirm if the curret investment does not break our cap rule. | ||
*/ | ||
function isBreakingCap(uint weiAmount, uint tokenAmount, uint weiRaisedTotal, uint tokensSoldTotal) constant returns (bool limitBroken) { | ||
if(tokenAmount > getTokensLeft()) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* We are sold out when our approve pool becomes empty. | ||
*/ | ||
function isCrowdsaleFull() public constant returns (bool) { | ||
return getTokensLeft() == 0; | ||
} | ||
|
||
/** | ||
* Get the amount of unsold tokens allocated to this contract; | ||
*/ | ||
function getTokensLeft() public constant returns (uint) { | ||
return token.allowance(owner, this); | ||
} | ||
|
||
/** | ||
* Transfer tokens from approve() pool to the buyer. | ||
* | ||
* Use approve() given to this crowdsale to distribute the tokens. | ||
*/ | ||
function assignTokens(address receiver, uint tokenAmount) internal { | ||
if(!token.transferFrom(beneficiary, receiver, tokenAmount)) throw; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* This smart contract code is Copyright 2017 TokenMarket Ltd. For more information see https://tokenmarket.net | ||
* | ||
* Licensed under the Apache License, version 2.0: https://github.com/TokenMarketNet/ico/blob/master/LICENSE.txt | ||
*/ | ||
|
||
/** | ||
* Deserialize bytes payloads. | ||
* | ||
* Values are in big-endian byte order. | ||
* | ||
*/ | ||
library BytesDeserializer { | ||
|
||
/** | ||
* Extract 256-bit worth of data from the bytes stream. | ||
*/ | ||
function slice32(bytes b, uint offset) constant returns (bytes32) { | ||
bytes32 out; | ||
|
||
for (uint i = 0; i < 32; i++) { | ||
out |= bytes32(b[offset + i] & 0xFF) >> (i * 8); | ||
} | ||
return out; | ||
} | ||
|
||
/** | ||
* Extract Ethereum address worth of data from the bytes stream. | ||
*/ | ||
function sliceAddress(bytes b, uint offset) constant returns (address) { | ||
bytes32 out; | ||
|
||
for (uint i = 0; i < 20; i++) { | ||
out |= bytes32(b[offset + i] & 0xFF) >> ((i+12) * 8); | ||
} | ||
return address(uint(out)); | ||
} | ||
|
||
/** | ||
* Extract 128-bit worth of data from the bytes stream. | ||
*/ | ||
function slice16(bytes b, uint offset) constant returns (bytes16) { | ||
bytes16 out; | ||
|
||
for (uint i = 0; i < 16; i++) { | ||
out |= bytes16(b[offset + i] & 0xFF) >> (i * 8); | ||
} | ||
return out; | ||
} | ||
|
||
/** | ||
* Extract 32-bit worth of data from the bytes stream. | ||
*/ | ||
function slice4(bytes b, uint offset) constant returns (bytes4) { | ||
bytes4 out; | ||
|
||
for (uint i = 0; i < 4; i++) { | ||
out |= bytes4(b[offset + i] & 0xFF) >> (i * 8); | ||
} | ||
return out; | ||
} | ||
|
||
/** | ||
* Extract 16-bit worth of data from the bytes stream. | ||
*/ | ||
function slice2(bytes b, uint offset) constant returns (bytes2) { | ||
bytes2 out; | ||
|
||
for (uint i = 0; i < 2; i++) { | ||
out |= bytes2(b[offset + i] & 0xFF) >> (i * 8); | ||
} | ||
return out; | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.