Open drwasho opened 5 years ago
Changed the spec to remove the magnitude
key in favor of a simpler "one value" reprentation.
{
"data": "value",
"amount": { // this key would match the replaced key in the BEFORE case
"value": "12345678",
// "magnitude": -8, # omit this key
"currency": {
"code": "BTC", // this key would always be `code`
"divisibility": 8
}
},
"otherdata": "othervalue"
}
@amangale Discussion has raised the following requirement:
NOTE: We need to ensure values lower than
0
in thevalue
field when used in the JSON API are rejected with an error explaining that the value must be a positive integer.
Recommend a 400 Bad Request
error response.
@amangale you asked for some details of calls that use the amount field, here's what I turned up with a quick search that I know the desktop client uses. This may not include everything:
@amangale Just added three new endpoints ^^^ (rob)
@amangale
Ashwan, just following up on my comment in the slack thread:
Keep in mind that a few of those endpoints include the full listing which does already have the coinDivisibility in it in the metadata object. It’s a required field when creating the listing.
So, for those api’s no change is needed.
I think these are the ones with the full listing:
@amangale
Another thing is the metadata.coinDivisibility in the listing is in the old format (e.g. 100000000 instead of 8. Can you please make sure it uses the new format?
And I guess the server needs to be compatible with old listings using the old format.. or I guess maybe it just needs to migrate the data.
@amangale @jjeffryes @mg
Another thing with that endpoint list is that a few of those endpoints aren't READs from the server. They are the client posting data back to the server.
For ob/purchase
, the client would use the coinDiv from the listing which is referenced by a hash
included in the POST data. I'm assuming the server when it receives the post could also get the coinDiv from the listing and use it to process any price fields?
For wallet/spend
, should the client just use the coinDiv provided via wallet/balance
or is it better for the client to explicitly send back the coinDiv it's using in the spend call?
For wallet/orderspend
, should the client use the coinDiv from the listing the order is for or same question as above, should the client explicitly provide it in the orderspend call?
@rmisio To respond to your old questions, I think posting the full definitions despite just getting them from a prior call makes the API more stateless. This means that a POST body might need to repeat the symbol and divisibility of the amount being sent. (The type and name can probably be omitted.) I think it's reasonable to accept just the string instead of the full definition, allow the server to assume the same divisibility as whats in the dictionary... but that would probably be a different key.
openbazaar-go
updatesHigh-level overview
[ ] 1.
repo.Listing
abstraction (for handling contract versioning properly)[ ] 2.
(*repo.Listing) Quantity() big.Int
respects versions properly (w/ unit tests)[ ] 3.
MarshalJSON
andUnmarshalJSON
[ ] 4.
protobuf
changes (updates to proto usage should userepo.Listing
getters for accessing changed schema data)[ ] 5. JSON API updates
[ ] 6.
openbazaar-go
datastore migrationsProtobuf Schema
pb.CurrencyValue
proto to track high-precision value of a currency[ ] 8. Restrict prior schema version to BTC, BCH, LTC, ZEC as accepted currencies for transactions (recommend creating non-proto type
pb.Listing
to manage version-specific marshal/unmarshal of JSON contracts and proper mapping of changing fields between currentv4
and futurev5
Listings.... Ex:pb.Listing.Price()
can return a valid price regardless of source being v4 or v5.)[ ] 9. Bump Listing to new schema
v5
[ ] 9A. Update
pb.Listing.Metadata.Coin[Type|Divisibility]
to usepb.CurrencyDefinition
[ ] 9B. Update
pb.ListingItem.Price
to usepb.CurrencyValue
[ ] 9C. Merge
pb.Listing.Metadata.PricingCurrency
withpb.Listing.ListingItem.Price
intopb.CurrencyValue
[ ] 9D. In
pb.Listing.BuyerOrder
updatepb.Order_Payment.Amount
andpb.Order_Payment.Coin
to usepb.CurrencyValue
[ ] 9Di. Replace
ModeratorInfo.Price
usage withpb.CurrencyValue
[ ] 9Dii. Replace
CoinType
andpb.CoinDivisibility
to usepb.CurrencyDefinition
[ ] 9E. Update
pb.ListingItem.Skus.Quantity
to usejson.Number
(to support larger inventory requirements in CRYPTOLISTING listings)[ ] 9F. Update
pb.Listing.BuyerOrder.RefundFee
to usepb.CurrencyValue
[ ] 9G. In
pb.Listing.BuyerOrder.Items
collapseQuantity
andQuantity64
itojson.Number
[ ] 9Gi. Properly represent that
< v2
schema expectsQuantity
and>= v3
requiresQuantity64
[ ] 9Gii.
>= v5
requiresjson.Number
to support (now) larger inventory requirements for Cryptocurrency listings[ ] 9H. In
pb.Listing.BuyerOrder
updateAmount
andCoin
to usepb.CurrencyValue
[ ] 9I. Update BuyerOrder schema version?
[ ] 9J. Update
pb.VendorOrderConfirmation.RequestedAmount
topb.CurrencyValue
[ ] 9K. Update
pb.VendorOrderFulfillment.Payout.PayoutFeePerByte
topb.CurrencyValue
[ ] 9L. Update
pb.Dispute.Outputs[].Value
topb.CurrencyValue
[ ] 9M. Update
pb.TransactionRecord.Value
topb.CurrencyValue
[ ] 9N. In
pb.ShippingOption.Service
updatePrice
andAdditionalItemPrice
topb.CurrencyValue
[ ] 9O. Update
pb.Coupon.PriceDiscount
topb.CurrencyValue
*Note: I know there is redundant data with the currency type being expressed in every place where a value is represented. This was done intentionally so that knowledge of implicit relationships between fields aren't required to make sense of the data. Denormalizing data here also doesn't hurt us as we can ensure the implicit relationships are intact more easily with tests and validations.
API changes
pb.CurrencyValue
type above should be used in place ofint
usages for amount. The typical transformation will look similar to the following other indicated otherwise:A value of
0.12345678 BTC
might be represented like this before:This data would be changed to look like:
[ ] NOTE: We need to ensure values lower than 0 in the
value
field are rejected with an error explaining that the value must be a positive integer.[ ] 11.
POST /ob/purchase
(POSTPurchase
) responseDatastore migrations: SQLite data
buyerOutputs
andvendorOutputs
which contain serialized sets ofvalue
s:[ ] 13. Inventory
count
from typeinteger
totext
surcharge
from typeinteger
totext
[ ] 14. Notifications
serializedNotification
to new model schema[ ] 15. Purchases/sales (consider merging these into one table and add a
type
column to differentiate?)total
from typeinteger
totext
?transactions
which contain serialized sets ofvalues
:type
differentiator?)value
frominteger
totext
?