package examples import ( "encoding/json" "errors" "fmt" "regexp" ) type SendResult struct { Ok bool `json:"ok"` Result struct { RequestedSat int64 `json:"requested_sat"` RecipientSat int64 `json:"recipient_sat"` ChangeSat int64 `json:"change_sat"` TxID string `json:"txid"` Net string `json:"net"` } `json:"result"` } var txidPattern = regexp.MustCompile(`^[0-9a-fA-F]{64}$`) func FormatSendReply(raw []byte) (string, error) { var r SendResult if err := json.Unmarshal(raw, &r); err != nil { return "", err } if !r.Ok || !txidPattern.MatchString(r.Result.TxID) || r.Result.RequestedSat <= 0 || r.Result.RecipientSat < 0 { return "", errors.New("unverified or incomplete send result") } return fmt.Sprintf("Bitcoin Engine accepted a %s send request. Requested: %d sat; recipient output: %d sat; change: %d sat. TXID: %s. Confirmation has not been verified.", r.Result.Net, r.Result.RequestedSat, r.Result.RecipientSat, r.Result.ChangeSat, r.Result.TxID), nil }