API Version in the URL, not the payload. Duh.
This commit is contained in:
parent
2b60c1d5ac
commit
23bd804f97
|
@ -11,6 +11,8 @@ import (
|
|||
|
||||
// TODO proper doc comments!
|
||||
|
||||
const API_VERSION = 1
|
||||
|
||||
const PathAuthToken = "/auth/full"
|
||||
const PathRegister = "/signup"
|
||||
const PathWallet = "/wallet"
|
||||
|
@ -150,9 +152,10 @@ func (s *Server) checkAuth(
|
|||
// PUT = "...creates a new resource or replaces a representation of the target resource with the request payload."
|
||||
|
||||
func (s *Server) Serve() {
|
||||
http.HandleFunc(PathAuthToken, s.getAuthToken)
|
||||
http.HandleFunc(PathWallet, s.handleWallet)
|
||||
http.HandleFunc(PathRegister, s.register)
|
||||
PathPrefix := fmt.Sprintf("/api/%d", API_VERSION)
|
||||
http.HandleFunc(PathPrefix+PathAuthToken, s.getAuthToken)
|
||||
http.HandleFunc(PathPrefix+PathWallet, s.handleWallet)
|
||||
http.HandleFunc(PathPrefix+PathRegister, s.register)
|
||||
|
||||
fmt.Println("Serving at localhost:8090")
|
||||
http.ListenAndServe("localhost:8090", nil)
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"orblivion/lbry-id/wallet"
|
||||
)
|
||||
|
||||
const CURRENT_VERSION = 1
|
||||
|
||||
type WalletRequest struct {
|
||||
Version int `json:"version"`
|
||||
Token auth.TokenString `json:"token"`
|
||||
|
@ -20,8 +18,7 @@ type WalletRequest struct {
|
|||
}
|
||||
|
||||
func (r *WalletRequest) validate() bool {
|
||||
return (r.Version == CURRENT_VERSION &&
|
||||
r.Token != auth.TokenString("") &&
|
||||
return (r.Token != auth.TokenString("") &&
|
||||
r.EncryptedWallet != wallet.EncryptedWallet("") &&
|
||||
r.Hmac != wallet.WalletHmac("") &&
|
||||
r.Sequence >= wallet.Sequence(1))
|
||||
|
@ -92,7 +89,6 @@ func (s *Server) getWallet(w http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
walletResponse := WalletResponse{
|
||||
Version: CURRENT_VERSION,
|
||||
EncryptedWallet: latestEncryptedWallet,
|
||||
Sequence: latestSequence,
|
||||
Hmac: latestHmac,
|
||||
|
@ -143,7 +139,6 @@ func (s *Server) postWallet(w http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
walletResponse := WalletResponse{
|
||||
Version: CURRENT_VERSION,
|
||||
EncryptedWallet: latestEncryptedWallet,
|
||||
Sequence: latestSequence,
|
||||
Hmac: latestHmac,
|
||||
|
|
|
@ -59,15 +59,17 @@ class LBRYSDK():
|
|||
|
||||
class WalletSync():
|
||||
def __init__(self, local):
|
||||
self.API_VERSION = 1
|
||||
|
||||
if local:
|
||||
BASE_URL = 'http://localhost:8090'
|
||||
else:
|
||||
BASE_URL = 'https://dev.lbry.id:8091'
|
||||
self.AUTH_URL = BASE_URL + '/auth/full'
|
||||
self.REGISTER_URL = BASE_URL + '/signup'
|
||||
self.WALLET_URL = BASE_URL + '/wallet'
|
||||
API_URL = BASE_URL + '/api/%d' % self.API_VERSION
|
||||
|
||||
self.API_VERSION = 1
|
||||
self.AUTH_URL = API_URL + '/auth/full'
|
||||
self.REGISTER_URL = API_URL + '/signup'
|
||||
self.WALLET_URL = API_URL + '/wallet'
|
||||
|
||||
def register(self, email, password):
|
||||
body = json.dumps({
|
||||
|
@ -121,7 +123,6 @@ class WalletSync():
|
|||
|
||||
def update_wallet(self, wallet_state, hmac, token):
|
||||
body = json.dumps({
|
||||
'version': self.API_VERSION,
|
||||
'token': token,
|
||||
"encryptedWallet": wallet_state.encrypted_wallet,
|
||||
"sequence": wallet_state.sequence,
|
||||
|
@ -130,8 +131,6 @@ class WalletSync():
|
|||
|
||||
response = requests.post(self.WALLET_URL, body)
|
||||
|
||||
# TODO check that response.json().version == self.API_VERSION
|
||||
|
||||
if response.status_code == 200:
|
||||
conflict = False
|
||||
print ('Successfully updated wallet state on server')
|
||||
|
|
Loading…
Reference in a new issue