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

Filecoin integration #2095

Open
wants to merge 52 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
0069bbc
multiwallet fixes
hoffmabc Jul 16, 2020
f8c0dc0
spvwallet fixes
hoffmabc Jul 16, 2020
1eac8ad
wallet-interface fixes
hoffmabc Jul 16, 2020
e5b1ba5
ethwallet fixes
hoffmabc Jul 16, 2020
9c23964
Constants update
hoffmabc Jul 16, 2020
8ea2f66
coin config update
hoffmabc Jul 16, 2020
04ee986
Database chainhash fix
hoffmabc Jul 16, 2020
89eaa9f
Filecoin currency definition
hoffmabc Jul 16, 2020
48ad63a
Fix misspelling
hoffmabc Jul 16, 2020
71ff7a7
Add Filecoin API wallet
hoffmabc Jul 16, 2020
fc969b6
Filecoin server constants
hoffmabc Jul 21, 2020
b60d5a9
chash fixes
hoffmabc Jul 21, 2020
3561c8c
multiwallet updates
hoffmabc Jul 21, 2020
73cb941
chash fix
hoffmabc Jul 21, 2020
94c7a62
Fix dependency issues in vendor
cpacia Jul 23, 2020
c37c81c
Update version
hoffmabc Jul 22, 2020
291314b
Print golangci-lint errors
hoffmabc Jul 22, 2020
793790d
Fix Delete chainhash
hoffmabc Jul 23, 2020
a2b8cfc
Remove unused import
hoffmabc Jul 23, 2020
2f2f118
Update codebase for option wallet interfaces
cpacia Jul 23, 2020
6a16052
Update multiwallet dep
cpacia Jul 26, 2020
2d8d5a2
Remove chainhash code
hoffmabc Jul 23, 2020
5c35c76
Add opentracing
hoffmabc Jul 28, 2020
be25913
Remove filecoin submodule
hoffmabc Jul 28, 2020
33f2e92
Commit filecoin vendor
hoffmabc Jul 28, 2020
c5ed999
Fix txns_test
hoffmabc Jul 28, 2020
00c3bed
Add base58 as dep
hoffmabc Jul 28, 2020
811175d
Add new dependencies
hoffmabc Jul 28, 2020
b2ca068
Add murmur3
hoffmabc Jul 28, 2020
780c6e7
Add go.zipexe
hoffmabc Jul 28, 2020
4dcbd50
Add refmt
hoffmabc Jul 28, 2020
e2bfd0e
Add xerrors
hoffmabc Jul 28, 2020
ab1bb06
Add goprocess
hoffmabc Jul 28, 2020
21bd79f
Add final deps
hoffmabc Jul 28, 2020
243850b
Add jwt v3
hoffmabc Jul 28, 2020
07c0812
Add lru
hoffmabc Jul 28, 2020
d0a1056
Internal dep
hoffmabc Jul 28, 2020
1b8b65e
Add go.opencensus.io
hoffmabc Jul 28, 2020
bcff804
Update filecoin wallet dep
cpacia Jul 29, 2020
40d7244
Fix filecoin outgoing value
cpacia Jul 29, 2020
c207e3a
Init big int in filecoin save
cpacia Jul 29, 2020
b4bc1e3
Use correct filecoin txid
cpacia Jul 30, 2020
aa6cf84
Fix wallet balance
hoffmabc Jul 30, 2020
a486135
Fix wallet balance
hoffmabc Jul 30, 2020
5a7c3f6
Fix value comparison in filecoin
cpacia Jul 30, 2020
9573645
Do not process FIL txs with no order id
hoffmabc Aug 4, 2020
65a44fe
Fix wallet code for signed messages
hoffmabc Aug 4, 2020
dff7265
Fix incoming transactions
hoffmabc Aug 4, 2020
668fc00
Don’t die on failed transaction request
hoffmabc Aug 4, 2020
1380f95
Checking more closely on order payment msgs
hoffmabc Aug 4, 2020
d349967
gofmt handlers
hoffmabc Aug 4, 2020
b615e50
Update lotus and depenencies
cpacia Oct 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- "1.11"
- "1.13"
sudo: required
services:
- docker
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading