Skip to content

Commit

Permalink
Merge pull request #176 from BuxOrg/feat/BUX-430/removeLogs
Browse files Browse the repository at this point in the history
BUX-430/Remove logs and debug flag
  • Loading branch information
Nazarii-4chain authored Dec 29, 2023
2 parents 0dc9233 + dbe5756 commit 4c3c4f9
Show file tree
Hide file tree
Showing 17 changed files with 19 additions and 319 deletions.
12 changes: 0 additions & 12 deletions buxclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type BuxClient struct {
transports.TransportService
accessKey *bec.PrivateKey
accessKeyString string
debug bool
transport transports.TransportService
transportOptions []transports.ClientOps
xPriv *bip32.ExtendedKey
Expand Down Expand Up @@ -107,17 +106,6 @@ func (b *BuxClient) SetAdminKey(adminKeyString string) error {
return nil
}

// SetDebug turn the debugging on or off
func (b *BuxClient) SetDebug(debug bool) {
b.debug = debug
b.transport.SetDebug(debug)
}

// IsDebug return the debugging status
func (b *BuxClient) IsDebug() bool {
return b.transport.IsDebug()
}

// SetSignRequest turn the signing of the http request on or off
func (b *BuxClient) SetSignRequest(signRequest bool) {
b.transport.SetSignRequest(signRequest)
Expand Down
32 changes: 0 additions & 32 deletions buxclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,36 +161,6 @@ func TestSetAdminKey(t *testing.T) {
})
}

// TestSetDebug will test the debug setter
func TestSetDebug(t *testing.T) {
t.Run("true", func(t *testing.T) {
client, _ := New(
WithXPriv(xPrivString),
WithHTTP(serverURL),
)
client.SetDebug(true)
assert.True(t, client.IsDebug())
})

t.Run("false", func(t *testing.T) {
client, _ := New(
WithXPriv(xPrivString),
WithHTTP(serverURL),
)
client.SetDebug(false)
assert.False(t, client.IsDebug())
})

t.Run("false", func(t *testing.T) {
_, err := New(
WithXPriv(xPrivString),
WithDebugging(false),
WithHTTP(serverURL),
)
require.NoError(t, err)
})
}

// TestSetSignRequest will test the sign request setter
func TestSetSignRequest(t *testing.T) {
t.Run("true", func(t *testing.T) {
Expand All @@ -214,7 +184,6 @@ func TestSetSignRequest(t *testing.T) {
t.Run("false", func(t *testing.T) {
_, err := New(
WithXPriv(xPrivString),
WithDebugging(false),
WithHTTP(serverURL),
)
require.NoError(t, err)
Expand Down Expand Up @@ -573,7 +542,6 @@ func TestGetTransport(t *testing.T) {
WithXPriv(xPrivString),
WithGraphQL(serverURL),
WithAdminKey(xPrivString),
WithDebugging(true),
WithSignRequest(false),
)
transport := client.GetTransport()
Expand Down
9 changes: 0 additions & 9 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,3 @@ func WithSignRequest(signRequest bool) ClientOps {
}
}
}

// WithDebugging will set whether to turn debugging on
func WithDebugging(debug bool) ClientOps {
return func(c *BuxClient) {
if c != nil {
c.transportOptions = append(c.transportOptions, transports.WithDebugging(debug))
}
}
}
17 changes: 3 additions & 14 deletions examples/graphql/graphql.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
package main

import (
"github.com/BuxOrg/go-buxclient/xpriv"
"log"

"github.com/BuxOrg/go-buxclient"
"github.com/BuxOrg/go-buxclient/xpriv"
)

func main() {

// Generate keys
keys, resErr := xpriv.Generate()
if resErr != nil {
log.Fatalln(resErr.Error())
}
keys, _ := xpriv.Generate()

// Create a client
buxClient, err := buxclient.New(
_, _ = buxclient.New(
buxclient.WithXPriv(keys.XPriv()),
buxclient.WithGraphQL("localhost:3001"),
buxclient.WithDebugging(true),
buxclient.WithSignRequest(true),
)
if err != nil {
log.Fatalln(err.Error())
}

log.Printf("client loaded - bux debug: %v", buxClient.IsDebug())
}
17 changes: 3 additions & 14 deletions examples/http/http.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
package main

import (
"github.com/BuxOrg/go-buxclient/xpriv"
"log"

"github.com/BuxOrg/go-buxclient"
"github.com/BuxOrg/go-buxclient/xpriv"
)

func main() {

// Generate keys
keys, resErr := xpriv.Generate()
if resErr != nil {
log.Fatalln(resErr.Error())
}
keys, _ := xpriv.Generate()

// Create a client
buxClient, err := buxclient.New(
_, _ = buxclient.New(
buxclient.WithXPriv(keys.XPriv()),
buxclient.WithHTTP("localhost:3001"),
buxclient.WithDebugging(true),
buxclient.WithSignRequest(true),
)
if err != nil {
log.Fatalln(err.Error())
}

log.Printf("client loaded - bux debug: %v", buxClient.IsDebug())
}
10 changes: 1 addition & 9 deletions examples/http_with_access_key/http_with_access_key.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"log"

"github.com/BuxOrg/go-buxclient"
)

Expand All @@ -12,15 +10,9 @@ func main() {
exampleAccessKey := "some_generated_access_key"

// Create a client
client, err := buxclient.New(
_, _ = buxclient.New(
buxclient.WithAccessKey(exampleAccessKey),
buxclient.WithHTTP("http://localhost:3003/v1"),
buxclient.WithDebugging(true),
buxclient.WithSignRequest(true),
)
if err != nil {
log.Fatalln(err.Error())
}

log.Printf("client loaded - bux debug: %v", client.IsDebug())
}
5 changes: 0 additions & 5 deletions examples/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ func main() {
panic(err)
}

fmt.Println("<-- Generate method")
fmt.Println("XPriv: ", keys.XPriv())
fmt.Println("XPub: ", keys.XPub().String())
fmt.Println("Mnemonic: ", keys.Mnemonic())

//Generate keys from mnemonic string
xpriv3, err := xpriv.FromMnemonic(keys.Mnemonic())
if err != nil {
Expand Down
23 changes: 4 additions & 19 deletions examples/new_paymail/new_paymail.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,22 @@ package main

import (
"context"
"github.com/BuxOrg/go-buxclient/xpriv"
"log"

"github.com/BuxOrg/go-buxclient"
"github.com/BuxOrg/go-buxclient/xpriv"
)

func main() {

// Generate keys
keys, resErr := xpriv.Generate()
if resErr != nil {
log.Fatalln(resErr.Error())
}
keys, _ := xpriv.Generate()

// Create a client
buxClient, err := buxclient.New(
buxClient, _ := buxclient.New(
buxclient.WithXPriv(keys.XPriv()),
buxclient.WithHTTP("localhost:3001"),
buxclient.WithDebugging(true),
buxclient.WithSignRequest(true),
)
if err != nil {
log.Fatalln(err.Error())
}

log.Printf("client loaded - bux debug: %v", buxClient.IsDebug())
err = buxClient.NewPaymail(context.Background(), keys.XPub().String(), "[email protected]", "", "Foo", nil)

if err != nil {
log.Fatalln(err.Error())
}
log.Printf("paymail added")
_ = buxClient.NewPaymail(context.Background(), keys.XPub().String(), "[email protected]", "", "Foo", nil)

}
22 changes: 5 additions & 17 deletions examples/register_xpub/register_xpub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,24 @@ package main

import (
"context"
"github.com/BuxOrg/go-buxclient/xpriv"
"log"

buxmodels "github.com/BuxOrg/bux-models"
"github.com/BuxOrg/go-buxclient"
"github.com/BuxOrg/go-buxclient/xpriv"
)

func main() {
// Generate keys
keys, resErr := xpriv.Generate()
if resErr != nil {
log.Fatalln(resErr.Error())
}
keys, _ := xpriv.Generate()

// Create a client
buxClient, err := buxclient.New(
buxClient, _ := buxclient.New(
buxclient.WithXPriv(keys.XPriv()),
buxclient.WithHTTP("localhost:3001"),
buxclient.WithDebugging(true),
buxclient.WithSignRequest(true),
)
if err != nil {
log.Fatalln(err.Error())
}

if err = buxClient.NewXpub(
_ = buxClient.NewXpub(
context.Background(), keys.XPub().String(), &buxmodels.Metadata{"example_field": "example_data"},
); err != nil {
log.Fatalln(err.Error())
}
)

log.Println("registered xPub: " + keys.XPub().String())
}
16 changes: 0 additions & 16 deletions transports/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func WithGraphQL(serverURL string) ClientOps {
return func(c *Client) {
if c != nil {
c.transport = NewTransportService(&TransportGraphQL{
debug: c.debug,
server: serverURL,
signRequest: c.signRequest,
adminXPriv: c.adminXPriv,
Expand All @@ -57,7 +56,6 @@ func WithHTTP(serverURL string) ClientOps {
return func(c *Client) {
if c != nil {
c.transport = NewTransportService(&TransportHTTP{
debug: c.debug,
server: serverURL,
signRequest: c.signRequest,
adminXPriv: c.adminXPriv,
Expand All @@ -75,7 +73,6 @@ func WithGraphQLClient(serverURL string, httpClient *http.Client) ClientOps {
return func(c *Client) {
if c != nil {
c.transport = NewTransportService(&TransportGraphQL{
debug: c.debug,
server: serverURL,
signRequest: c.signRequest,
adminXPriv: c.adminXPriv,
Expand All @@ -93,7 +90,6 @@ func WithHTTPClient(serverURL string, httpClient *http.Client) ClientOps {
return func(c *Client) {
if c != nil {
c.transport = NewTransportService(&TransportHTTP{
debug: c.debug,
server: serverURL,
signRequest: c.signRequest,
adminXPriv: c.adminXPriv,
Expand Down Expand Up @@ -126,15 +122,3 @@ func WithSignRequest(signRequest bool) ClientOps {
}
}
}

// WithDebugging will set whether to turn debugging on
func WithDebugging(debug bool) ClientOps {
return func(c *Client) {
if c != nil {
c.debug = debug
if c.transport != nil {
c.transport.SetDebug(debug)
}
}
}
}
21 changes: 0 additions & 21 deletions transports/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/hex"
"encoding/json"
"log"
"net/http"

buxmodels "github.com/BuxOrg/bux-models"
Expand All @@ -24,7 +23,6 @@ type TransportGraphQL struct {
accessKey *bec.PrivateKey
adminXPriv *bip32.ExtendedKey
client graphQlService
debug bool
httpClient *http.Client
server string
signRequest bool
Expand Down Expand Up @@ -113,16 +111,6 @@ func (g *TransportGraphQL) SetAdminKey(adminKey *bip32.ExtendedKey) {
g.adminXPriv = adminKey
}

// SetDebug turn the debugging on or off
func (g *TransportGraphQL) SetDebug(debug bool) {
g.debug = debug
}

// IsDebug return the debugging status
func (g *TransportGraphQL) IsDebug() bool {
return g.debug
}

// SetSignRequest turn the signing of the HTTP request on or off
func (g *TransportGraphQL) SetSignRequest(signRequest bool) {
g.signRequest = signRequest
Expand Down Expand Up @@ -801,9 +789,6 @@ func (g *TransportGraphQL) draftTransactionCommon(ctx context.Context, reqBody s
return nil, WrapError(err)
}
draftTransaction := respData.NewTransaction
if g.debug {
log.Printf("Draft transaction: %v\n", draftTransaction)
}

return draftTransaction, nil
}
Expand Down Expand Up @@ -852,9 +837,6 @@ func (g *TransportGraphQL) RecordTransaction(ctx context.Context, hex, reference
return nil, WrapError(err)
}
transaction := respData.Transaction
if g.debug {
log.Printf("transaction: %s\n", transaction.ID)
}

return transaction, nil
}
Expand Down Expand Up @@ -1021,9 +1003,6 @@ func (g *TransportGraphQL) doGraphQLQuery(ctx context.Context, reqBody string, v
if err := g.client.Run(ctx, req, &respData); err != nil {
return WrapError(err)
}
if g.debug {
log.Printf("model: %v\n", respData)
}

return nil
}
Expand Down
Loading

0 comments on commit 4c3c4f9

Please sign in to comment.