This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to convert 1handle to [email protected]
- Loading branch information
Showing
5 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ func (m *mockHTTP) Do(req *http.Request) (*http.Response, error) { | |
// Invalid paymail | ||
resp.Body = invalidResponse("PayMail not found", req.URL.String(), resp.StatusCode) | ||
|
||
} else if strings.Contains(req.URL.String(), "/1mrz") { | ||
} else if strings.Contains(req.URL.String(), "/[email protected]") { | ||
|
||
// Valid 1handle | ||
resp.StatusCode = http.StatusOK | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,16 @@ type GetAddressResponse struct { | |
// GetAddress returns the address of a given 1handle, $handcash, paymail, Twetch user id or BitcoinSV address | ||
func GetAddress(client Client, handleOrPaymail string) (response *GetAddressResponse, err error) { | ||
|
||
// Convert handle to paymail if detected | ||
if strings.Contains(handleOrPaymail, "$") { | ||
handleOrPaymail = HandCashConvert(handleOrPaymail, false) | ||
} else if strings.HasPrefix(handleOrPaymail, "1") && len(handleOrPaymail) < 25 { | ||
handleOrPaymail = RelayXConvert(handleOrPaymail) | ||
} | ||
|
||
// Set the API url | ||
// todo: beta is temporary, and only used via the method directly | ||
reqURL := fmt.Sprintf("%s/%s/%s", apiEndpoint, "getAddress", HandCashConvert(handleOrPaymail, false)) | ||
reqURL := fmt.Sprintf("%s/%s/%s", apiEndpoint, "getAddress", handleOrPaymail) | ||
|
||
// Store for debugging purposes | ||
response = &GetAddressResponse{ | ||
|
@@ -71,7 +78,10 @@ func GetAddress(client Client, handleOrPaymail string) (response *GetAddressResp | |
|
||
// Cleanup | ||
defer func() { | ||
_ = resp.Body.Close() | ||
if resp.Body != nil { | ||
_ = resp.Body.Close() | ||
} | ||
|
||
}() | ||
|
||
// Set the status | ||
|
@@ -82,6 +92,10 @@ func GetAddress(client Client, handleOrPaymail string) (response *GetAddressResp | |
|
||
// Decode the error message | ||
if resp.StatusCode == http.StatusBadRequest { | ||
if resp.Body == nil { | ||
err = fmt.Errorf("no response body found") | ||
return | ||
} | ||
if err = json.NewDecoder(resp.Body).Decode(&response); err != nil { | ||
return | ||
} | ||
|
@@ -112,3 +126,11 @@ func HandCashConvert(handle string, isBeta bool) string { | |
} | ||
return handle | ||
} | ||
|
||
// RelayXConvert now converts 1handle to paymail: [email protected] | ||
func RelayXConvert(handle string) string { | ||
if strings.HasPrefix(handle, "1") && len(handle) < 25 { | ||
return strings.ToLower(strings.Replace(handle, "1", "", -1)) + "@relayx.io" | ||
} | ||
return handle | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,3 +106,43 @@ func BenchmarkHandCashConvert(b *testing.B) { | |
_ = HandCashConvert("$mr-z", false) | ||
} | ||
} | ||
|
||
// TestRelayXConvert will test the RelayXConvert() method | ||
func TestRelayXConvert(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Create the list of tests | ||
var tests = []struct { | ||
input string | ||
expected string | ||
}{ | ||
{"1mr-z", "[email protected]"}, | ||
{"invalid1mr-z", "invalid1mr-z"}, | ||
{"1", "@relayx.io"}, | ||
{"1mrz", "[email protected]"}, | ||
{"1handle", "[email protected]"}, | ||
{"1misterz", "[email protected]"}, | ||
{"[email protected]", "[email protected]"}, | ||
} | ||
|
||
// Test all | ||
for _, test := range tests { | ||
if output := RelayXConvert(test.input); output != test.expected { | ||
t.Errorf("%s Failed: [%s] inputted and [%s] expected, received: [%s]", t.Name(), test.input, test.expected, output) | ||
} | ||
} | ||
} | ||
|
||
// ExampleHandCashConvert example using RelayXConvert() | ||
func ExampleRelayXConvert() { | ||
paymail := RelayXConvert("1mr-z") | ||
fmt.Println(paymail) | ||
// Output:[email protected] | ||
} | ||
|
||
// BenchmarkHandCashConvert benchmarks the RelayXConvert method | ||
func BenchmarkRelayXConvert(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_ = RelayXConvert("1mr-z") | ||
} | ||
} |