Skip to content

Commit

Permalink
Merge pull request #11 from vyuldashev/v2
Browse files Browse the repository at this point in the history
Deep Link: Allow to override URL
  • Loading branch information
Klimov Sergey authored May 19, 2021
2 parents b11c39d + 32760a5 commit 52cd519
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [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)

- 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)
Expand Down
36 changes: 33 additions & 3 deletions transaction/deeplink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -14,6 +15,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.
Expand All @@ -29,8 +32,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,
}
Expand Down Expand Up @@ -77,6 +80,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 {
dl, err := d.SetUrl(value)

if err != nil {
panic(err)
}

return dl
}

func NewDeepLink(data Data) (*DeepLink, error) {
d := new(DeepLink)

Expand All @@ -86,5 +111,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
}
16 changes: 16 additions & 0 deletions transaction/deeplink_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,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
}

0 comments on commit 52cd519

Please sign in to comment.