Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge d349967 into b4be594
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffmabc committed Oct 13, 2020
2 parents b4be594 + d349967 commit 4e3ca10
Show file tree
Hide file tree
Showing 2,511 changed files with 423,685 additions and 404 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,6 +1,6 @@
language: go
go:
- "1.11"
- "1.13"
sudo: required
services:
- docker
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,5 +1,5 @@
# Build stage - Use a full build environment to create a static binary
FROM golang:1.11
FROM golang:1.13
COPY . /go/src/github.com/OpenBazaar/openbazaar-go
RUN go build --ldflags '-extldflags "-static"' -o /opt/openbazaard /go/src/github.com/OpenBazaar/openbazaar-go

Expand Down
6 changes: 1 addition & 5 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions api/jsonapi.go
Expand Up @@ -3371,7 +3371,7 @@ func (i *jsonAPIHandler) POSTBumpFee(w http.ResponseWriter, r *http.Request) {
}
var wal wallet.Wallet
for _, w := range i.node.Multiwallet {
_, err := w.GetTransaction(*txHash)
_, err := w.GetTransaction(txHash.String())
if err == nil {
wal = w
break
Expand All @@ -3381,7 +3381,12 @@ func (i *jsonAPIHandler) POSTBumpFee(w http.ResponseWriter, r *http.Request) {
ErrorResponse(w, http.StatusBadRequest, "transaction not found in any wallet")
return
}
newTxid, err := wal.BumpFee(*txHash)
feeBumper, ok := wal.(wallet.WalletCanBumpFee)
if !ok {
ErrorResponse(w, http.StatusBadRequest, "wallet does not support bumping fees")
return
}
newTxid, err := feeBumper.BumpFee(txHash.String())
if err != nil {
if err == spvwallet.BumpFeeAlreadyConfirmedError {
ErrorResponse(w, http.StatusBadRequest, err.Error())
Expand All @@ -3405,7 +3410,7 @@ func (i *jsonAPIHandler) POSTBumpFee(w http.ResponseWriter, r *http.Request) {
return
}
if err := i.node.Datastore.TxMetadata().Put(repo.Metadata{
Txid: newTxid.String(),
Txid: newTxid,
Address: "",
Memo: fmt.Sprintf("Fee bump of %s", txid),
OrderId: "",
Expand All @@ -3429,7 +3434,7 @@ func (i *jsonAPIHandler) POSTBumpFee(w http.ResponseWriter, r *http.Request) {
ErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
txn, err := wal.GetTransaction(*newTxid)
txn, err := wal.GetTransaction(newTxid)
if err != nil {
ErrorResponse(w, http.StatusInternalServerError, err.Error())
return
Expand All @@ -3439,7 +3444,7 @@ func (i *jsonAPIHandler) POSTBumpFee(w http.ResponseWriter, r *http.Request) {

t := repo.NewAPITime(txn.Timestamp)
resp := &response{
Txid: newTxid.String(),
Txid: newTxid,
ConfirmedBalance: &repo.CurrencyValue{Currency: defn, Amount: &confirmed.Value},
UnconfirmedBalance: &repo.CurrencyValue{Currency: defn, Amount: &unconfirmed.Value},
Amount: amt0,
Expand Down Expand Up @@ -3468,7 +3473,7 @@ func (i *jsonAPIHandler) GETEstimateFee(w http.ResponseWriter, r *http.Request)
var feeLevel wallet.FeeLevel
switch strings.ToUpper(fl) {
case "PRIORITY":
feeLevel = wallet.PRIORITY
feeLevel = wallet.PRIOIRTY
case "NORMAL":
feeLevel = wallet.NORMAL
case "ECONOMIC":
Expand Down Expand Up @@ -3526,7 +3531,7 @@ func (i *jsonAPIHandler) GETFees(w http.ResponseWriter, r *http.Request) {
if coinType == "fees" {
ret := make(map[string]interface{})
for ct, wal := range i.node.Multiwallet {
priority := wal.GetFeePerByte(wallet.PRIORITY)
priority := wal.GetFeePerByte(wallet.PRIOIRTY)
normal := wal.GetFeePerByte(wallet.NORMAL)
economic := wal.GetFeePerByte(wallet.ECONOMIC)
superEconomic := wal.GetFeePerByte(wallet.SUPER_ECONOMIC)
Expand Down Expand Up @@ -3555,7 +3560,7 @@ func (i *jsonAPIHandler) GETFees(w http.ResponseWriter, r *http.Request) {
ErrorResponse(w, http.StatusBadRequest, "Unknown wallet type")
return
}
priority := wal.GetFeePerByte(wallet.PRIORITY)
priority := wal.GetFeePerByte(wallet.PRIOIRTY)
normal := wal.GetFeePerByte(wallet.NORMAL)
economic := wal.GetFeePerByte(wallet.ECONOMIC)
superEconomic := wal.GetFeePerByte(wallet.SUPER_ECONOMIC)
Expand Down Expand Up @@ -3947,7 +3952,7 @@ func (i *jsonAPIHandler) GETWalletStatus(w http.ResponseWriter, r *http.Request)
ret := make(map[string]interface{})
for ct, wal := range i.node.Multiwallet {
height, hash := wal.ChainTip()
ret[ct.CurrencyCode()] = status{height, hash.String()}
ret[ct.CurrencyCode()] = status{height, hash}
}
out, err := json.MarshalIndent(ret, "", " ")
if err != nil {
Expand All @@ -3963,7 +3968,7 @@ func (i *jsonAPIHandler) GETWalletStatus(w http.ResponseWriter, r *http.Request)
return
}
height, hash := wal.ChainTip()
st := status{height, hash.String()}
st := status{height, hash}
out, err := json.MarshalIndent(st, "", " ")
if err != nil {
ErrorResponse(w, http.StatusInternalServerError, err.Error())
Expand Down
14 changes: 11 additions & 3 deletions core/completion.go
Expand Up @@ -177,6 +177,10 @@ func (n *OpenBazaarNode) CompleteOrder(orderRatings *OrderRatings, contract *pb.

// Payout order if moderated and not disputed
if order.Payment.Method == pb.Order_Payment_MODERATED && contract.DisputeResolution == nil {
escrowWallet, ok := wal.(wallet.EscrowWallet)
if !ok {
return errors.New("wallet does not support escrow")
}
var ins []wallet.TransactionInput
outValue := new(big.Int)
for _, r := range records {
Expand Down Expand Up @@ -230,7 +234,7 @@ func (n *OpenBazaarNode) CompleteOrder(orderRatings *OrderRatings, contract *pb.
if !ok {
return errors.New("invalid payout fee per byte value")
}
buyerSignatures, err := wal.CreateMultisigSignature(ins, []wallet.TransactionOutput{output}, buyerKey, redeemScript, *n)
buyerSignatures, err := escrowWallet.CreateMultisigSignature(ins, []wallet.TransactionOutput{output}, buyerKey, redeemScript, *n)
if err != nil {
return err
}
Expand Down Expand Up @@ -318,6 +322,10 @@ func (n *OpenBazaarNode) ReleaseFundsAfterTimeout(contract *pb.RicardianContract
if err != nil {
return err
}
escrowWallet, ok := wal.(wallet.EscrowWallet)
if !ok {
return errors.New("wallet does not support escrow")
}
defn, err := repo.AllCurrencies().Lookup(order.Payment.AmountCurrency.Code)
if err != nil {
log.Errorf("Failed ReleaseFundsAfterTimeout(): %s", err.Error())
Expand All @@ -334,7 +342,7 @@ func (n *OpenBazaarNode) ReleaseFundsAfterTimeout(contract *pb.RicardianContract
return err
}

confirms, _, err := wal.GetConfirmations(*hash)
confirms, _, err := wal.GetConfirmations(hash.String())
if err != nil {
return err
}
Expand Down Expand Up @@ -382,7 +390,7 @@ func (n *OpenBazaarNode) ReleaseFundsAfterTimeout(contract *pb.RicardianContract
if err != nil {
return err
}
_, err = wal.SweepAddress(txInputs, nil, vendorKey, &redeemScript, wallet.NORMAL)
_, err = escrowWallet.SweepAddress(txInputs, nil, vendorKey, &redeemScript, wallet.NORMAL)
if err != nil {
return err
}
Expand Down
12 changes: 10 additions & 2 deletions core/confirmation.go
Expand Up @@ -127,6 +127,10 @@ func (n *OpenBazaarNode) ConfirmOfflineOrder(oldState pb.OrderState, contract *p
}

if confirmedContract.BuyerOrder.Payment.Method != pb.Order_Payment_MODERATED {
escrowWallet, ok := wal.(wallet.EscrowWallet)
if !ok {
return errors.New("wallet does not support escrow")
}
// Sweep the temp address into our wallet
var txInputs []wallet.TransactionInput
for _, r := range records {
Expand Down Expand Up @@ -176,7 +180,7 @@ func (n *OpenBazaarNode) ConfirmOfflineOrder(oldState pb.OrderState, contract *p
recoverState()
return err
}
_, err = wal.SweepAddress(txInputs, nil, vendorKey, &redeemScript, wallet.NORMAL)
_, err = escrowWallet.SweepAddress(txInputs, nil, vendorKey, &redeemScript, wallet.NORMAL)
if err != nil {
recoverState()
return err
Expand Down Expand Up @@ -213,6 +217,10 @@ func (n *OpenBazaarNode) RejectOfflineOrder(contract *pb.RicardianContract, reco
}
rejectMsg.Timestamp = ts
if order.Payment.Method == pb.Order_Payment_MODERATED {
escrowWallet, ok := wal.(wallet.EscrowWallet)
if !ok {
return errors.New("wallet does not support escrow")
}
var ins []wallet.TransactionInput
outValue := *big.NewInt(0)
for _, r := range records {
Expand Down Expand Up @@ -265,7 +273,7 @@ func (n *OpenBazaarNode) RejectOfflineOrder(contract *pb.RicardianContract, reco
if !ok {
return errors.New("invalid refund fee value")
}
signatures, err := wal.CreateMultisigSignature(ins, []wallet.TransactionOutput{output}, vendorKey, redeemScript, *fee)
signatures, err := escrowWallet.CreateMultisigSignature(ins, []wallet.TransactionOutput{output}, vendorKey, redeemScript, *fee)
if err != nil {
return fmt.Errorf("generate multisig: %s", err.Error())
}
Expand Down
23 changes: 18 additions & 5 deletions core/disputes.go
Expand Up @@ -176,7 +176,7 @@ func (n *OpenBazaarNode) verifyEscrowFundsAreDisputeable(contract *pb.RicardianC
log.Errorf("Nil NewHashFromStr(%s)", r.Txid)
return false
}
actualConfirmations, _, err := wal.GetConfirmations(*hash)
actualConfirmations, _, err := wal.GetConfirmations(hash.String())
if err != nil {
log.Errorf("Failed GetConfirmations(%s): %s", hash.String(), err.Error())
return false
Expand Down Expand Up @@ -592,6 +592,10 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
if err != nil {
return fmt.Errorf("currency (%s) not supported by wallet", preferredOrder.Payment.AmountCurrency.Code)
}
escrowWallet, ok := wal.(wallet.EscrowWallet)
if !ok {
return errors.New("wallet does not support escrow")
}

// Create outputs using full value. We will subtract the fee off each output later.
outMap := make(map[string]wallet.TransactionOutput)
Expand Down Expand Up @@ -743,7 +747,7 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
return err
}

sigs, err := wal.CreateMultisigSignature(inputs, outs, moderatorKey, redeemScriptBytes, *big.NewInt(0))
sigs, err := escrowWallet.CreateMultisigSignature(inputs, outs, moderatorKey, redeemScriptBytes, *big.NewInt(0))
if err != nil {
return err
}
Expand Down Expand Up @@ -982,6 +986,11 @@ func (n *OpenBazaarNode) ValidateCaseContract(contract *pb.RicardianContract) []
validationErrors = append(validationErrors, "Contract uses a coin not found in wallet")
return validationErrors
}
escrowWallet, ok := wal.(wallet.EscrowWallet)
if !ok {
validationErrors = append(validationErrors, "Wallet does not support escrow")
return validationErrors
}
chaincode, err := hex.DecodeString(order.Payment.Chaincode)
if err != nil {
validationErrors = append(validationErrors, "Error validating bitcoin address and redeem script")
Expand All @@ -1008,7 +1017,7 @@ func (n *OpenBazaarNode) ValidateCaseContract(contract *pb.RicardianContract) []
return validationErrors
}
timeout, _ := time.ParseDuration(strconv.Itoa(int(contract.VendorListings[0].Metadata.EscrowTimeoutHours)) + "h")
addr, redeemScript, err := wal.GenerateMultisigScript([]hd.ExtendedKey{*buyerKey, *vendorKey, *moderatorKey}, 2, timeout, vendorKey)
addr, redeemScript, err := escrowWallet.GenerateMultisigScript([]hd.ExtendedKey{*buyerKey, *vendorKey, *moderatorKey}, 2, timeout, vendorKey)
if err != nil {
validationErrors = append(validationErrors, "Error generating multisig script")
return validationErrors
Expand Down Expand Up @@ -1150,6 +1159,10 @@ func (n *OpenBazaarNode) ReleaseFunds(contract *pb.RicardianContract, records []
if err != nil {
return err
}
escrowWallet, ok := wal.(wallet.EscrowWallet)
if !ok {
return errors.New("wallet does not support escrow")
}

// Create outputs
var outputs []wallet.TransactionOutput
Expand Down Expand Up @@ -1222,7 +1235,7 @@ func (n *OpenBazaarNode) ReleaseFunds(contract *pb.RicardianContract, records []
return err
}

mySigs, err := wal.CreateMultisigSignature(inputs, outputs, signingKey, redeemScriptBytes, *big.NewInt(0))
mySigs, err := escrowWallet.CreateMultisigSignature(inputs, outputs, signingKey, redeemScriptBytes, *big.NewInt(0))
if err != nil {
return err
}
Expand All @@ -1249,7 +1262,7 @@ func (n *OpenBazaarNode) ReleaseFunds(contract *pb.RicardianContract, records []
peerID := order.BuyerID.PeerID

// Build, sign, and broadcast transaction
txnID, err := wal.Multisign(inputs, outputs, mySigs, moderatorSigs, redeemScriptBytes, *big.NewInt(0), true)
txnID, err := escrowWallet.Multisign(inputs, outputs, mySigs, moderatorSigs, redeemScriptBytes, *big.NewInt(0), true)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion core/fulfillment.go
Expand Up @@ -37,6 +37,10 @@ func (n *OpenBazaarNode) FulfillOrder(fulfillment *pb.OrderFulfillment, contract
if err != nil {
return err
}
escrowWallet, ok := wal.(wallet.EscrowWallet)
if !ok {
return errors.New("wallet does not support escrow")
}
currentAddress := wal.CurrentAddress(wallet.EXTERNAL)
payout.PayoutAddress = currentAddress.String()
f := wal.GetFeePerByte(wallet.NORMAL)
Expand Down Expand Up @@ -79,7 +83,7 @@ func (n *OpenBazaarNode) FulfillOrder(fulfillment *pb.OrderFulfillment, contract
if !ok {
return errors.New("invalid payout fee value")
}
signatures, err := wal.CreateMultisigSignature(ins, []wallet.TransactionOutput{output}, vendorKey, redeemScript, *fee)
signatures, err := escrowWallet.CreateMultisigSignature(ins, []wallet.TransactionOutput{output}, vendorKey, redeemScript, *fee)
if err != nil {
return err
}
Expand Down

0 comments on commit 4e3ca10

Please sign in to comment.