Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.55 KB | None | 0 0
  1. pragma solidity ^0.4.4;
  2.  
  3.  
  4. // Base class for contracts that are used in a doug system.
  5. contract DougEnabled {
  6. address DOUG;
  7.  
  8. function setDougAddress(address dougAddr) public returns (bool result){
  9. // Once the doug address is set, don't allow it to be set again, except by the
  10. // doug contract itself.
  11. if(DOUG != 0x0 && msg.sender != DOUG){
  12. return false;
  13. }
  14. DOUG = dougAddr;
  15. return true;
  16. }
  17.  
  18. // Makes it so that Doug is the only contract that may kill it.
  19. function remove() public {
  20. if(msg.sender == DOUG){
  21. selfdestruct(DOUG);
  22. }
  23. }
  24.  
  25. }
  26.  
  27. // The Doug contract.
  28. contract Doug {
  29.  
  30. address owner;
  31.  
  32. // This is where we keep all the contracts.
  33. mapping (bytes32 => address) public contracts;
  34.  
  35. modifier onlyOwner { //a modifier to reduce code replication
  36. if (msg.sender == owner) // this ensures that only the owner can access the function
  37. _;
  38. }
  39. // Constructor
  40. function Doug() public {
  41. owner = msg.sender;
  42. }
  43.  
  44. // Add a new contract to Doug. This will overwrite an existing contract.
  45. function addContract(bytes32 name, address addr) onlyOwner public returns (bool result) {
  46. DougEnabled de = DougEnabled(addr);
  47. // Don't add the contract if this does not work.
  48. if(!de.setDougAddress(address(this))) {
  49. return false;
  50. }
  51. contracts[name] = addr;
  52. return true;
  53. }
  54.  
  55. // Remove a contract from Doug. We could also selfdestruct if we want to.
  56. function removeContract(bytes32 name) onlyOwner public returns (bool result) {
  57. if (contracts[name] == 0x0){
  58. return false;
  59. }
  60. contracts[name] = 0x0;
  61. return true;
  62. }
  63.  
  64. // Get the address of a contract by the name of the contract
  65. function getContract(bytes32 name) onlyOwner constant public returns (address addr) {
  66. return contracts[name];
  67. }
  68.  
  69. function remove() onlyOwner public {
  70. address lca = contracts["lcapplication"];
  71. address perms = contracts["perms"];
  72. address permsdb = contracts["permsdb"];
  73. address lc = contracts["letterofcredit"];
  74. address lcdb = contracts["letterofcreditdb"];
  75.  
  76. // Remove everything.
  77. if(lca != 0x0){ DougEnabled(lca).remove(); }
  78. if(perms != 0x0){ DougEnabled(perms).remove(); }
  79. if(permsdb != 0x0){ DougEnabled(permsdb).remove(); }
  80. if(lc != 0x0){ DougEnabled(lc).remove(); }
  81. if(lcdb != 0x0){ DougEnabled(lcdb).remove(); }
  82.  
  83. // Finally, remove doug. Doug will now have all the funds of the other contracts,
  84. // and when suiciding it will all go to the owner.
  85. selfdestruct(owner);
  86. }
  87. }
  88.  
  89. // The LC manager
  90. contract LCApplication is DougEnabled {
  91.  
  92. address owner;
  93.  
  94. // Constructor
  95. function LCApplication() public {
  96. owner = msg.sender;
  97. }
  98.  
  99. function getContractLetterOfCredit() private returns (address res) {
  100. return ContractProvider(DOUG).contracts("letterofcredit");
  101. }
  102.  
  103. // Attempt to create a letter of credit.
  104. function create(bytes32 purchaseOrder, uint price, address accountSeller) payable public returns (bool res) {
  105. if (msg.value == 0 || purchaseOrder == 0x0 || price == 0 || accountSeller == 0x0 ){
  106. return false;
  107. }
  108. address letterofcredit = getContractLetterOfCredit();
  109. address perms = ContractProvider(DOUG).contracts("perms");
  110. if ( letterofcredit == 0x0 || perms == 0x0 || Permissions(perms).getPermission(msg.sender) != 1) {
  111. // If the user sent money, we should return it if we can't deposit.
  112. if (!msg.sender.send(msg.value)){ throw; }
  113. return false;
  114. }
  115.  
  116. // Use the interface to call on the bank contract. We pass msg.value along as well.
  117. bool success = LetterOfCredit(letterofcredit).create.value(msg.value)(purchaseOrder, price, msg.sender, accountSeller);
  118.  
  119. // If the transaction failed, return the Ether to the caller.
  120. if (!success) {
  121. if (!msg.sender.send(msg.value)){ throw; }
  122. }
  123. return success;
  124. }
  125.  
  126. // Attempt to confirm the letter of credit
  127. function confirm() public returns (bool res) {
  128.  
  129. address letterofcredit = getContractLetterOfCredit();
  130. address perms = ContractProvider(DOUG).contracts("perms");
  131. if ( letterofcredit == 0x0 || perms == 0x0 || Permissions(perms).getPermission(msg.sender) != 3) {
  132. return false;
  133. }
  134.  
  135. // Use the interface to call on the bank contract.
  136. bool success = LetterOfCredit(letterofcredit).confirm();
  137.  
  138. return success;
  139. }
  140.  
  141. // Attempt to approve the letter of credit
  142. function approve() public returns (bool res) {
  143.  
  144. address letterofcredit = getContractLetterOfCredit();
  145. address perms = ContractProvider(DOUG).contracts("perms");
  146. if ( letterofcredit == 0x0 || perms == 0x0 || Permissions(perms).getPermission(msg.sender) != 4) {
  147. return false;
  148. }
  149.  
  150. // Use the interface to call on the bank contract.
  151. bool success = LetterOfCredit(letterofcredit).approve();
  152.  
  153. return success;
  154. }
  155.  
  156. // Attempt to ship the goods
  157. function ship(bytes32 packingSlip) public returns (bool res) {
  158. if (packingSlip == 0x0 ){
  159. return false;
  160. }
  161.  
  162. address letterofcredit = getContractLetterOfCredit();
  163. address perms = ContractProvider(DOUG).contracts("perms");
  164. if ( letterofcredit == 0x0 || perms == 0x0 || Permissions(perms).getPermission(msg.sender) != 2) {
  165. return false;
  166. }
  167.  
  168. // Use the interface to call on the bank contract.
  169. bool success = LetterOfCredit(letterofcredit).ship(packingSlip);
  170.  
  171. return success;
  172. }
  173.  
  174. // Attempt to invoice the buyer
  175. function invoice(bytes32 inv) public returns (bool res) {
  176. if (inv == 0x0 ){
  177. return false;
  178. }
  179.  
  180. address letterofcredit = getContractLetterOfCredit();
  181. address perms = ContractProvider(DOUG).contracts("perms");
  182. if ( letterofcredit == 0x0 || perms == 0x0 || Permissions(perms).getPermission(msg.sender) != 2) {
  183. return false;
  184. }
  185.  
  186. // Use the interface to call on the bank contract.
  187. bool success = LetterOfCredit(letterofcredit).invoice(inv);
  188.  
  189. return success;
  190. }
  191.  
  192. // Attempt to approve the release
  193. function approveRelease() public returns (bool res) {
  194.  
  195. address letterofcredit = getContractLetterOfCredit();
  196. address perms = ContractProvider(DOUG).contracts("perms");
  197. if ( letterofcredit == 0x0 || perms == 0x0 || Permissions(perms).getPermission(msg.sender) != 4) {
  198. return false;
  199. }
  200.  
  201. // Use the interface to call on the bank contract.
  202. bool success = LetterOfCredit(letterofcredit).approveRelease();
  203.  
  204. return success;
  205. }
  206.  
  207. // Attempt to release the funds of the letter of credit to the seller
  208. function releaseFunds() public returns (bool res) {
  209.  
  210. address letterofcredit = getContractLetterOfCredit();
  211. address perms = ContractProvider(DOUG).contracts("perms");
  212. if ( letterofcredit == 0x0 || perms == 0x0 || Permissions(perms).getPermission(msg.sender) != 3) {
  213. return false;
  214. }
  215.  
  216. // Use the interface to call on the bank contract.
  217. bool success = LetterOfCredit(letterofcredit).releaseFunds();
  218.  
  219. return success;
  220. }
  221.  
  222. function getPurchaseOrder() public returns (bytes32 po){
  223. address letterofcredit = getContractLetterOfCredit();
  224. address perms = ContractProvider(DOUG).contracts("perms");
  225. uint8 permsSender = Permissions(perms).getPermission(msg.sender);
  226. if ( letterofcredit == 0x0 || perms == 0x0 || permsSender < 1) {
  227. return 0x0;
  228. }
  229.  
  230. // Use the interface to call on the LetterOfCredit contract.
  231. bytes32 purchord = LetterOfCredit(letterofcredit).getPurchaseOrder(permsSender);
  232. return purchord;
  233. }
  234.  
  235. function getPrice() public returns (uint price){
  236. address letterofcredit = getContractLetterOfCredit();
  237. address perms = ContractProvider(DOUG).contracts("perms");
  238. uint8 permsSender = Permissions(perms).getPermission(msg.sender);
  239. if ( letterofcredit == 0x0 || perms == 0x0 || permsSender < 1) {
  240. return 0;
  241. }
  242.  
  243. // Use the interface to call on the LetterOfCredit contract.
  244. uint prc = LetterOfCredit(letterofcredit).getPrice(permsSender);
  245. return prc;
  246. }
  247.  
  248. // Set the permissions for a given address.
  249. function setPermission(address addr, uint8 perm) public returns (bool res) {
  250. if (msg.sender != owner){
  251. return false;
  252. }
  253. address perms = ContractProvider(DOUG).contracts("perms");
  254. if ( perms == 0x0 || Permissions(perms).getPermission(msg.sender) != 5 ) {
  255. return false;
  256. }
  257. return Permissions(perms).setPermission(addr,perm);
  258. }
  259.  
  260. // Get the permissions for a given address.
  261. function getPermission(address addr) public returns (uint8 perm) {
  262. if (msg.sender != owner){
  263. throw;
  264. }
  265. address perms = ContractProvider(DOUG).contracts("perms");
  266. if ( perms == 0x0 || Permissions(perms).getPermission(msg.sender) != 5 ) {
  267. throw;
  268. }
  269. return Permissions(perms).getPermission(addr);
  270. }
  271.  
  272. }
  273.  
  274. // Interface for getting contracts from Doug
  275. contract ContractProvider {
  276. function contracts(bytes32 name) public returns (address addr){}
  277. }
  278.  
  279. // Base class for contracts that only allow the fundmanager to call them.
  280. // Note that it inherits from DougEnabled
  281. contract LCApplicationEnabled is DougEnabled {
  282.  
  283. // Makes it easier to check that fundmanager is the caller.
  284. function isLCApplication() public returns (bool res) {
  285. if(DOUG != 0x0){
  286. address lca = ContractProvider(DOUG).contracts("lcapplication");
  287. return msg.sender == lca;
  288. }
  289. return false;
  290. }
  291. }
  292.  
  293. contract LCStateEnabled {
  294.  
  295. enum States {
  296. New,
  297. Created,
  298. Confirmed,
  299. Approved,
  300. Shipped,
  301. Invoiced,
  302. ReleaseApproved,
  303. Released,
  304. Completed
  305. }
  306.  
  307. States public state;
  308.  
  309. modifier atState(States _state){
  310. if (state != _state){
  311. return;
  312. }
  313. _;
  314. }
  315.  
  316. // This modifier goes to the next state
  317. // after the function is done.
  318. modifier transitionNext(){
  319. _;
  320. nextState();
  321. }
  322.  
  323.  
  324. function nextState() internal {
  325. state = States(uint(state) + 1);
  326. }
  327.  
  328. event Created();
  329. event Confirmed();
  330. event Approved();
  331. event Shipped();
  332. event Invoiced();
  333. event ReleaseApproved();
  334. event Released();
  335.  
  336. }
  337.  
  338. contract LCAuthorizationEnabled {
  339. // Check that the function is called from
  340. // a certain address
  341. modifier onlyBy(address _account)
  342. {
  343. if(msg.sender != _account){
  344. return;
  345. }
  346. _;
  347. }
  348.  
  349. }
  350.  
  351. contract LetterOfCredit is LCApplicationEnabled, LCAuthorizationEnabled {
  352.  
  353.  
  354. function getContractLetterOfCreditDb() private returns (address res) {
  355. return ContractProvider(DOUG).contracts("letterofcreditdb");
  356. }
  357.  
  358. function create (bytes32 purchaseOrder, uint price, address accountBuyer, address accountSeller) payable public returns (bool res) {
  359. if (!isLCApplication()){
  360. return false;
  361. }
  362.  
  363. address letterofcreditdb = getContractLetterOfCreditDb();
  364. if ( letterofcreditdb == 0x0 ) {
  365. // If the user sent money, we should return it if we can't deposit.
  366. if (!msg.sender.send(msg.value)){ throw; }
  367. return false;
  368. }
  369.  
  370. // Use the interface to call on the letter of credit contract. We pass msg.value along as well.
  371. bool success = LetterOfCreditDb(letterofcreditdb).create.value(msg.value)(purchaseOrder, price, accountBuyer, accountSeller);
  372.  
  373. // If the transaction failed, return the Ether to the caller.
  374. if (!success) {
  375. if (!msg.sender.send(msg.value)){ throw; }
  376. }
  377.  
  378. return success;
  379. }
  380.  
  381. function confirm() public returns (bool res) {
  382. if (!isLCApplication()){
  383. return false;
  384. }
  385.  
  386. address letterofcreditdb = getContractLetterOfCreditDb();
  387. if ( letterofcreditdb == 0x0 ) {
  388. return false;
  389. }
  390.  
  391. // Use the interface to call on the letter of credit contract. We pass msg.value along as well.
  392. return LetterOfCreditDb(letterofcreditdb).confirm();
  393. }
  394.  
  395. function approve() public returns (bool res) {
  396. if (!isLCApplication()){
  397. return false;
  398. }
  399.  
  400. address letterofcreditdb = getContractLetterOfCreditDb();
  401. if ( letterofcreditdb == 0x0 ) {
  402. return false;
  403. }
  404.  
  405. // Use the interface to call on the letter of credit contract. We pass msg.value along as well.
  406. return LetterOfCreditDb(letterofcreditdb).approve();
  407. }
  408.  
  409. function ship(bytes32 packingSlip) public returns (bool res) {
  410. if (!isLCApplication()){
  411. return false;
  412. }
  413.  
  414. address letterofcreditdb = getContractLetterOfCreditDb();
  415. if ( letterofcreditdb == 0x0 ) {
  416. return false;
  417. }
  418.  
  419. // Use the interface to call on the letter of credit contract. We pass msg.value along as well.
  420. return LetterOfCreditDb(letterofcreditdb).ship(packingSlip);
  421.  
  422. }
  423.  
  424. function invoice(bytes32 inv) public returns (bool res) {
  425. if (!isLCApplication()){
  426. return false;
  427. }
  428.  
  429. address letterofcreditdb = getContractLetterOfCreditDb();
  430. if ( letterofcreditdb == 0x0 ) {
  431. return false;
  432. }
  433.  
  434. // Use the interface to call on the letter of credit contract. We pass msg.value along as well.
  435. return LetterOfCreditDb(letterofcreditdb).invoice(inv);
  436.  
  437. }
  438.  
  439. function approveRelease() public returns (bool res) {
  440. if (!isLCApplication()){
  441. return false;
  442. }
  443.  
  444. address letterofcreditdb = getContractLetterOfCreditDb();
  445. if ( letterofcreditdb == 0x0 ) {
  446. return false;
  447. }
  448.  
  449. // Use the interface to call on the letter of credit contract. We pass msg.value along as well.
  450. return LetterOfCreditDb(letterofcreditdb).approveRelease();
  451.  
  452. }
  453.  
  454. function releaseFunds() public returns (bool res) {
  455. if (!isLCApplication()){
  456. return false;
  457. }
  458.  
  459. address letterofcreditdb = getContractLetterOfCreditDb();
  460. if ( letterofcreditdb == 0x0 ) {
  461. return false;
  462. }
  463.  
  464. // Use the interface to call on the letter of credit contract.
  465. return LetterOfCreditDb(letterofcreditdb).releaseFunds();
  466.  
  467. }
  468.  
  469. function getPurchaseOrder(uint8 perms) public returns (bytes32 po) {
  470. if (!isLCApplication()){
  471. throw;
  472. }
  473.  
  474. address letterofcreditdb = getContractLetterOfCreditDb();
  475. if ( letterofcreditdb == 0x0 ) {
  476. return 0x0;
  477. }
  478.  
  479. return LetterOfCreditDb(letterofcreditdb).getPurchaseOrder(perms);
  480. }
  481.  
  482. function getPrice(uint8 perms) public returns (uint price) {
  483. if (!isLCApplication()){
  484. throw;
  485. }
  486.  
  487. address letterofcreditdb = getContractLetterOfCreditDb();
  488. if ( letterofcreditdb == 0x0 ) {
  489. return 0x0;
  490. }
  491.  
  492. return LetterOfCreditDb(letterofcreditdb).getPrice(perms);
  493. }
  494.  
  495. function getPackingSlip() public returns (bytes32 po) {
  496. if (!isLCApplication()){
  497. throw;
  498. }
  499.  
  500. address letterofcredit = ContractProvider(DOUG).contracts("letterofcredit");
  501. if ( letterofcredit == 0x0 ) {
  502. return "";
  503. }
  504. return LetterOfCreditDb(letterofcredit).getPackingSlip();
  505. }
  506.  
  507. function getInvoice() public returns (bytes32 po) {
  508. if (!isLCApplication()){
  509. throw;
  510. }
  511.  
  512. address letterofcredit = ContractProvider(DOUG).contracts("letterofcredit");
  513. if ( letterofcredit == 0x0 ) {
  514. return "";
  515. }
  516. return LetterOfCreditDb(letterofcredit).getInvoice();
  517. }
  518.  
  519. }
  520.  
  521. contract LetterOfCreditDb is DougEnabled {
  522.  
  523. enum States {
  524. New,
  525. Created,
  526. Confirmed,
  527. Approved,
  528. Shipped,
  529. Invoiced,
  530. ReleaseApproved,
  531. Released,
  532. Completed
  533. }
  534.  
  535. States public state;
  536.  
  537. modifier atState(States _state){
  538. if (state != _state){
  539. return;
  540. }
  541. _;
  542. }
  543.  
  544. // This modifier goes to the next state
  545. // after the function is done.
  546. modifier transitionNext(){
  547. _;
  548. nextState();
  549. }
  550.  
  551. modifier allowReadRequirements(uint perms){
  552. // advising bank can only view requiremnts after confirmation of issuing bank, so state Confirmed or later
  553. if (perms == 4 && ( state == States.New || state == States.Created) ){
  554. return;
  555. }
  556. // seller (exporter) can only view requiremnts after approval of advising bank, so state Approved or later
  557. if (perms == 2 && ( state == States.New || state != States.Created || state != States.Confirmed) ) {
  558. return;
  559. }
  560.  
  561. _;
  562. }
  563.  
  564.  
  565. function nextState() internal {
  566. state = States(uint(state) + 1);
  567. }
  568.  
  569. event Created();
  570. event Confirmed();
  571. event Approved();
  572. event Shipped();
  573. event Invoiced();
  574. event ReleaseApproved();
  575. event Released();
  576.  
  577.  
  578. address public owner;
  579.  
  580. address public buyer;
  581. address public seller;
  582. uint public balance;
  583.  
  584. bytes32 refPurchaseOrder;
  585. bytes32 refPackingSlip;
  586. bytes32 refInvoice;
  587.  
  588. uint purchasePrice;
  589.  
  590. function LetterOfCreditDb () public {
  591. owner = msg.sender;
  592. state = States.New;
  593. }
  594.  
  595. function create(bytes32 purchaseOrder, uint price, address accountBuyer, address accountSeller) atState(States.New) payable public returns (bool res ){
  596. if(DOUG != 0x0){
  597. address letterofcredit = ContractProvider(DOUG).contracts("letterofcredit");
  598. if (msg.sender == letterofcredit ){
  599. buyer = accountBuyer;
  600. seller = accountSeller;
  601. balance = msg.value;
  602. purchasePrice = price;
  603. refPurchaseOrder = purchaseOrder;
  604. state = States.Created;
  605. Created();
  606. return true;
  607. }
  608. }
  609.  
  610. // Return if deposit cannot be made.
  611. if (!msg.sender.send(msg.value)){ throw; }
  612. return false;
  613. }
  614.  
  615. function confirm() atState(States.Created) public returns (bool res ){
  616. if(DOUG != 0x0){
  617. address letterofcredit = ContractProvider(DOUG).contracts("letterofcredit");
  618. if (msg.sender == letterofcredit ){
  619. state = States.Confirmed;
  620. Confirmed();
  621. return true;
  622. }
  623. }
  624. return false;
  625. }
  626.  
  627. function approve() atState(States.Confirmed) public returns (bool res ){
  628. if(DOUG != 0x0){
  629. address letterofcredit = ContractProvider(DOUG).contracts("letterofcredit");
  630. if (msg.sender == letterofcredit ){
  631. state = States.Approved;
  632. Approved();
  633. return true;
  634. }
  635. }
  636. return false;
  637. }
  638.  
  639. function ship(bytes32 packingSlip) atState(States.Approved) public returns (bool res ){
  640. if(DOUG != 0x0){
  641. address letterofcredit = ContractProvider(DOUG).contracts("letterofcredit");
  642. if (msg.sender == letterofcredit ){
  643. refPackingSlip = packingSlip;
  644. state = States.Shipped;
  645. Shipped();
  646. return true;
  647. }
  648. }
  649. return false;
  650. }
  651.  
  652. function invoice(bytes32 inv) atState(States.Shipped) public returns (bool res ){
  653. if(DOUG != 0x0){
  654. address letterofcredit = ContractProvider(DOUG).contracts("letterofcredit");
  655. if (msg.sender == letterofcredit ){
  656. refInvoice = inv;
  657. state = States.Invoiced;
  658. Invoiced();
  659. return true;
  660. }
  661. }
  662. return false;
  663. }
  664.  
  665. function approveRelease() atState(States.Invoiced) public returns (bool res ){
  666. if(DOUG != 0x0){
  667. address letterofcredit = ContractProvider(DOUG).contracts("letterofcredit");
  668. if (msg.sender == letterofcredit ){
  669. state = States.ReleaseApproved;
  670. ReleaseApproved();
  671. return true;
  672. }
  673. }
  674. return false;
  675. }
  676.  
  677. function releaseFunds() atState(States.ReleaseApproved) public payable returns (bool res) {
  678.  
  679. // CONDITIONS
  680.  
  681. if(DOUG != 0x0){
  682.  
  683. address letterofcredit = ContractProvider(DOUG).contracts("letterofcredit");
  684.  
  685. if (msg.sender == letterofcredit ){
  686.  
  687. uint oldBalance = balance;
  688.  
  689. if(oldBalance >= purchasePrice){
  690.  
  691. // EFFECTS
  692. balance = oldBalance - purchasePrice;
  693. state = States.Released;
  694.  
  695. // INTERACTION
  696. if (!seller.send(purchasePrice)){ throw; }
  697. if (!buyer.send(balance)){ throw; } // Transfer the possible remaining balance to the buyer
  698. Released(); // event
  699.  
  700. return true;
  701. }
  702. }
  703. }
  704. return false;
  705. }
  706.  
  707. function getState() constant public returns (States stat) {
  708. return state;
  709. }
  710.  
  711. function getPurchaseOrder(uint8 perms) allowReadRequirements(perms) constant public returns (bytes32 po) {
  712. return refPurchaseOrder;
  713. }
  714.  
  715. function getPrice(uint8 perms) allowReadRequirements(perms) constant public returns (uint price) {
  716. return purchasePrice;
  717. }
  718.  
  719. function getPackingSlip() constant public returns (bytes32 pks) {
  720. return refPackingSlip;
  721. }
  722.  
  723. function getInvoice() constant public returns (bytes32 inv) {
  724. return refInvoice;
  725. }
  726. }
  727.  
  728. // Permissions database
  729. contract PermissionsDb is DougEnabled {
  730.  
  731. mapping (address => uint8) public perms;
  732.  
  733. function PermissionsDb() public {
  734. perms[msg.sender] = 5; // owner gets super permissions
  735. }
  736.  
  737. // Set the permissions of an account.
  738. function setPermission(address addr, uint8 perm) public returns (bool res) {
  739. if(DOUG != 0x0){
  740. address permC = ContractProvider(DOUG).contracts("perms");
  741. if (msg.sender == permC ){
  742. perms[addr] = perm;
  743. return true;
  744. }
  745. return false;
  746. } else {
  747. return false;
  748. }
  749. }
  750.  
  751. // Get the permissions of an account.
  752. function getPermission(address addr) public returns (uint8 res) {
  753. if(DOUG != 0x0){
  754. address permC = ContractProvider(DOUG).contracts("perms");
  755. if (msg.sender == permC ){
  756. return perms[addr];
  757. }
  758. throw;
  759. } else {
  760. throw;
  761. }
  762. }
  763.  
  764.  
  765. }
  766.  
  767. // Permissions
  768. contract Permissions is LCApplicationEnabled {
  769.  
  770. // Set the permissions of an account.
  771. function setPermission(address addr, uint8 perm) public returns (bool res) {
  772. if (!isLCApplication()){
  773. return false;
  774. }
  775. address permdb = ContractProvider(DOUG).contracts("permsdb");
  776. if ( permdb == 0x0 ) {
  777. return false;
  778. }
  779. return PermissionsDb(permdb).setPermission(addr, perm);
  780. }
  781.  
  782. // Set the permissions of an account.
  783. function getPermission(address addr) public returns (uint8 res) {
  784. if (!isLCApplication()){
  785. throw;
  786. }
  787. address permdb = ContractProvider(DOUG).contracts("permsdb");
  788. if ( permdb == 0x0 ) {
  789. throw;
  790. }
  791. return PermissionsDb(permdb).getPermission(addr);
  792. }
  793. }
  794.  
  795.  
  796. jobs:
  797.  
  798. - name: addrSuperAccount
  799. job:
  800. set:
  801. val: F1925F5F1FAECA776B1340015F38C88008DE3089
  802.  
  803. - name: addrBuyer
  804. job:
  805. set:
  806. val: 0ABD37F8D497A2264AAB0DC4A1A58DBA7115F916
  807.  
  808. - name: addrSeller
  809. job:
  810. set:
  811. val: DA3C76F15BD6902072FA92B869F45F38AF5F92F1
  812.  
  813. - name: addrIssuingBank
  814. job:
  815. set:
  816. val: 096957107AD460D9703FDA86CD14B4C1FB22A10E
  817.  
  818. - name: addrAdvisingBank
  819. job:
  820. set:
  821. val: D6EEBF4818185C65544EB0FE2839607400589D06
  822.  
  823. - name: deployDoug
  824. job:
  825. deploy:
  826. contract: letterofcredit.sol
  827. instance: Doug
  828.  
  829. - name: deployLetterOfCredit
  830. job:
  831. deploy:
  832. contract: letterofcredit.sol
  833. instance: LetterOfCredit
  834.  
  835. - name: deployLetterOfCreditDb
  836. job:
  837. deploy:
  838. contract: letterofcredit.sol
  839. instance: LetterOfCreditDb
  840.  
  841. - name: deployLCApplication
  842. job:
  843. deploy:
  844. contract: letterofcredit.sol
  845. instance: LCApplication
  846.  
  847. - name: deployPermissions
  848. job:
  849. deploy:
  850. contract: letterofcredit.sol
  851. instance: Permissions
  852.  
  853. - name: deployPermissionsDb
  854. job:
  855. deploy:
  856. contract: letterofcredit.sol
  857. instance: PermissionsDb
  858.  
  859. - name: callSetDougLetterOfCredit
  860. job:
  861. call:
  862. destination: $deployLetterOfCredit
  863. function: setDougAddress
  864. data:
  865. - $deployDoug
  866.  
  867. - name: callSetDougLetterOfCreditDb
  868. job:
  869. call:
  870. destination: $deployLetterOfCreditDb
  871. function: setDougAddress
  872. data:
  873. - $deployDoug
  874.  
  875. - name: callSetDougLCApplication
  876. job:
  877. call:
  878. destination: $deployLCApplication
  879. function: setDougAddress
  880. data:
  881. - $deployDoug
  882.  
  883. - name: callAddContractLetterOfCredit
  884. job:
  885. call:
  886. destination: $deployDoug
  887. function: addContract
  888. data:
  889. - "letterofcredit"
  890. - $deployLetterOfCredit
  891.  
  892. - name: callAddContractLetterOfCreditDb
  893. job:
  894. call:
  895. destination: $deployDoug
  896. function: addContract
  897. data:
  898. - "letterofcreditdb"
  899. - $deployLetterOfCreditDb
  900.  
  901. - name: callAddContractLCApplication
  902. job:
  903. call:
  904. destination: $deployDoug
  905. function: addContract
  906. data:
  907. - "lcapplication"
  908. - $deployLCApplication
  909.  
  910. - name: callAddContractPermissions
  911. job:
  912. call:
  913. destination: $deployDoug
  914. function: addContract
  915. data:
  916. - "perms"
  917. - $deployPermissions
  918.  
  919. - name: callAddContractPermissionsDb
  920. job:
  921. call:
  922. destination: $deployDoug
  923. function: addContract
  924. data:
  925. - "permsdb"
  926. - $deployPermissionsDb
  927.  
  928. - name: callGetContractLetterOfCredit
  929. job:
  930. call:
  931. destination: $deployDoug
  932. function: getContract
  933. data:
  934. - "letterofcredit"
  935.  
  936. - name: callGetContractLetterOfCreditDb
  937. job:
  938. call:
  939. destination: $deployDoug
  940. function: getContract
  941. data:
  942. - "letterofcreditdb"
  943.  
  944. - name: callGetContractLCApplication
  945. job:
  946. call:
  947. destination: $deployDoug
  948. function: getContract
  949. data:
  950. - "lcapplication"
  951.  
  952. - name: callGetContractPermissions
  953. job:
  954. call:
  955. destination: $deployDoug
  956. function: getContract
  957. data:
  958. - "perms"
  959.  
  960. - name: callGetContractPermissionsDb
  961. job:
  962. call:
  963. destination: $deployDoug
  964. function: getContract
  965. data:
  966. - "permsdb"
  967.  
  968. - name: assertContractLetterOfCredit
  969. job:
  970. assert:
  971. key: $callGetContractLetterOfCredit
  972. relation: eq
  973. val: $deployLetterOfCredit
  974.  
  975. - name: assertContractLetterOfCreditDb
  976. job:
  977. assert:
  978. key: $callGetContractLetterOfCreditDb
  979. relation: eq
  980. val: $deployLetterOfCreditDb
  981.  
  982. - name: assertContractLCApplication
  983. job:
  984. assert:
  985. key: $callGetContractLCApplication
  986. relation: eq
  987. val: $deployLCApplication
  988.  
  989. - name: assertContractPermissions
  990. job:
  991. assert:
  992. key: $callGetContractPermissions
  993. relation: eq
  994. val: $deployPermissions
  995.  
  996. - name: assertContractPermissionsDb
  997. job:
  998. assert:
  999. key: $callGetContractPermissionsDb
  1000. relation: eq
  1001. val: $deployPermissionsDb
  1002.  
  1003. - name: callGetPermissionSelf
  1004. job:
  1005. call:
  1006. destination: $deployLCApplication
  1007. function: getPermission
  1008. data:
  1009. - $addrSuperAccount
  1010.  
  1011. - name: assertPermissionSelf
  1012. job:
  1013. assert:
  1014. key: $callGetPermissionSelf
  1015. relation: eq
  1016. val: 5
  1017.  
  1018. - name: callSetPermissionBuyer
  1019. job:
  1020. call:
  1021. destination: $deployLCApplication
  1022. function: setPermission
  1023. data:
  1024. - $addrBuyer
  1025. - 1
  1026.  
  1027. - name: callSetPermissionSeller
  1028. job:
  1029. call:
  1030. destination: $deployLCApplication
  1031. function: setPermission
  1032. data:
  1033. - $addrSeller
  1034. - 2
  1035.  
  1036. - name: callSetPermissionIssuingBank
  1037. job:
  1038. call:
  1039. destination: $deployLCApplication
  1040. function: setPermission
  1041. data:
  1042. - $addrIssuingBank
  1043. - 3
  1044.  
  1045. - name: callSetPermissionAdvisingBank
  1046. job:
  1047. call:
  1048. destination: $deployLCApplication
  1049. function: setPermission
  1050. data:
  1051. - $addrAdvisingBank
  1052. - 4
  1053.  
  1054. - name: callGetPermissionBuyer
  1055. job:
  1056. call:
  1057. destination: $deployLCApplication
  1058. function: getPermission
  1059. data:
  1060. - $addrBuyer
  1061.  
  1062. - name: callGetPermissionSeller
  1063. job:
  1064. call:
  1065. destination: $deployLCApplication
  1066. function: getPermission
  1067. data:
  1068. - $addrSeller
  1069.  
  1070. - name: callGetPermissionIssuingBank
  1071. job:
  1072. call:
  1073. destination: $deployLCApplication
  1074. function: getPermission
  1075. data:
  1076. - $addrIssuingBank
  1077.  
  1078. - name: callGetPermissionAdvisingBank
  1079. job:
  1080. call:
  1081. destination: $deployLCApplication
  1082. function: getPermission
  1083. data:
  1084. - $addrAdvisingBank
  1085.  
  1086. - name: assertPermissionBuyer
  1087. job:
  1088. assert:
  1089. key: $callGetPermissionBuyer
  1090. relation: eq
  1091. val: 1
  1092.  
  1093. - name: assertPermissionSeller
  1094. job:
  1095. assert:
  1096. key: $callGetPermissionSeller
  1097. relation: eq
  1098. val: 2
  1099.  
  1100. - name: assertPermissionIssuingBank
  1101. job:
  1102. assert:
  1103. key: $callGetPermissionIssuingBank
  1104. relation: eq
  1105. val: 3
  1106.  
  1107. - name: assertPermissionAdvisingBank
  1108. job:
  1109. assert:
  1110. key: $callGetPermissionAdvisingBank
  1111. relation: eq
  1112. val: 4
  1113.  
  1114. - name: accSuperAccount
  1115. job:
  1116. account:
  1117. address: $addrSuperAccount
  1118.  
  1119. - name: callGetBalance
  1120. job:
  1121. query-account:
  1122. account: $addrSuperAccount
  1123. field: balance
  1124.  
  1125. - name: callCreateLC
  1126. job:
  1127. call:
  1128. destination: $deployLCApplication
  1129. function: create
  1130. address: $addrBuyer
  1131. data:
  1132. - "purchaseorder"
  1133. - 100
  1134. - $addrSeller
  1135. amount: 10000
  1136.  
  1137. - name: callGetBalance
  1138. job:
  1139. query-account:
  1140. account: $addrSuperAccount
  1141. field: balance
  1142.  
  1143. - name: accBuyer
  1144. job:
  1145. account:
  1146. address: $addrBuyer
  1147.  
  1148. - name: callGetBalance
  1149. job:
  1150. query-account:
  1151. account: $addrBuyer
  1152. field: balance
  1153.  
  1154. - name: callCreateLC
  1155. job:
  1156. call:
  1157. destination: $deployLCApplication
  1158. function: create
  1159. address: $addrBuyer
  1160. data:
  1161. - "purchaseorder"
  1162. - 100
  1163. - $addrSeller
  1164. amount: 10000
  1165.  
  1166. - name: callGetBalance
  1167. job:
  1168. query-account:
  1169. account: $addrBuyer
  1170. field: balance
  1171.  
  1172. - name: accAdvisingBank
  1173. job:
  1174. account:
  1175. address: $addrAdvisingBank
  1176.  
  1177. - name: callGetPurchaseOrder
  1178. job:
  1179. call:
  1180. destination: $deployLCApplication
  1181. function: getPurchaseOrder
  1182.  
  1183. - name: accSeller
  1184. job:
  1185. account:
  1186. address: $addrSeller
  1187.  
  1188. - name: callGetPurchaseOrder
  1189. job:
  1190. call:
  1191. destination: $deployLCApplication
  1192. function: getPurchaseOrder
  1193.  
  1194. - name: callConfirm
  1195. job:
  1196. call:
  1197. destination: $deployLCApplication
  1198. function: confirm
  1199.  
  1200. - name: accIssuingBank
  1201. job:
  1202. account:
  1203. address: $addrIssuingBank
  1204.  
  1205. - name: callGetPurchaseOrder
  1206. job:
  1207. call:
  1208. destination: $deployLCApplication
  1209. function: getPurchaseOrder
  1210.  
  1211. - name: callGetPrice
  1212. job:
  1213. call:
  1214. destination: $deployLCApplication
  1215. function: getPrice
  1216.  
  1217. - name: callConfirm
  1218. job:
  1219. call:
  1220. destination: $deployLCApplication
  1221. function: confirm
  1222.  
  1223. - name: callApprove
  1224. job:
  1225. call:
  1226. destination: $deployLCApplication
  1227. function: approve
  1228.  
  1229. - name: accAdvisingBank
  1230. job:
  1231. account:
  1232. address: $addrAdvisingBank
  1233.  
  1234. - name: callGetPurchaseOrder
  1235. job:
  1236. call:
  1237. destination: $deployLCApplication
  1238. function: getPurchaseOrder
  1239.  
  1240. - name: callGetPrice
  1241. job:
  1242. call:
  1243. destination: $deployLCApplication
  1244. function: getPrice
  1245.  
  1246. - name: callApprove
  1247. job:
  1248. call:
  1249. destination: $deployLCApplication
  1250. function: approve
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement