mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-21 20:25:51 +00:00
chore(samples): replace tab for 4 spaces
This commit is contained in:
@@ -1,115 +1,115 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/xrpl/currency"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
transactions "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/currency"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
transactions "github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
w, err := wallet.FromSeed("sEdSMVV4dJ1JbdBxmakRR4Puu3XVZz2", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w, err := wallet.FromSeed("sEdSMVV4dJ1JbdBxmakRR4Puu3XVZz2", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
receiverWallet, err := wallet.FromSeed("sEd7d8Ci9nevdLCeUMctF3uGXp9WQqJ", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
receiverWallet, err := wallet.FromSeed("sEd7d8Ci9nevdLCeUMctF3uGXp9WQqJ", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
balance, err := client.GetXrpBalance(w.GetAddress())
|
||||
balance, err := client.GetXrpBalance(w.GetAddress())
|
||||
|
||||
if err != nil || balance == "0" {
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
err = client.FundWallet(&w)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallet funded")
|
||||
}
|
||||
if err != nil || balance == "0" {
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
err = client.FundWallet(&w)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallet funded")
|
||||
}
|
||||
|
||||
balance, _ = client.GetXrpBalance(w.GetAddress())
|
||||
balance, _ = client.GetXrpBalance(w.GetAddress())
|
||||
|
||||
fmt.Printf("💸 Balance: %s\n", balance)
|
||||
fmt.Printf("💸 Balance: %s\n", balance)
|
||||
|
||||
amount, err := currency.XrpToDrops("1")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
amount, err := currency.XrpToDrops("1")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
amountUint, err := strconv.ParseUint(amount, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
amountUint, err := strconv.ParseUint(amount, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Sending payment...")
|
||||
payment := transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(w.GetAddress()),
|
||||
Memos: []types.MemoWrapper{
|
||||
{
|
||||
Memo: types.Memo{
|
||||
MemoData: hex.EncodeToString([]byte("Hello, World!")),
|
||||
MemoFormat: hex.EncodeToString([]byte("plain")),
|
||||
MemoType: hex.EncodeToString([]byte("message")),
|
||||
},
|
||||
},
|
||||
{
|
||||
Memo: types.Memo{
|
||||
MemoData: hex.EncodeToString([]byte("Hello, World 2!")),
|
||||
MemoFormat: hex.EncodeToString([]byte("text/plain")),
|
||||
MemoType: hex.EncodeToString([]byte("message2")),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Destination: types.Address(receiverWallet.GetAddress()),
|
||||
Amount: types.XRPCurrencyAmount(amountUint),
|
||||
}
|
||||
fmt.Println("⏳ Sending payment...")
|
||||
payment := transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(w.GetAddress()),
|
||||
Memos: []types.MemoWrapper{
|
||||
{
|
||||
Memo: types.Memo{
|
||||
MemoData: hex.EncodeToString([]byte("Hello, World!")),
|
||||
MemoFormat: hex.EncodeToString([]byte("plain")),
|
||||
MemoType: hex.EncodeToString([]byte("message")),
|
||||
},
|
||||
},
|
||||
{
|
||||
Memo: types.Memo{
|
||||
MemoData: hex.EncodeToString([]byte("Hello, World 2!")),
|
||||
MemoFormat: hex.EncodeToString([]byte("text/plain")),
|
||||
MemoType: hex.EncodeToString([]byte("message2")),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Destination: types.Address(receiverWallet.GetAddress()),
|
||||
Amount: types.XRPCurrencyAmount(amountUint),
|
||||
}
|
||||
|
||||
flatTx := payment.Flatten()
|
||||
flatTx := payment.Flatten()
|
||||
|
||||
err = client.Autofill(&flatTx)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatTx)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err := w.Sign(flatTx)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err := w.Sign(flatTx)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, true)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, true)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println("✅ Payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user