func (a *SellActivity) HandleReceipt(log bitwrk.Logger, encResultHash, encResultHashSig string) error { if err := bitcoin.VerifySignatureBase64(encResultHash, a.tx.Buyer, encResultHashSig); err != nil { return err } if err := SendTxMessageTransmitFinished(a.txId, a.identity, encResultHash, encResultHashSig, a.encResultKey.String()); err != nil { return fmt.Errorf("Signaling working finished failed: %v", err) } return nil }
func updateTransaction(c appengine.Context, r *http.Request, txId string, txKey *datastore.Key) error { now := time.Now() r.ParseForm() values := make(map[string]string) // Check that we don't have any multi-occurring parameters, // copy into a simple key value map for easier handling for k, v := range r.Form { if len(v) == 1 { values[k] = v[0] } else if len(v) > 1 { return fmt.Errorf("Multiple occurrences of argument %#v", k) } } // Verify "txid" parameter, add if not found if txId2, ok := values["txid"]; ok { if txId2 != txId { return fmt.Errorf("Transaction ID parameter doesn't match %#v", txId) } } else { values["txid"] = txId } // Check whether "workerurl" parameter actually points to origin of request if CfgRequireValidWorkerURL { if rawurl, ok := values["workerurl"]; !ok { } else if len(rawurl) >= 256 { return fmt.Errorf("WorkerURL may not exceed 255 characters") } else if u, err := url.Parse(rawurl); err != nil { return err } else if !hostsMatch(u.Host, r.RemoteAddr) { return fmt.Errorf("workerurl host %v and remote host %v do not match.", u.Host, r.RemoteAddr) } } // Filter out "signature" parameter var signature string if _signature, ok := values["signature"]; ok { delete(values, "signature") signature = _signature } else { return fmt.Errorf("Missing signature parameter in message") } // Filter out "address" parameter var address string if _address, ok := values["address"]; ok { delete(values, "address") address = _address } else { return fmt.Errorf("Missing address parameter in message") } document := makeDocument(values) if CfgRequireValidSignature { if err := bitcoin.VerifySignatureBase64(document, address, signature); err != nil { return err } } // no need for txid in values anymore delete(values, "txid") if err := db.UpdateTransaction(c, txKey, now, address, values, document, signature); err != nil { return err } return nil }