Skip to content

Commit

Permalink
Remove stale client methods (#1037)
Browse files Browse the repository at this point in the history
* Remove '/blocks/child/' client's method.

* Remove '/addresses/signText/' client's method.

* Remove '/addresses/verifyText/' client's method.

* Remove '/alias/broadcast/create' client's method.

* Remove '/alias/create' client's method.

* Implemented 'TextUnmarshaler' for 'WavesAddress'.

* Implemented 'TextMarshaler' for 'WavesAddress'.

* Implemented '/assets/{assetID}/distribution/{height}/limit/{limit}' client's method.

* Remove '/assets/issue' client's method.

* Remove '/assets/masstransfer' client's method.

* Remove '/assets/sponsor' client's method.

* Remove '/assets/burn' client's method.

* Refactored 'Blocks.HeightByID' method.

* Remove '/blocks/signature/{id}' client's method.

* Remove '/blocks/first' client's method.

* Removed stale 'Client.Consensus' client's methods.

* Remove '/debug/blocks/{count}' client's method.

* Remove '/debug/historyInfo' client's method.

* Remove '/debug/stateChanges/info/{id}' client's method.

* Removed unused functions.

* Remove api key check in '/utils/seed' client's method.

* Remove api key check in '/utils/hash/secure' client's method.

* Remove api key check in '/utils/hash/fast' client's method.

* Remove api key check in '/utils/time' client's method.

* Remove '/utils/sign/{secretKey}' client's method.

* Remove api key check in '/utils/seed/{length}' client's method.

* Fixed 'Utils.ScriptCompile' and add 'Utils.ScriptCompileCode' methods.

* Add necessary fields for 'Utils.ScriptEstimate' client's response.

* Refactored a bit '/wallet/seed' client's method.

* Remove 'pkg/client/transactions_integration_test.go'.

* Remove 'pkg/client/peers_integration_test.go'.

* Remove 'pkg/client/utils_integration_test.go'.
  • Loading branch information
nickeskov authored Mar 2, 2023
1 parent fd5df67 commit f22d664
Show file tree
Hide file tree
Showing 23 changed files with 163 additions and 1,956 deletions.
82 changes: 0 additions & 82 deletions pkg/client/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
"fmt"
"net/http"
"net/url"
"strings"

"github.com/pkg/errors"
"github.com/wavesplatform/gowaves/pkg/crypto"
"github.com/wavesplatform/gowaves/pkg/proto"
)

Expand Down Expand Up @@ -212,86 +210,6 @@ func (a *Addresses) PublicKey(ctx context.Context, publicKey string) (*proto.Wav
return out.Address, response, nil
}

type AddressesSignText struct {
Message string `json:"message"`
PublicKey crypto.PublicKey `json:"publicKey"`
Signature crypto.Signature `json:"signature"`
}

// SignText signs a message with a private key associated with address
func (a *Addresses) SignText(ctx context.Context, address proto.WavesAddress, message string) (*AddressesSignText, *Response, error) {
if a.options.ApiKey == "" {
return nil, nil, NoApiKeyError
}

u, err := joinUrl(a.options.BaseUrl, fmt.Sprintf("/addresses/signText/%s", address.String()))
if err != nil {
return nil, nil, err
}

req, err := http.NewRequest(
"POST", u.String(),
strings.NewReader(message))
if err != nil {
return nil, nil, err
}

req.Header.Set("X-API-Key", a.options.ApiKey)

out := new(AddressesSignText)
response, err := doHttp(ctx, a.options, req, out)
if err != nil {
return nil, response, err
}

return out, response, nil
}

type VerifyText struct {
Valid bool
}

type VerifyTextReq struct {
Message string `json:"message"`
PublicKey crypto.PublicKey `json:"publickey"`
Signature crypto.Signature `json:"signature"`
}

// VerifyText checks a signature of a message signed by an account
func (a *Addresses) VerifyText(ctx context.Context, address proto.WavesAddress, body VerifyTextReq) (bool, *Response, error) {
if a.options.ApiKey == "" {
return false, nil, NoApiKeyError
}

u, err := joinUrl(a.options.BaseUrl, fmt.Sprintf("/addresses/verifyText/%s", address.String()))
if err != nil {
return false, nil, err
}

bodyBytes, err := json.Marshal(body)
if err != nil {
return false, nil, err
}

req, err := http.NewRequest(
"POST", u.String(),
bytes.NewReader(bodyBytes))
if err != nil {
return false, nil, err
}

req.Header.Set("X-API-Key", a.options.ApiKey)

out := new(VerifyText)
response, err := doHttp(ctx, a.options, req, out)
if err != nil {
return false, response, err
}

return out.Valid, response, nil

}

type BalanceAfterConfirmations struct {
Address proto.WavesAddress `json:"address"`
Confirmations uint64 `json:"confirmations"`
Expand Down
62 changes: 0 additions & 62 deletions pkg/client/addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/wavesplatform/gowaves/pkg/crypto"
"github.com/wavesplatform/gowaves/pkg/proto"
)

Expand Down Expand Up @@ -190,67 +189,6 @@ func TestAddresses_PublicKey(t *testing.T) {
resp.Request.URL.String())
}

var addressSignTextJson = `
{
"message": "some-text",
"publicKey": "CRxqEuxhdZBEHX42MU4FfyJxuHmbDBTaHMhM3Uki7pLw",
"signature": "RP742bUjfrzWcXhnmkbim2dWk9mSUcPcmn77EcsD5t2TBUZqZGe8Vk211hAYbW4FNxWtWqcCmR1Trv8gUXKN6if"
}`

func TestAddresses_SignText(t *testing.T) {
address, _ := proto.NewAddressFromString("3MzemqBzJ9h844PparHU1EzGC5SQmtH5pNp")
pubKey, _ := crypto.NewPublicKeyFromBase58("CRxqEuxhdZBEHX42MU4FfyJxuHmbDBTaHMhM3Uki7pLw")
sign, _ := crypto.NewSignatureFromBase58("RP742bUjfrzWcXhnmkbim2dWk9mSUcPcmn77EcsD5t2TBUZqZGe8Vk211hAYbW4FNxWtWqcCmR1Trv8gUXKN6if")
text := "some-text"
client, err := NewClient(Options{
BaseUrl: "https://testnode1.wavesnodes.com/",
ApiKey: "ApiKey",
Client: NewMockHttpRequestFromString(addressSignTextJson, 200),
})
require.NoError(t, err)
body, resp, err :=
client.Addresses.SignText(context.Background(), address, text)
require.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, text, body.Message)
assert.Equal(t, &AddressesSignText{
Message: text,
PublicKey: pubKey,
Signature: sign,
}, body)
assert.Equal(t,
"https://testnode1.wavesnodes.com/addresses/signText/3MzemqBzJ9h844PparHU1EzGC5SQmtH5pNp",
resp.Request.URL.String())
}

var addressVerifyTextJson = `
{
"valid": true
}`

func TestAddresses_VerifyText(t *testing.T) {
address, _ := proto.NewAddressFromString("3MzemqBzJ9h844PparHU1EzGC5SQmtH5pNp")
pubKey, _ := crypto.NewPublicKeyFromBase58("J26nL27BBmTgCRye1MdzkFduFDE2aA4agCcuJUyDR2sZ")
sign, _ := crypto.NewSignatureFromBase58("4Bh3vksvhe55Ej8bwt42HiPgU18MynnKg87Rr1ZhRQUhmJmFiWC7imgaorW5QJRXxXwbK38bvRmZH4dncPzA9grA")
data := VerifyTextReq{
Message: "text",
PublicKey: pubKey,
Signature: sign,
}
client, err := NewClient(Options{
BaseUrl: "https://testnode1.wavesnodes.com/",
ApiKey: "apiKey",
Client: NewMockHttpRequestFromString(addressVerifyTextJson, 200),
})
require.NoError(t, err)
body, resp, err :=
client.Addresses.VerifyText(context.Background(), address, data)
require.NoError(t, err)
assert.NotNil(t, resp)
assert.True(t, body)
assert.Equal(t, "https://testnode1.wavesnodes.com/addresses/verifyText/3MzemqBzJ9h844PparHU1EzGC5SQmtH5pNp", resp.Request.URL.String())
}

var addressBalanceAfterConfirmationsJson = `
{
"address": "3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8",
Expand Down
89 changes: 0 additions & 89 deletions pkg/client/alias.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package client

import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/wavesplatform/gowaves/pkg/crypto"
"github.com/wavesplatform/gowaves/pkg/proto"
)

Expand Down Expand Up @@ -62,89 +59,3 @@ func (a *Alias) GetByAddress(ctx context.Context, address proto.WavesAddress) ([

return out, response, nil
}

type AliasCreateReq struct {
Sender proto.WavesAddress `json:"sender"`
Alias string `json:"alias"`
Fee uint64 `json:"fee"`
Timestamp uint64 `json:"timestamp,omitempty"`
}

type CreateAliasWithSig struct {
Type proto.TransactionType `json:"type"`
Version byte `json:"version,omitempty"`
ID *crypto.Digest `json:"id,omitempty"`
Signature *crypto.Signature `json:"signature,omitempty"`
SenderPK crypto.PublicKey `json:"senderPublicKey"`
Alias string `json:"alias"`
Fee uint64 `json:"fee"`
Timestamp uint64 `json:"timestamp,omitempty"`
}

func (a *Alias) Create(ctx context.Context, createReq AliasCreateReq) (*CreateAliasWithSig, *Response, error) {
if a.options.ApiKey == "" {
return nil, nil, NoApiKeyError
}

url, err := joinUrl(a.options.BaseUrl, "/alias/create")
if err != nil {
return nil, nil, err
}

bts, err := json.Marshal(createReq)
if err != nil {
return nil, nil, err
}

req, err := http.NewRequest(
"POST", url.String(),
bytes.NewReader(bts))
if err != nil {
return nil, nil, err
}

req.Header.Set("X-API-Key", a.options.ApiKey)

out := new(CreateAliasWithSig)
response, err := doHttp(ctx, a.options, req, out)
if err != nil {
return nil, response, err
}

return out, response, nil
}

type AliasBroadcastReq struct {
SenderPublicKey crypto.PublicKey `json:"senderPublicKey"`
Fee uint64 `json:"fee"`
Timestamp uint64 `json:"timestamp"`
Signature crypto.Signature `json:"signature"`
Alias string `json:"alias"`
}

func (a *Alias) Broadcast(ctx context.Context, broadcastReq AliasBroadcastReq) (*CreateAliasWithSig, *Response, error) {
bts, err := json.Marshal(broadcastReq)
if err != nil {
return nil, nil, err
}

url, err := joinUrl(a.options.BaseUrl, "/alias/broadcast/create")
if err != nil {
return nil, nil, err
}

req, err := http.NewRequest(
"POST", url.String(),
bytes.NewReader(bts))
if err != nil {
return nil, nil, err
}

out := new(CreateAliasWithSig)
response, err := doHttp(ctx, a.options, req, out)
if err != nil {
return nil, response, err
}

return out, response, nil
}
Loading

0 comments on commit f22d664

Please sign in to comment.