示例#1
0
        public Tuple <Transaction.Transaction, Contract> Deploy(DeployParams param, int attempts, int interval)
        {
            if (string.IsNullOrEmpty(code) || init == null || init.Count() <= 0)
            {
                throw new Exception("Cannot deploy without code or initialisation parameters.");
            }
            Transaction.Transaction transaction = new Transaction.Transaction();
            transaction.ID           = param.ID;
            transaction.Version      = param.Version;
            transaction.Nonce        = param.Nonce;
            transaction.GasPrice     = param.GasPrice;
            transaction.GasLimit     = param.GasLimit;
            transaction.SenderPubKey = param.SenderPubKey;
            transaction.ToAddr       = NIL_ADDRESS;
            transaction.Amount       = "0";
            transaction.Code         = this.code.Replace("/\\", "");
            transaction.Data         = JsonConvert.SerializeObject(this.init);
            transaction.Provider     = this.provider;
            transaction = this.prepareTx(transaction, attempts, interval);
            if (transaction.IsRejected())
            {
                this.contractStatus = ContractStatus.Rejected;
                return(Tuple.Create <Transaction.Transaction, Contract>(transaction, this));
            }

            this.contractStatus = ContractStatus.Deployed;
            this.address        = ContractFactory.GetAddressForContract(transaction);
            return(Tuple.Create <Transaction.Transaction, Contract>(transaction, this));
        }
示例#2
0
 public Contract(ContractFactory factory, string code, string abi, string address, Values[] init, List <LaksaCsharp.BlockChain.State> state)
 {
     this.contractFactory = factory;
     this.provider        = factory.Provider;
     this.signer          = factory.Signer;
     if (!string.IsNullOrEmpty(address))
     {
         this.abi            = abi;
         this.address        = address;
         this.init           = init;
         this.state          = state;
         this.code           = code;
         this.contractStatus = ContractStatus.Deployed;
     }
     else
     {
         this.abi            = abi;
         this.code           = code;
         this.init           = init;
         this.contractStatus = ContractStatus.Initialised;
     }
 }