From f93f109b93cb2f3d9722f8e84b374b03547cefc6 Mon Sep 17 00:00:00 2001 From: Vladimir Yuldashev Date: Mon, 17 May 2021 14:31:36 +0200 Subject: [PATCH 1/4] deep link: allow to override url --- transaction/deeplink.go | 33 ++++++++++++++++++++++++++-- transaction/deeplink_example_test.go | 19 +++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/transaction/deeplink.go b/transaction/deeplink.go index 5f80347..ad20510 100644 --- a/transaction/deeplink.go +++ b/transaction/deeplink.go @@ -14,6 +14,8 @@ type DeepLink struct { Nonce *uint32 `rlp:"nilList"` // optional, used for prevent transaction reply GasPrice *uint32 `rlp:"nilList"` // optional, fee multiplier, should be equal or greater than current mempool min gas price GasCoin *CoinID `rlp:"nilList"` // optional, ID of a coin to pay fee, right padded with zeros + + url *url.URL } // Returns url link. @@ -29,8 +31,8 @@ func (d *DeepLink) CreateLink(pass string) (string, error) { } u := &url.URL{ - Scheme: "https", - Host: "bip.to", + Scheme: d.url.Scheme, + Host: d.url.Host, Path: fmt.Sprintf("/tx/%s", tx), RawQuery: rawQuery, } @@ -77,6 +79,28 @@ func (d *DeepLink) SetGasCoin(id uint64) *DeepLink { return d } +func (d *DeepLink) SetUrl(value string) (*DeepLink, error) { + u, err := url.Parse(value) + + if err != nil { + return d, err + } + + d.url = u + + return d, nil +} + +func (d *DeepLink) MustSetUrl(value string) *DeepLink { + d, err := d.SetUrl(value) + + if err != nil { + panic(err) + } + + return d +} + func NewDeepLink(data Data) (*DeepLink, error) { d := new(DeepLink) @@ -86,5 +110,10 @@ func NewDeepLink(data Data) (*DeepLink, error) { } d.Data = bytes + d.url = &url.URL{ + Scheme: "https", + Host: "bip.to", + } + return d.setType(data.Type()), nil } diff --git a/transaction/deeplink_example_test.go b/transaction/deeplink_example_test.go index d956a12..3ead6d3 100644 --- a/transaction/deeplink_example_test.go +++ b/transaction/deeplink_example_test.go @@ -2,8 +2,9 @@ package transaction_test import ( "fmt" - "github.com/MinterTeam/minter-go-sdk/v2/transaction" "math/big" + + "github.com/MinterTeam/minter-go-sdk/v2/transaction" ) func ExampleNewDeepLink() { @@ -35,3 +36,19 @@ func ExampleDeepLink_CreateLink() { // Output: // https://bip.to/tx/9AGg3wGUdjOYDAABOd070ko_VOBkdPqUHhaIiscjBInoAACOY3VzdG9tIG1lc3NhZ2XAwAM?p=cGFzcw } + +func ExampleDeepLink_CreateLink_customHost() { + link, _ := transaction.NewDeepLink( + transaction.NewSendData(). + MustSetTo("Mx7633980c000139dd3bd24a3f54e06474fa941e16"). + SetCoin(1). + SetValue(transaction.BipToPip(big.NewInt(10))), + ) + + link.MustSetUrl("https://testnet.bip.to").SetPayload([]byte("custom message")).SetGasCoin(3) + + data, _ := link.CreateLink("pass") + fmt.Println(data) + // Output: + // https://testnet.bip.to/tx/9AGg3wGUdjOYDAABOd070ko_VOBkdPqUHhaIiscjBInoAACOY3VzdG9tIG1lc3NhZ2XAwAM?p=cGFzcw +} From 341040e9946685c9aaac325cb1ca8751c6bfe3db Mon Sep 17 00:00:00 2001 From: Vladimir Yuldashev Date: Mon, 17 May 2021 14:32:22 +0200 Subject: [PATCH 2/4] deep link: allow to override url --- transaction/deeplink.go | 7 ++++--- transaction/deeplink_example_test.go | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/transaction/deeplink.go b/transaction/deeplink.go index ad20510..09afd67 100644 --- a/transaction/deeplink.go +++ b/transaction/deeplink.go @@ -3,8 +3,9 @@ package transaction import ( "encoding/base64" "fmt" - "github.com/ethereum/go-ethereum/rlp" "net/url" + + "github.com/ethereum/go-ethereum/rlp" ) type DeepLink struct { @@ -92,13 +93,13 @@ func (d *DeepLink) SetUrl(value string) (*DeepLink, error) { } func (d *DeepLink) MustSetUrl(value string) *DeepLink { - d, err := d.SetUrl(value) + dl, err := d.SetUrl(value) if err != nil { panic(err) } - return d + return dl } func NewDeepLink(data Data) (*DeepLink, error) { diff --git a/transaction/deeplink_example_test.go b/transaction/deeplink_example_test.go index 3ead6d3..a33860d 100644 --- a/transaction/deeplink_example_test.go +++ b/transaction/deeplink_example_test.go @@ -2,9 +2,8 @@ package transaction_test import ( "fmt" - "math/big" - "github.com/MinterTeam/minter-go-sdk/v2/transaction" + "math/big" ) func ExampleNewDeepLink() { From 5a9d1036f6b9a9520f6a10fb66410de8e2d1cfa6 Mon Sep 17 00:00:00 2001 From: Vladimir Yuldashev Date: Wed, 19 May 2021 23:52:41 +0200 Subject: [PATCH 3/4] update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87392e8..3f493c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## [v2.3.0](https://github.com/MinterTeam/minter-go-sdk/tree/v2.2.0) (2021-05-20) + +[Full Changelog](https://github.com/MinterTeam/minter-go-sdk/compare/v2.2.0...v2.3.0) + +- DeepLink: Allow to set custom URL [#11](https://github.com/MinterTeam/minter-go-sdk/pull/11) + ## [v2.2.0](https://github.com/MinterTeam/minter-go-sdk/tree/v2.2.0) (2021-04-12) [Full Changelog](https://github.com/MinterTeam/minter-go-sdk/compare/v2.1.1...v2.2.0) From 32760a58bc16c601686619df1ea3c0022a2d5b41 Mon Sep 17 00:00:00 2001 From: Vladimir Yuldashev Date: Wed, 19 May 2021 23:54:05 +0200 Subject: [PATCH 4/4] update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f493c8..5189b51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [v2.3.0](https://github.com/MinterTeam/minter-go-sdk/tree/v2.2.0) (2021-05-20) +## [v2.3.0](https://github.com/MinterTeam/minter-go-sdk/tree/v2.3.0) (2021-05-20) [Full Changelog](https://github.com/MinterTeam/minter-go-sdk/compare/v2.2.0...v2.3.0)