Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. pragma solidity ^0.4.2;
  2.  
  3. contract CBContract {
  4. /* Constructor */
  5. struct Option {
  6. address oa;
  7. uint op;
  8. }
  9.  
  10. struct Bond {
  11. address ba;
  12. uint bp;
  13. }
  14.  
  15. Option[] public o;
  16. Bond[] public b;
  17. mapping (address => uint) public option;
  18. mapping (address => uint) public bond;
  19.  
  20. function CBContract() {
  21. o.push(Option(0, 0));
  22. b.push(Bond(0, 0));
  23. }
  24. function BuyOption(uint optionPrice, uint optionAmount){
  25. uint c;
  26. for (uint count = 1; count <= optionAmount; count++){
  27. for (uint k = 0; k <= b.length-1; k++) {
  28. if (optionPrice + b[k].bp >= 100) {
  29. option[msg.sender]++;
  30. bond[b[k].ba]++;
  31. DeleteBond(k);
  32. c++;
  33. break;
  34. }
  35. }
  36. if (c == 0){
  37. o.push(Option(msg.sender, optionPrice));
  38. }
  39. }
  40. }
  41.  
  42. function BuyBond(uint bondPrice, uint bondAmount){
  43. uint c;
  44. for (uint count = 1; count <= bondAmount; count++){
  45. for (uint k = 0; k <= o.length-1; k++) {
  46. if (bondPrice + o[k].op >= 100) {
  47. bond[msg.sender]++;
  48. option[o[k].oa]++;
  49. DeleteOption(k);
  50. c++;
  51. break;
  52. }
  53. }
  54. if (c == 0){
  55. b.push(Bond(msg.sender, bondPrice));
  56. }
  57. }
  58. }
  59.  
  60.  
  61. function DeleteOption(uint deleteIndex){
  62. for (uint j = deleteIndex; j <= o.length-2; j++) {
  63. o[j] = o[j+1];
  64. }
  65. delete o[o.length-1];
  66. }
  67.  
  68. function DeleteBond(uint deleteIndex){
  69. for (uint j = deleteIndex; j <= b.length-2; j++) {
  70. b[j] = b[j+1];
  71. }
  72. delete b[o.length-1];
  73.  
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement