mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-24 13:45:49 +00:00
chore(samples): replace tab for 4 spaces
This commit is contained in:
@@ -1,111 +1,111 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/path"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/path"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
|
||||
pathtypes "github.com/Peersyst/xrpl-go/xrpl/queries/path/types"
|
||||
pathtypes "github.com/Peersyst/xrpl-go/xrpl/queries/path/types"
|
||||
)
|
||||
|
||||
const (
|
||||
DestinationAccount = types.Address("rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj")
|
||||
DestinationAccount = types.Address("rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj")
|
||||
)
|
||||
|
||||
var (
|
||||
DestinationAmount = types.IssuedCurrencyAmount{
|
||||
Issuer: "rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc",
|
||||
Currency: "USD",
|
||||
Value: "0.001",
|
||||
}
|
||||
DestinationAmount = types.IssuedCurrencyAmount{
|
||||
Issuer: "rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc",
|
||||
Currency: "USD",
|
||||
Value: "0.001",
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
if err := client.FundWallet(&wallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
if err := client.FundWallet(&wallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet funded")
|
||||
fmt.Println()
|
||||
fmt.Println("💸 Wallet funded")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Getting paths...")
|
||||
res, err := client.GetRipplePathFind(&path.RipplePathFindRequest{
|
||||
SourceAccount: wallet.GetAddress(),
|
||||
SourceCurrencies: []pathtypes.RipplePathFindCurrency{
|
||||
{
|
||||
Currency: "XRP",
|
||||
},
|
||||
},
|
||||
DestinationAccount: DestinationAccount,
|
||||
DestinationAmount: DestinationAmount,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Getting paths...")
|
||||
res, err := client.GetRipplePathFind(&path.RipplePathFindRequest{
|
||||
SourceAccount: wallet.GetAddress(),
|
||||
SourceCurrencies: []pathtypes.RipplePathFindCurrency{
|
||||
{
|
||||
Currency: "XRP",
|
||||
},
|
||||
},
|
||||
DestinationAccount: DestinationAccount,
|
||||
DestinationAmount: DestinationAmount,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("🌐 Computed paths: %d\n", len(res.Alternatives))
|
||||
fmt.Println()
|
||||
fmt.Printf("🌐 Computed paths: %d\n", len(res.Alternatives))
|
||||
fmt.Println()
|
||||
|
||||
if len(res.Alternatives) == 0 {
|
||||
fmt.Println("❌ No alternatives found")
|
||||
return
|
||||
}
|
||||
if len(res.Alternatives) == 0 {
|
||||
fmt.Println("❌ No alternatives found")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Submitting Payment through path: ", res.Alternatives[0].PathsComputed)
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: wallet.GetAddress(),
|
||||
},
|
||||
Destination: DestinationAccount,
|
||||
Amount: DestinationAmount,
|
||||
Paths: res.Alternatives[0].PathsComputed,
|
||||
}
|
||||
fmt.Println("⏳ Submitting Payment through path: ", res.Alternatives[0].PathsComputed)
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: wallet.GetAddress(),
|
||||
},
|
||||
Destination: DestinationAccount,
|
||||
Amount: DestinationAmount,
|
||||
Paths: res.Alternatives[0].PathsComputed,
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
flatP := p.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatP); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Autofill(&flatP); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, hash, err := wallet.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, hash, err := wallet.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
txRes, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
txRes, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", txRes.Validated)
|
||||
fmt.Println("✅ Payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", txRes.Validated)
|
||||
}
|
||||
|
||||
@@ -1,122 +1,122 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/path"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/websocket"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/path"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/websocket"
|
||||
|
||||
pathtypes "github.com/Peersyst/xrpl-go/xrpl/queries/path/types"
|
||||
pathtypes "github.com/Peersyst/xrpl-go/xrpl/queries/path/types"
|
||||
)
|
||||
|
||||
const (
|
||||
DestinationAccount = types.Address("rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj")
|
||||
DestinationAccount = types.Address("rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj")
|
||||
)
|
||||
|
||||
var (
|
||||
DestinationAmount = types.IssuedCurrencyAmount{
|
||||
Issuer: "rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc",
|
||||
Currency: "USD",
|
||||
Value: "0.001",
|
||||
}
|
||||
DestinationAmount = types.IssuedCurrencyAmount{
|
||||
Issuer: "rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc",
|
||||
Currency: "USD",
|
||||
Value: "0.001",
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("⏳ Connecting to testnet...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
fmt.Println("⏳ Connecting to testnet...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("❌ Failed to connect to testnet")
|
||||
return
|
||||
}
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("❌ Failed to connect to testnet")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Connected to testnet")
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Connected to testnet")
|
||||
fmt.Println()
|
||||
|
||||
wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
if err := client.FundWallet(&wallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
if err := client.FundWallet(&wallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet funded")
|
||||
fmt.Println()
|
||||
fmt.Println("💸 Wallet funded")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Getting paths...")
|
||||
res, err := client.GetRipplePathFind(&path.RipplePathFindRequest{
|
||||
SourceAccount: wallet.GetAddress(),
|
||||
SourceCurrencies: []pathtypes.RipplePathFindCurrency{
|
||||
{
|
||||
Currency: "XRP",
|
||||
},
|
||||
},
|
||||
DestinationAccount: DestinationAccount,
|
||||
DestinationAmount: DestinationAmount,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Getting paths...")
|
||||
res, err := client.GetRipplePathFind(&path.RipplePathFindRequest{
|
||||
SourceAccount: wallet.GetAddress(),
|
||||
SourceCurrencies: []pathtypes.RipplePathFindCurrency{
|
||||
{
|
||||
Currency: "XRP",
|
||||
},
|
||||
},
|
||||
DestinationAccount: DestinationAccount,
|
||||
DestinationAmount: DestinationAmount,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("🌐 Computed paths: %d\n", len(res.Alternatives))
|
||||
fmt.Println()
|
||||
fmt.Printf("🌐 Computed paths: %d\n", len(res.Alternatives))
|
||||
fmt.Println()
|
||||
|
||||
if len(res.Alternatives) == 0 {
|
||||
fmt.Println("❌ No alternatives found")
|
||||
return
|
||||
}
|
||||
if len(res.Alternatives) == 0 {
|
||||
fmt.Println("❌ No alternatives found")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Submitting Payment through path: ", res.Alternatives[0].PathsComputed)
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: wallet.GetAddress(),
|
||||
},
|
||||
Destination: DestinationAccount,
|
||||
Amount: DestinationAmount,
|
||||
Paths: res.Alternatives[0].PathsComputed,
|
||||
}
|
||||
fmt.Println("⏳ Submitting Payment through path: ", res.Alternatives[0].PathsComputed)
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: wallet.GetAddress(),
|
||||
},
|
||||
Destination: DestinationAccount,
|
||||
Amount: DestinationAmount,
|
||||
Paths: res.Alternatives[0].PathsComputed,
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
flatP := p.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatP); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Autofill(&flatP); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, hash, err := wallet.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, hash, err := wallet.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
txRes, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
txRes, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", txRes.Validated)
|
||||
fmt.Println("✅ Payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", txRes.Validated)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user