github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/xc/qtum/contracts/README.md (about)

     1  # XC
     2  
     3  ## Data Structs 
     4  
     5  ```
     6  
     7  /**
     8   * Data Structs
     9   */
    10  library Data {
    11  
    12      /**
    13       * Contract Administrator
    14       * @field status Contract external service status.
    15       * @field platformName Current contract platform name.
    16       * @field account Current contract administrator.
    17       */
    18      struct Admin {
    19          bool status;
    20          bytes32 platformName;
    21          address account;
    22      }
    23  
    24      /**
    25       * Transaction Proposal
    26       * @field status Transaction proposal status(false:pending,true:complete).
    27       * @field fromAccount Account of form platform.
    28       * @field toAccount Account of to platform.
    29       * @field value Transfer amount.
    30       * @field voters Proposers.
    31       */
    32      struct Proposal {
    33          bool status;
    34          address fromAccount;
    35          address toAccount;
    36          uint value;
    37          address[] voters;
    38      }
    39  
    40      /**
    41       * Trusted Platform
    42       * @field status Trusted platform state(false:no trusted,true:trusted).
    43       * @field weight weight of platform.
    44       * @field publicKeys list of public key.
    45       * @field proposals list of proposal.
    46       */
    47      struct Platform {
    48          bool status;
    49          uint weight;
    50          address[] publicKeys;
    51          mapping(string => Proposal) proposals;
    52      }
    53  }
    54  
    55  contract XCPlugin {
    56      Data.Admin private admin;
    57      mapping(bytes32 => Data.Platform) private platforms;
    58  }
    59  
    60  contract XC {
    61      Data.Admin private admin;
    62      uint public lockBalance;
    63  }
    64  ```
    65  
    66  > 1)Data.Admin : contract admin info
    67  > 
    68  > 2)Data.Platform : xc platform info
    69  >
    70  > 3)XCPlugin.platforms : trusted platforms
    71  > 
    72  > 4)XC.lockBalance : XC contract total lock amount
    73  > 
    74  
    75  remark:balanceOf Used for checking account transfer between various platforms.
    76  
    77  
    78  ## Event
    79  
    80  ```
    81  contract XC {
    82      event lockEvent(bytes32 toPlatform, address toAccount, string value);
    83      event unlockEvent(bytes32 txId, bytes32 fromPlatform, address fromAccount, string value);
    84  }
    85  ```
    86  
    87  > XC transaction trigger.
    88  
    89  ## Interface 
    90  
    91  ```
    92  /**
    93   * XC Contract Interface.
    94   */
    95  interface XCInterface {
    96  
    97      /**
    98       * Open the contract service status.
    99       */
   100      function start() external;
   101  
   102      /**
   103       * Close the contract service status.
   104       */
   105      function stop() external;
   106  
   107      /**
   108       * Get contract service status.
   109       * @return contract service status.
   110       */
   111      function getStatus() external constant returns (bool);
   112  
   113      /**
   114       * Destruction of the contract.
   115       */
   116      function kill() external;
   117  
   118      /**
   119       * Set the current contract platform name.
   120       * @param platformName platform name.
   121       */
   122      function setPlatformName(bytes32 platformName) external;
   123  
   124      /**
   125       * Get the current contract platform name.
   126       * @return contract platform name.
   127       */
   128      function getPlatformName() external constant returns (bytes32);
   129  
   130      /**
   131       * Set the current contract administrator.
   132       * @param account account of contract administrator.
   133       */
   134      function setAdmin(address account) external;
   135  
   136      /**
   137       * Get the current contract administrator.
   138       * @return contract administrator.
   139       */
   140      function getAdmin() external constant returns (address);
   141  
   142      /**
   143       * Set the INK contract address.
   144       * @param account contract address.
   145       */
   146      function setINK(address account) external;
   147  
   148      /**
   149       * Get the INK contract address.
   150       * @return contract address.
   151       */
   152      function getINK() external constant returns (address);
   153  
   154      /**
   155       * Set the XCPlugin contract address.
   156       * @param account contract address.
   157       */
   158      function setXCPlugin(address account) external;
   159  
   160      /**
   161       * Get the XCPlugin contract address.
   162       * @return contract address.
   163       */
   164      function getXCPlugin() external constant returns (address);
   165  
   166      /**
   167       * Transfer out of cross chain.
   168       * @param toPlatform name of to platform.
   169       * @param toAccount account of to platform.
   170       * @param value transfer amount.
   171       */
   172      function lock(bytes32 toPlatform, address toAccount, uint value) external payable;
   173  
   174      /**
   175       * Transfer in of cross chain.
   176       * @param txid transaction id.
   177       * @param fromPlatform name of form platform.
   178       * @param fromAccount ame of to platform.
   179       * @param toAccount account of to platform.
   180       * @param value transfer amount.
   181       */
   182      function unlock(string txid, bytes32 fromPlatform, address fromAccount, address toAccount, uint value) external payable;
   183  
   184      /**
   185       * Transfer the misoperation to the amount of the contract account to the specified account.
   186       * @param account the specified account.
   187       * @param value transfer amount.
   188       */
   189      function withdrawal(address account, uint value) external payable;
   190  
   191      /**
   192       * Administrator’s transfer out of cross chain.
   193       * @param toPlatform name of to platform.
   194       * @param toAccount account of to platform.
   195       * @param value transfer amount.
   196       */
   197      function lockAdmin(bytes32 toPlatform, address toAccount, uint value) external payable;
   198  
   199      /**
   200       * Administrator’s transfer in of cross chain.
   201       * @param txid transaction id.
   202       * @param fromPlatform name of form platform.
   203       * @param fromAccount ame of to platform.
   204       * @param toAccount account of to platform.
   205       * @param value transfer amount.
   206       */
   207      function unlockAdmin(string txid, bytes32 fromPlatform, address fromAccount, address toAccount, uint value) external payable;
   208  }
   209  ```
   210  > 1)setPlatformName & getPlatformName:Used to maintain the name of the contract platform.
   211  >
   212  > 2)start & stop & getStatus:Used to maintain contract service status.
   213  >
   214  > 3)setAdmin & getAdmin : Used to maintain contract administrators, transferable.
   215  >
   216  > 4)setINK、getINK、setXCPlugin、getXCPlugin : Used to maintain INK and XCPlugin contracts. can upgrade.
   217  >
   218  > 5)lockAdmin、unlockAdmin : Admin cross - chain ledger usage.
   219  >
   220  > 6)withdrawal : Used to extract the amount of money that someone has mistakenly transferred to a contract.
   221  >
   222  > 7)lock 和 unlock : Used for cross - chain transfer.
   223  > 
   224  
   225  remark:1)2)3)4)5)6)The administrator maintains the interface. 7)Open interface.
   226  
   227  ```
   228  /**
   229   * XC Plugin Contract Interface.
   230   */
   231  interface XCPluginInterface {
   232  
   233      /**
   234       * Open the contract service status.
   235       */
   236      function start() external;
   237  
   238      /**
   239       * Close the contract service status.
   240       */
   241      function stop() external;
   242  
   243      /**
   244       * Get contract service status.
   245       * @return contract service status.
   246       */
   247      function getStatus() external constant returns (bool);
   248  
   249      /**
   250       * Destruction of the contract.
   251       */
   252      function kill() external;
   253  
   254      /**
   255       * Set the current contract platform name.
   256       * @param platformName platform name.
   257       */
   258      function setPlatformName(bytes32 platformName) external;
   259  
   260      /**
   261       * Get the current contract platform name.
   262       * @return contract platform name.
   263       */
   264      function getPlatformName() external constant returns (bytes32);
   265  
   266      /**
   267       * Set the current contract administrator.
   268       * @param account account of contract administrator.
   269       */
   270      function setAdmin(address account) external;
   271  
   272      /**
   273       * Get the current contract administrator.
   274       * @return contract administrator.
   275       */
   276      function getAdmin() external constant returns (address);
   277  
   278      /**
   279       * Add a contract trust caller.
   280       * @param caller account of caller.
   281       */
   282      function addCaller(address caller) external;
   283  
   284      /**
   285       * Delete a contract trust caller.
   286       * @param caller account of caller.
   287       */
   288      function deleteCaller(address caller) external;
   289  
   290      /**
   291       * Whether the trust caller exists.
   292       * @param caller account of caller.
   293       * @return whether exists.
   294       */
   295      function existCaller(address caller) public constant returns (bool);
   296  
   297      /**
   298       * Get all contract trusted callers.
   299       * @return al lcallers.
   300       */
   301      function getCallers() external constant returns (address[]);
   302  
   303      /**
   304       * Add a trusted platform name.
   305       * @param name a platform name.
   306       */
   307      function addPlatform(bytes32 name) external;
   308  
   309      /**
   310       * Delete a trusted platform name.
   311       * @param name a platform name.
   312       */
   313      function deletePlatform(bytes32 name) external;
   314  
   315      /**
   316       * Whether the trusted platform information exists.
   317       * @param name a platform name.
   318       * @return whether exists.
   319       */
   320      function existPlatform(bytes32 name) public constant returns (bool);
   321  
   322      /**
   323       * Add the trusted platform public key information.
   324       * @param platformName a platform name.
   325       * @param publicKey a public key.
   326       */
   327      function addPublicKey(bytes32 platformName, address publicKey) external;
   328  
   329      /**
   330       * Delete the trusted platform public key information.
   331       * @param platformName a platform name.
   332       * @param publicKey a public key.
   333       */
   334      function deletePublicKey(bytes32 platformName, address publicKey) external;
   335  
   336      /**
   337       * Whether the trusted platform public key information exists.
   338       * @param platformName a platform name.
   339       * @param publicKey a public key.
   340       */
   341      function existPublicKey(bytes32 platformName, address publicKey) public constant returns (bool);
   342  
   343      /**
   344       * Get the count of public key for the trusted platform.
   345       * @param platformName a platform name.
   346       * @return count of public key.
   347       */
   348      function countOfPublicKey(bytes32 platformName) external constant returns (uint);
   349  
   350      /**
   351       * Get the list of public key for the trusted platform.
   352       * @param platformName a platform name.
   353       * @return list of public key.
   354       */
   355      function publicKeys(bytes32 platformName) external constant returns (address[]);
   356  
   357      /**
   358       * Set the weight of a trusted platform.
   359       * @param platformName a platform name.
   360       * @param weight weight of platform.
   361       */
   362      function setWeight(bytes32 platformName, uint weight) external;
   363  
   364      /**
   365       * Get the weight of a trusted platform.
   366       * @param platformName a platform name.
   367       * @return weight of platform.
   368       */
   369      function getWeight(bytes32 platformName) external constant returns (uint);
   370  
   371      /**
   372       * Initiate and vote on the transaction proposal.
   373       * @param fromPlatform name of form platform.
   374       * @param fromAccount name of to platform.
   375       * @param toAccount account of to platform.
   376       * @param value transfer amount.
   377       * @param txid transaction id.
   378       * @param sign transaction signature.
   379       */
   380      function voterProposal(bytes32 fromPlatform, address fromAccount, address toAccount, uint value, string txid, bytes sign) external;
   381  
   382      /**
   383       * Verify that the transaction proposal is valid.
   384       * @param fromPlatform name of form platform.
   385       * @param fromAccount name of to platform.
   386       * @param toAccount account of to platform.
   387       * @param value transfer amount.
   388       * @param txid transaction id.
   389       */
   390      function verifyProposal(bytes32 fromPlatform, address fromAccount, address toAccount, uint value, string txid) external constant returns (bool);
   391  
   392      /**
   393       * Commit the transaction proposal.
   394       * @param platformName a platform name.
   395       * @param txid transaction id.
   396       */
   397      function commitProposal(bytes32 platformName, string txid) external returns (bool);
   398  
   399      /**
   400       * Get the transaction proposal information.
   401       * @param platformName a platform name.
   402       * @param txid transaction id.
   403       * @return status
   404       * @return fromAccount
   405       * @return toAccount
   406       * @return value
   407       * @return voters
   408       */
   409      function getProposal(bytes32 platformName, string txid) external returns (bool status, address fromAccount, address toAccount, uint value, address[] voters);
   410  }
   411  ```
   412  
   413  > 1)setPlatformName & getPlatformName:Used to maintain the name of the contract platform.
   414  >
   415  > 2)start & stop & getStatus:Used to maintain contract service status.
   416  >
   417  > 2)setAdmin & getAdmin : Used to maintain contract administrators, transferable.
   418  >
   419  > 3)addPlatform、deletePlatfrom、getPlatfrom、existPlatfrom : Used to maintain information of trusted chain platform.
   420  >
   421  > 4)addPublickey、deletePublickey、countOfPublickey : Used to maintain the credible public key of the trusted chain platform.
   422  >
   423  > 5)setWeight、getWeight : Used to maintain the weight of trusted chain platform.
   424  >
   425  > 6)voter : Attestation to vote; verify : Verify the legality of cross-chain transactions. deleteProposal : Remove the proposal of vote.
   426  > 
   427  
   428  remark:1)2)3)4) 5)The administrator maintains the interface. 6)Open interface.
   429  
   430  ## Contract
   431  
   432  ```
   433  contract INK {}
   434  contract XCPlugin {}
   435  contract XC {
   436      INK private inkToken;
   437      XCPlugin private xcPlugin;
   438  }
   439  ```
   440  > 1)INK : INK Token contract. XCPlugin : Cross-chain functional contracts. XC : Across the chain contracts.
   441  >
   442  > 2)INK & XCPlugin are XC function plug-in contracts.
   443  > 
   444  
   445  ## Using
   446  
   447  ### Install INK contract
   448  ...
   449  
   450  ### Install XCPlugin contract
   451  ```
   452  1)Using addPlatform, deletePlatfrom, getPlatfrom, existPlatfrom method to maintain trusted platform information .
   453  2)Use the addPublickey, deletePublickey, countOfPublickey method to maintain the trusted public key information of the trusted platform.
   454  3)Use setWeight and getWeight method to set the verification weight of each trusted platform.
   455  ```
   456  
   457  ### Install XC contract;
   458  
   459  ```
   460  On XC contract, Using setINK、setXCPlugin method  setup INK contract & XCPlugin contract.
   461  Use getINK & getXCPlugin method to check.
   462  ```