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

Function GetContractAllowance

http/base/common/common.go:343–375  ·  view source on GitHub ↗
(cVersion byte, contractAddr, fromAddr, toAddr common.Address)

Source from the content-addressed store, hash-verified

341}
342
343func GetContractAllowance(cVersion byte, contractAddr, fromAddr, toAddr common.Address) (uint64, error) {
344 type allowanceStruct struct {
345 From common.Address
346 To common.Address
347 }
348 mutable, err := NewNativeInvokeTransaction(0, 0, contractAddr, cVersion, "allowance",
349 []interface{}{&allowanceStruct{
350 From: fromAddr,
351 To: toAddr,
352 }})
353 if err != nil {
354 return 0, fmt.Errorf("NewNativeInvokeTransaction error:%s", err)
355 }
356
357 tx, err := mutable.IntoImmutable()
358 if err != nil {
359 return 0, err
360 }
361
362 result, err := bactor.PreExecuteContract(tx)
363 if err != nil {
364 return 0, fmt.Errorf("PrepareInvokeContract error:%s", err)
365 }
366 if result.State == 0 {
367 return 0, fmt.Errorf("prepare invoke failed")
368 }
369 data, err := hex.DecodeString(result.Result.(string))
370 if err != nil {
371 return 0, fmt.Errorf("hex.DecodeString error:%s", err)
372 }
373 allowance := common.BigIntFromNeoBytes(data)
374 return allowance.Uint64(), nil
375}
376
377func GetGasPrice() (map[string]interface{}, error) {
378 start := bactor.GetCurrentBlockHeight()

Callers 1

GetAllowanceFunction · 0.85

Calls 5

BigIntFromNeoBytesFunction · 0.92
ErrorfMethod · 0.80
IntoImmutableMethod · 0.80
PreExecuteContractMethod · 0.65

Tested by

no test coverage detected