MCPcopy Create free account
hub / github.com/DNAProject/DNA / deployContract

Function deployContract

cmd/contract_cmd.go:121–193  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

119)
120
121func deployContract(ctx *cli.Context) error {
122 SetRpcPort(ctx)
123 if !ctx.IsSet(utils.GetFlagName(utils.ContractCodeFileFlag)) ||
124 !ctx.IsSet(utils.GetFlagName(utils.ContractNameFlag)) {
125 PrintErrorMsg("Missing %s or %s argument.", utils.ContractCodeFileFlag.Name, utils.ContractNameFlag.Name)
126 cli.ShowSubcommandHelp(ctx)
127 return nil
128 }
129
130 vmtypeFlag := ctx.Uint(utils.GetFlagName(utils.ContractVmTypeFlag))
131 vmtype, err := payload.VmTypeFromByte(byte(vmtypeFlag))
132 if err != nil {
133 return err
134 }
135
136 codeFile := ctx.String(utils.GetFlagName(utils.ContractCodeFileFlag))
137 if "" == codeFile {
138 return fmt.Errorf("please specific code file")
139 }
140 codeStr, err := ioutil.ReadFile(codeFile)
141 if err != nil {
142 return fmt.Errorf("read code:%s error:%s", codeFile, err)
143 }
144
145 name := ctx.String(utils.GetFlagName(utils.ContractNameFlag))
146 version := ctx.String(utils.GetFlagName(utils.ContractVersionFlag))
147 author := ctx.String(utils.GetFlagName(utils.ContractAuthorFlag))
148 email := ctx.String(utils.GetFlagName(utils.ContractEmailFlag))
149 desc := ctx.String(utils.GetFlagName(utils.ContractDescFlag))
150 code := strings.TrimSpace(string(codeStr))
151 gasPrice := ctx.Uint64(utils.GetFlagName(utils.TransactionGasPriceFlag))
152 gasLimit := ctx.Uint64(utils.GetFlagName(utils.TransactionGasLimitFlag))
153 networkId, err := utils.GetNetworkId()
154 if err != nil {
155 return err
156 }
157 if networkId == config.NETWORK_ID_SOLO_NET {
158 gasPrice = 0
159 }
160
161 cversion := fmt.Sprintf("%s", version)
162
163 if ctx.IsSet(utils.GetFlagName(utils.ContractPrepareDeployFlag)) {
164 preResult, err := utils.PrepareDeployContract(vmtype, code, name, cversion, author, email, desc)
165 if err != nil {
166 return fmt.Errorf("PrepareDeployContract error:%s", err)
167 }
168 if preResult.State == 0 {
169 return fmt.Errorf("contract pre-deploy failed")
170 }
171 PrintInfoMsg("Contract pre-deploy successfully.")
172 PrintInfoMsg("Gas consumed:%d.", preResult.Gas)
173 return nil
174 }
175
176 signer, err := cmdcom.GetAccount(ctx)
177 if err != nil {
178 return fmt.Errorf("get signer account error:%s", err)

Callers

nothing calls this directly

Calls 12

GetFlagNameFunction · 0.92
VmTypeFromByteFunction · 0.92
GetNetworkIdFunction · 0.92
PrepareDeployContractFunction · 0.92
DeployContractFunction · 0.92
SetRpcPortFunction · 0.85
PrintErrorMsgFunction · 0.85
PrintInfoMsgFunction · 0.85
ErrorfMethod · 0.80
GetAccountMethod · 0.80
StringMethod · 0.45
ToHexStringMethod · 0.45

Tested by

no test coverage detected