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

[WIP] Enable ERC20 #2035

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
15 changes: 15 additions & 0 deletions core/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,30 @@ func (n *OpenBazaarNode) Purchase(data *repo.PurchaseData) (orderID string, paym
}
// Add payment data and send to vendor
if data.Moderator != "" { // Moderated payment
log.Info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
contract, err := prepareModeratedOrderContract(data, n, contract, wal)
log.Info("after prepareModeratedOrderContract, err: ", err)
if err != nil {
return "", "", retCurrency, false, err
}

contract, err = n.SignOrder(contract)
log.Info("after signorder : ", err)
if err != nil {
return "", "", retCurrency, false, err
}

// Send to order vendor
merchantResponse, err := n.SendOrder(contract.VendorListings[0].VendorID.PeerID, contract)
log.Info("after send order, err : ", err)
if err != nil {
id, addr, amt, err := processOfflineModeratedOrder(n, contract)
retCurrency.Amount = &amt
return id, addr, retCurrency, false, err
}
log.Info("ven dor is online ................")
id, addr, amt, f, err := processOnlineModeratedOrder(merchantResponse, n, contract)
log.Info("after processOnlineModeratedOrder, err : ", err)
retCurrency.Amount = &amt
return id, addr, retCurrency, f, err

Expand Down Expand Up @@ -470,14 +476,17 @@ func processOnlineModeratedOrder(resp *pb.Message, n *OpenBazaarNode, contract *
}
// Vendor responded
if resp.MessageType == pb.Message_ERROR {
log.Info("ret 1111111111111111111111")
return "", "", *big.NewInt(0), false, extractErrorMessage(resp)
}
if resp.MessageType != pb.Message_ORDER_CONFIRMATION {
log.Info("ret 2222222222222222222222")
return "", "", *big.NewInt(0), false, errors.New("vendor responded to the order with an incorrect message type")
}
rc := new(pb.RicardianContract)
err = proto.Unmarshal(resp.Payload.Value, rc)
if err != nil {
log.Info("ret 33333333333333333333333 ", err)
return "", "", *big.NewInt(0), false, errors.New("error parsing the vendor's response")
}
contract.VendorOrderConfirmation = rc.VendorOrderConfirmation
Expand All @@ -487,24 +496,30 @@ func processOnlineModeratedOrder(resp *pb.Message, n *OpenBazaarNode, contract *
}
}
err = n.ValidateOrderConfirmation(contract, true)
log.Info("ret 444444444444444444444444444 : ", err)
if err != nil {
return "", "", *big.NewInt(0), false, err
}
if contract.VendorOrderConfirmation.PaymentAddress != contract.BuyerOrder.Payment.Address {
log.Info("ret 555555555555555555555555555")
return "", "", *big.NewInt(0), false, errors.New("vendor responded with incorrect multisig address")
}
orderID, err := n.CalcOrderID(contract.BuyerOrder)
if err != nil {
log.Info("ret 6666666666666666666666666 : ", err)
return "", "", *big.NewInt(0), false, err
}
err = n.Datastore.Purchases().Put(orderID, *contract, pb.OrderState_AWAITING_PAYMENT, false)
if err != nil {
log.Info("ret 777777777777777777777777777 : ", err)
return "", "", *big.NewInt(0), false, err
}
total, ok := new(big.Int).SetString(v5Order.Payment.BigAmount, 10)
if !ok {
log.Info("ret 88888888888888888888888888")
return "", "", *big.NewInt(0), false, errors.New("invalid payment amount")
}
log.Info("ret last : ", orderID, " ", contract.VendorOrderConfirmation.PaymentAddress, " ", total.String())
return orderID, contract.VendorOrderConfirmation.PaymentAddress, *total, true, nil
}

Expand Down
2 changes: 2 additions & 0 deletions core/spend.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func (n *OpenBazaarNode) Spend(args *SpendRequest) (*SpendResponse, error) {
feeLevel = wallet.NORMAL
}

log.Info("before wallet spend : amt - ", amt.String(), " addr : ", addr.String())
log.Info("fee level : ", feeLevel, " orderID ", args.OrderID, " spend all ", args.SpendAll)
txid, err := wal.Spend(*amt, addr, feeLevel, args.OrderID, args.SpendAll)
if err != nil {
switch {
Expand Down
6 changes: 6 additions & 0 deletions qa/eth_complete_direct_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ def run_test(self):
time.sleep(4)
api_url = bob["gateway_url"] + "wallet/address/" + self.cointype
r = requests.get(api_url)
print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
print("bob api_url : ", api_url)
if r.status_code == 200:
resp = json.loads(r.text)
address = resp["address"]
print(address)
elif r.status_code == 404:
raise TestFailure("EthCompleteDirectOnlineTest - FAIL: Address endpoint not found")
else:
Expand Down Expand Up @@ -55,11 +58,14 @@ def run_test(self):
# get listing hash
api_url = alice["gateway_url"] + "ob/listings/" + alice["peerId"]
r = requests.get(api_url)
print("alice api_url : ", api_url)
if r.status_code != 200:
raise TestFailure("EthCompleteDirectOnlineTest - FAIL: Couldn't get listing index")
resp = json.loads(r.text)
listingId = resp[0]["hash"]

time.sleep(36000)

# bob send order
with open('testdata/v5/order_direct.json') as order_file:
order_json = json.load(order_file, object_pairs_hook=OrderedDict)
Expand Down
2 changes: 1 addition & 1 deletion qa/eth_dispute_close_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def run_test(self):
resp = json.loads(r.text)
raise TestFailure("EthDisputeCloseSplitTest - FAIL: Moderator POST failed. Reason: %s", resp["reason"])
moderatorId = charlie["peerId"]
time.sleep(4)
time.sleep(40)

# post profile for alice
with open('testdata/v5/profile.json') as profile_file:
Expand Down
4 changes: 2 additions & 2 deletions qa/testdata/v5/eth_listing.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"contractType": "PHYSICAL_GOOD",
"format": "FIXED_PRICE",
"expiry": "2030-08-17T04:52:19.000Z",
"acceptedCurrencies": ["TETH"],
"acceptedCurrencies": ["TETH","TOBT"],
"escrowTimeoutHours": 1080
},
"item": {
Expand All @@ -18,7 +18,7 @@
"name": "A",
"currencyType": "A"
},
"bigPrice": "4500000000000000",
"bigPrice": "45000000000000",
"tags": [
"tshirts",
"clothing",
Expand Down
2 changes: 2 additions & 0 deletions repo/currency_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ var (
"LTC": {Name: "Litecoin", Code: CurrencyCode("LTC"), CurrencyType: Crypto, Divisibility: 8, BlockTime: 150 * time.Second},
"ZEC": {Name: "Zcash", Code: CurrencyCode("ZEC"), CurrencyType: Crypto, Divisibility: 8, BlockTime: DefaultBlockTime},
"ETH": {Name: "Ethereum", Code: CurrencyCode("ETH"), CurrencyType: Crypto, Divisibility: 18, BlockTime: 10 * time.Second},
"OBT": {Name: "OB Token", Code: CurrencyCode("OBT"), CurrencyType: Crypto, Divisibility: 18, BlockTime: 10 * time.Second},
}
testnetCryptoDefinitions = map[string]CurrencyDefinition{
"TBTC": {Name: "Testnet Bitcoin", Code: CurrencyCode("TBTC"), CurrencyType: Crypto, Divisibility: 8, BlockTime: DefaultBlockTime},
"TBCH": {Name: "Testnet Bitcoin Cash", Code: CurrencyCode("TBCH"), CurrencyType: Crypto, Divisibility: 8, BlockTime: DefaultBlockTime},
"TLTC": {Name: "Testnet Litecoin", Code: CurrencyCode("TLTC"), CurrencyType: Crypto, Divisibility: 8, BlockTime: 150 * time.Second},
"TZEC": {Name: "Testnet Zcash", Code: CurrencyCode("TZEC"), CurrencyType: Crypto, Divisibility: 8, BlockTime: DefaultBlockTime},
"TETH": {Name: "Testnet Ethereum", Code: CurrencyCode("TETH"), CurrencyType: Crypto, Divisibility: 18, BlockTime: 10 * time.Second},
"TOBT": {Name: "Testnet OB Token", Code: CurrencyCode("TOBT"), CurrencyType: Crypto, Divisibility: 18, BlockTime: 10 * time.Second},
}
fiatDefinitions = map[string]CurrencyDefinition{
"AED": {Name: "UAE Dirham", Code: CurrencyCode("AED"), CurrencyType: Fiat, Divisibility: 2},
Expand Down
12 changes: 12 additions & 0 deletions schema/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type WalletsConfig struct {
LTC *CoinConfig `json:"LTC"`
ZEC *CoinConfig `json:"ZEC"`
ETH *CoinConfig `json:"ETH"`
OBT *CoinConfig `json:"OBT"`
}

type CoinConfig struct {
Expand Down Expand Up @@ -129,6 +130,17 @@ func DefaultWalletsConfig() *WalletsConfig {
MaxFee: 200,
WalletOptions: EthereumDefaultOptions(),
},
OBT: &CoinConfig{
Type: WalletTypeAPI,
APIPool: CoinPoolOBT,
APITestnetPool: CoinPoolTOBT,
FeeAPI: "", // intentionally blank
LowFeeDefault: 7,
MediumFeeDefault: 15,
HighFeeDefault: 30,
MaxFee: 200,
WalletOptions: OBTDefaultOptions(),
},
}
}

Expand Down
25 changes: 25 additions & 0 deletions schema/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ const (
EthereumRegistryAddressRinkeby = "0x5cEF053c7b383f430FC4F4e1ea2F7D31d8e2D16C"
EthereumRegistryAddressRopsten = "0x403d907982474cdd51687b09a8968346159378f3"

// OBToken
OBTRegistryAddressMainnet = "0x5c69ccf91eab4ef80d9929b3c1b4d5bc03eb0981"
OBTRegistryAddressRinkeby = "0x5cEF053c7b383f430FC4F4e1ea2F7D31d8e2D16C"
OBTRegistryAddressRopsten = "0x403d907982474cdd51687b09a8968346159378f3"
OBTAddressMainnet = "0x6b175474e89094c44da98b954eedeac495271d0f" //"0xe46ea07736e68df951df7b987dda453962ba7d5a"
OBTAddressRinkeby = "0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea" //"0xe46ea07736e68df951df7b987dda453962ba7d5a"
OBTAddressRopsten = "0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea" //"0xe46ea07736e68df951df7b987dda453962ba7d5a"

DataPushNodeOne = "QmbwN82MVyBukT7WTdaQDppaACo62oUfma8dUa5R9nBFHm"
DataPushNodeTwo = "QmPPg2qeF3n2KvTRXRZLaTwHCw8JxzF4uZK93RfMoDvf2o"
DataPushNodeThree = "QmY8puEnVx66uEet64gAf4VZRo7oUyMCwG6KdB9KM92EGQ"
Expand Down Expand Up @@ -89,6 +97,19 @@ func EthereumDefaultOptions() map[string]interface{} {
}
}

func OBTDefaultOptions() map[string]interface{} {
return map[string]interface{}{
"Name": "OB Token",
"Symbol": "OBT",
"MainNetAddress": OBTAddressMainnet,
"RinkebyAddress": OBTAddressRinkeby,
"RopstenAddress": OBTAddressRopsten,
"RegistryAddress": OBTRegistryAddressMainnet,
"RinkebyRegistryAddress": OBTRegistryAddressRinkeby,
"RopstenRegistryAddress": OBTRegistryAddressRopsten,
}
}

const (
WalletTypeAPI = "API"
WalletTypeSPV = "SPV"
Expand All @@ -100,12 +121,14 @@ const (
CoinAPIOpenBazaarLTC = "https://ltc.api.openbazaar.org/api"
CoinAPIOpenBazaarZEC = "https://zec.api.openbazaar.org/api"
CoinAPIOpenBazaarETH = "https://mainnet.infura.io"
CoinAPIOpenBazaarOBT = "https://mainnet.infura.io"

CoinAPIOpenBazaarTBTC = "https://tbtc.api.openbazaar.org/api"
CoinAPIOpenBazaarTBCH = "https://tbch.api.openbazaar.org/api"
CoinAPIOpenBazaarTLTC = "https://tltc.api.openbazaar.org/api"
CoinAPIOpenBazaarTZEC = "https://tzec.api.openbazaar.org/api"
CoinAPIOpenBazaarTETH = "https://rinkeby.infura.io"
CoinAPIOpenBazaarTOBT = "https://rinkeby.infura.io"
)

var (
Expand All @@ -114,10 +137,12 @@ var (
CoinPoolLTC = []string{CoinAPIOpenBazaarLTC}
CoinPoolZEC = []string{CoinAPIOpenBazaarZEC}
CoinPoolETH = []string{CoinAPIOpenBazaarETH}
CoinPoolOBT = []string{CoinAPIOpenBazaarOBT}

CoinPoolTBTC = []string{CoinAPIOpenBazaarTBTC}
CoinPoolTBCH = []string{CoinAPIOpenBazaarTBCH}
CoinPoolTLTC = []string{CoinAPIOpenBazaarTLTC}
CoinPoolTZEC = []string{CoinAPIOpenBazaarTZEC}
CoinPoolTETH = []string{CoinAPIOpenBazaarTETH}
CoinPoolTOBT = []string{CoinAPIOpenBazaarTOBT}
)
7 changes: 5 additions & 2 deletions vendor/github.com/OpenBazaar/go-ethwallet/wallet/client.go

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

Loading