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

Function getAllowance

cmd/asset_cmd.go:229–269  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

227}
228
229func getAllowance(ctx *cli.Context) error {
230 SetRpcPort(ctx)
231 from := ctx.String(utils.GetFlagName(utils.ApproveAssetFromFlag))
232 to := ctx.String(utils.GetFlagName(utils.ApproveAssetToFlag))
233 if from == "" || to == "" {
234 PrintErrorMsg("Missing %s or %s argument.", utils.ApproveAssetFromFlag.Name, utils.ApproveAssetToFlag.Name)
235 cli.ShowSubcommandHelp(ctx)
236 return nil
237 }
238 asset := ctx.String(utils.GetFlagName(utils.ApproveAssetFlag))
239 if asset == "" {
240 asset = utils.ASSET_GAS
241 }
242 fromAddr, err := cmdcom.ParseAddress(from, ctx)
243 if err != nil {
244 return err
245 }
246 toAddr, err := cmdcom.ParseAddress(to, ctx)
247 if err != nil {
248 return err
249 }
250 balanceStr, err := utils.GetAllowance(asset, fromAddr, toAddr)
251 if err != nil {
252 return err
253 }
254 switch strings.ToLower(asset) {
255 case "gas":
256 balance, err := strconv.ParseUint(balanceStr, 10, 64)
257 if err != nil {
258 return err
259 }
260 balanceStr = utils.FormatOng(balance)
261 default:
262 return fmt.Errorf("unsupport asset:%s", asset)
263 }
264 PrintInfoMsg("Allowance:%s", asset)
265 PrintInfoMsg(" From:%s", fromAddr)
266 PrintInfoMsg(" To:%s", toAddr)
267 PrintInfoMsg(" Balance:%s", balanceStr)
268 return nil
269}
270
271func approve(ctx *cli.Context) error {
272 SetRpcPort(ctx)

Callers

nothing calls this directly

Calls 8

GetFlagNameFunction · 0.92
GetAllowanceFunction · 0.92
FormatOngFunction · 0.92
SetRpcPortFunction · 0.85
PrintErrorMsgFunction · 0.85
PrintInfoMsgFunction · 0.85
ErrorfMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected