github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/client/rpcapi/address.go (about) 1 package rpcapi 2 3 import ( 4 "encoding/hex" 5 "github.com/piotrnar/gocoin/lib/btc" 6 //"github.com/piotrnar/gocoin/client/common" 7 ) 8 9 /* 10 11 {"result": 12 {"isvalid":true, 13 "address":"mqzwxBkSH1UKqEAjGwvkj6aV5Gc6BtBCSs", 14 "scriptPubKey":"76a91472fc9e6b1bbbd40a66653989a758098bfbf1b54788ac", 15 "ismine":false, 16 "iswatchonly":false, 17 "isscript":false 18 } 19 */ 20 21 type ValidAddressResponse struct { 22 IsValid bool `json:"isvalid"` 23 Address string `json:"address"` 24 ScriptPubKey string `json:"scriptPubKey"` 25 IsMine bool `json:"ismine"` 26 IsWatchOnly bool `json:"iswatchonly"` 27 IsScript bool `json:"isscript"` 28 } 29 30 type InvalidAddressResponse struct { 31 IsValid bool `json:"isvalid"` 32 } 33 34 func ValidateAddress(addr string) (interface{}) { 35 a, e := btc.NewAddrFromString(addr) 36 if e != nil { 37 return new(InvalidAddressResponse) 38 } 39 res := new(ValidAddressResponse) 40 res.IsValid = true 41 res.Address = addr 42 res.ScriptPubKey = hex.EncodeToString(a.OutScript()) 43 return res 44 //res.IsMine = false 45 //res.IsWatchOnly = false 46 //res.IsScript = false 47 }