Quota Bank This contract demonstrates a simple quota bank that stakes to obtain quota for given address.
Copy
pragma soliditypp ^ 0.4.5 ;
contract DelegateStake {
address constant stakeContract = "vite_0000000000000000000000000000000000000003f6af7459b9" ;
tokenId constant viteTokenId = "tti_5649544520544f4b454e6e40" ;
address owner;
bytes32 hash;
message StakeForQuota ( address recipient) payable ;
mapping ( bytes32 => StakeInfo) stakeMap;
struct StakeInfo {
address addr;
bytes32 id;
uint256 amount;
}
event Stake ( address indexed addr, bytes32 id, uint256 amount) ;
constructor ( ) public payable {
owner = msg. sender;
}
onMessage ( ) payable { }
onMessage delegateStake ( address addr, uint256 amount) {
require ( owner == msg. sender && amount >= 134 vite) ;
hash = send ( stakeContract, StakeForQuota ( addr) , viteTokenId, amount) ;
stakeMap[ hash] = StakeInfo ( addr, hash, amount) ;
emit Stake ( addr, hash, amount) ;
}
getter getStakeInfo ( bytes32 hash) returns ( address addr, bytes32 id, uint256 amount) {
return ( stakeMap[ hash] . addr, stakeMap[ hash] . id, stakeMap[ hash] . amount) ;
}
getter getHash ( ) returns ( bytes32 ) {
return hash;
}
} Key Features onMessage () payable {}
the payment fallback message listener allows in-bound transfers.
hash = send(stakeContract, StakeForQuota(addr), viteTokenId, amount);
calls the built-in quota contract's StakeForQuota message listener. viteTokenId
and amount
specify the token type and amount sent with the call.
message StakeForQuota(address recipient) payable;
declares a payable StakeForQuota message, which matches the message listener with the same name in the built-in quota contract.