-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: implement TonX API client with new dependencies
- Add a new file `client.go` in the `app/infra/tonx` directory - Define the `Options` struct and the `APIClient` struct in the `client.go` file - Implement the `NewAPIClient` function in the `client.go` file - Update `go.mod` to include `github.com/stretchr/testify v1.9.0` and `github.com/xssnick/tonutils-go v1.9.9` - Also add `github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc` and `github.com/oasisprotocol/curve25519-voi v0.0.0-20220328075252-7dd334e3daae` to `go.mod` - Include `github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2` and `github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3` in `go.mod` - Add `github.com/stretchr/objx v0.5.2` to `go.mod` Signed-off-by: Sean Zheng <[email protected]>
- Loading branch information
1 parent
e706b25
commit 723aba8
Showing
3 changed files
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package tonx | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blackhorseya/ryze/pkg/contextx" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/xssnick/tonutils-go/liteclient" | ||
"github.com/xssnick/tonutils-go/ton" | ||
) | ||
|
||
const ( | ||
mainnetConfigURL = "https://ton.org/global.config.json" | ||
testnetConfigURL = "https://ton-blockchain.github.io/testnet-global.config.json" | ||
) | ||
|
||
// Options is a struct that represents the options of the API client. | ||
type Options struct { | ||
Network string `json:"network" yaml:"network"` | ||
} | ||
|
||
// APIClient is a struct that represents the API client. | ||
type APIClient struct { | ||
*ton.APIClient | ||
mock.Mock | ||
} | ||
|
||
// NewAPIClient is a function that creates a new API client. | ||
func NewAPIClient(options Options) (*APIClient, error) { | ||
configURL := mainnetConfigURL | ||
if options.Network == "testnet" { | ||
configURL = testnetConfigURL | ||
} | ||
|
||
client := liteclient.NewConnectionPool() | ||
|
||
err := client.AddConnectionsFromConfigUrl(contextx.Background(), configURL) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to add connections from config: %w", err) | ||
} | ||
|
||
return &APIClient{ | ||
APIClient: ton.NewAPIClient(client), | ||
}, nil | ||
} |
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