github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/gomobile/walletutil/httpcli.go (about) 1 package walletutil 2 3 import ( 4 "fmt" 5 "github.com/sixexorg/magnetic-ring/common" 6 httpcli "github.com/sixexorg/magnetic-ring/http/cli" 7 "github.com/sixexorg/magnetic-ring/http/req" 8 ) 9 10 func PushTransaction(url string, txhex string) string { 11 ra,err := common.Hex2Bytes(txhex) 12 if err != nil { 13 return newErrorResp(err.Error()) 14 } 15 req := req.ReqSendTx{ 16 Raw: ra, 17 } 18 fullurl := fmt.Sprintf("%s/block/sendtx", url) 19 resp, err := httpcli.HttpSend(fullurl, req) 20 if err != nil { 21 return newErrorResp(err.Error()) 22 } 23 return newResp(fmt.Sprintf("%s", resp)) 24 } 25 26 27 func GetCurrentBlockHeigt(url string) string { 28 fullurl := fmt.Sprintf("%s/block/getcurrentblock", url) 29 resp, err := httpcli.HttpSend(fullurl, nil) 30 if err != nil { 31 return newErrorResp(err.Error()) 32 } 33 return newResp(fmt.Sprintf("%s", resp)) 34 } 35 36 37 func Getaccountnonce(url,account string) string { 38 fullurl := fmt.Sprintf("%s/block/getaccountnonce", url) 39 40 req := req.ReqAccountNounce{account} 41 42 resp, err := httpcli.HttpSend(fullurl, req) 43 rt := "" 44 if err != nil { 45 rt = newErrorResp(err.Error()) 46 } 47 rt = newResp(fmt.Sprintf("%s", resp)) 48 return rt 49 } 50 51 func Getblockbyheight(url string,height int64,orgId string) string { 52 fullurl := fmt.Sprintf("%s/block/getblockbyheight", url) 53 54 req := req.ReqGetBlockByHeight{uint64(height),orgId} 55 56 resp, err := httpcli.HttpSend(fullurl, req) 57 if err != nil { 58 return newErrorResp(err.Error()) 59 } 60 return newResp(fmt.Sprintf("%s", resp)) 61 } 62 63 64 func GetAccountBalance(url,account,orgid string) string { 65 fullurl := fmt.Sprintf("%s/block/getbalance",url) 66 67 req := req.ReqGetBalance{orgid,account} 68 69 resp, err := httpcli.HttpSend(fullurl, req) 70 if err != nil { 71 return newErrorResp(err.Error()) 72 } 73 return newResp(fmt.Sprintf("%s", resp)) 74 } 75 76 77 func GetAccountRefBlockHeights(url,account string,start,end int64) string { 78 fullurl := fmt.Sprintf("%s/block/getrefblock", url) 79 80 req := req.ReqGetRefBlock{ 81 uint64(start), 82 uint64(end), 83 account, 84 } 85 86 resp, err := httpcli.HttpSend(fullurl, req) 87 if err != nil { 88 return newErrorResp(err.Error()) 89 } 90 return newResp(fmt.Sprintf("%s", resp)) 91 } 92 93 func GetOrgInfo(url,orgid string) string { 94 fullurl := fmt.Sprintf("%s/block/getorginfo", url) 95 96 req := req.ReqOrgInfo{ 97 orgid, 98 } 99 100 resp, err := httpcli.HttpSend(fullurl, req) 101 if err != nil { 102 return newErrorResp(err.Error()) 103 } 104 return newResp(fmt.Sprintf("%s", resp)) 105 }