mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-26 23:45:50 +00:00
* refactor: replace claim client with exported version * refactor: replace shamir coordinator client with exported version * chore: update rddl-claim-service/client dependency * chore: update shamir-coordinator-service client Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> Signed-off-by: Julian Strobl <jmastr@mailbox.org>
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package clients
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"github.com/planetmint/planetmint-go/config"
|
|
"github.com/rddl-network/go-utils/tls"
|
|
"github.com/rddl-network/shamir-coordinator-service/client"
|
|
)
|
|
|
|
var ShamirCoordinatorServiceClient client.IShamirCoordinatorClient
|
|
|
|
func lazyLoadShamirCoordinatorClient() client.IShamirCoordinatorClient {
|
|
if ShamirCoordinatorServiceClient != nil {
|
|
return ShamirCoordinatorServiceClient
|
|
}
|
|
cfg := config.GetConfig()
|
|
httpsClient, err := tls.Get2WayTLSClient(cfg.CertsPath)
|
|
if err != nil {
|
|
defer log.Fatal("fatal error setting up mutual tls client for shamir coordinator")
|
|
}
|
|
ShamirCoordinatorServiceClient = client.NewShamirCoordinatorClient(cfg.IssuerHost, httpsClient)
|
|
return ShamirCoordinatorServiceClient
|
|
}
|
|
|
|
func SendTokens(ctx context.Context, recipient string, amount string, asset string) (txID string, err error) {
|
|
client := lazyLoadShamirCoordinatorClient()
|
|
res, err := client.SendTokens(ctx, recipient, amount, asset)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return res.TxID, nil
|
|
}
|
|
|
|
func ReIssueAsset(ctx context.Context, asset string, amount string) (txID string, err error) {
|
|
client := lazyLoadShamirCoordinatorClient()
|
|
res, err := client.ReIssueAsset(ctx, asset, amount)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return res.TxID, nil
|
|
}
|
|
|
|
func IssueNFTAsset(ctx context.Context, name string, machineAddress string, domain string) (assetID string, contract string, hexTx string, err error) {
|
|
client := lazyLoadShamirCoordinatorClient()
|
|
res, err := client.IssueMachineNFT(ctx, name, machineAddress, domain)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return res.Asset, res.Contract, res.HexTX, nil
|
|
}
|