Ejemplo n.º 1
0
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
	}

	// 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
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
func (bid *Bid) Verify() error {
	if err := bitcoin.VerifySignatureBase64(bid.Document, bid.Participant, bid.Signature); err != nil {
		return fmt.Errorf("Could not validate signature: %v", err)
	}
	return nil
}