Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.2;
- contract CBContract {
- /* Constructor */
- struct Option {
- address oa;
- uint op;
- }
- struct Bond {
- address ba;
- uint bp;
- }
- Option[] public o;
- Bond[] public b;
- mapping (address => uint) public option;
- mapping (address => uint) public bond;
- function CBContract() {
- o.push(Option(0, 0));
- b.push(Bond(0, 0));
- }
- function BuyOption(uint optionPrice, uint optionAmount){
- uint c;
- for (uint count = 1; count <= optionAmount; count++){
- for (uint k = 0; k <= b.length-1; k++) {
- if (optionPrice + b[k].bp >= 100) {
- option[msg.sender]++;
- bond[b[k].ba]++;
- DeleteBond(k);
- c++;
- break;
- }
- }
- if (c == 0){
- o.push(Option(msg.sender, optionPrice));
- }
- }
- }
- function BuyBond(uint bondPrice, uint bondAmount){
- uint c;
- for (uint count = 1; count <= bondAmount; count++){
- for (uint k = 0; k <= o.length-1; k++) {
- if (bondPrice + o[k].op >= 100) {
- bond[msg.sender]++;
- option[o[k].oa]++;
- DeleteOption(k);
- c++;
- break;
- }
- }
- if (c == 0){
- b.push(Bond(msg.sender, bondPrice));
- }
- }
- }
- function DeleteOption(uint deleteIndex){
- for (uint j = deleteIndex; j <= o.length-2; j++) {
- o[j] = o[j+1];
- }
- delete o[o.length-1];
- }
- function DeleteBond(uint deleteIndex){
- for (uint j = deleteIndex; j <= b.length-2; j++) {
- b[j] = b[j+1];
- }
- delete b[o.length-1];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement