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,208 +1,208 @@
|
||||
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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
var (
|
||||
CreatePaymentTx = func(sender, receiver *wallet.Wallet, amount txnTypes.CurrencyAmount) *transaction.Payment {
|
||||
return &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: sender.GetAddress(),
|
||||
TransactionType: transaction.PaymentTx,
|
||||
Flags: txnTypes.TfInnerBatchTxn,
|
||||
},
|
||||
Amount: amount,
|
||||
Destination: receiver.GetAddress(),
|
||||
}
|
||||
}
|
||||
CreatePaymentTx = func(sender, receiver *wallet.Wallet, amount txnTypes.CurrencyAmount) *transaction.Payment {
|
||||
return &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: sender.GetAddress(),
|
||||
TransactionType: transaction.PaymentTx,
|
||||
Flags: txnTypes.TfInnerBatchTxn,
|
||||
},
|
||||
Amount: amount,
|
||||
Destination: receiver.GetAddress(),
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Configure the client
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := rpc.NewClient(cfg)
|
||||
// Configure the client
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Create and fund wallets
|
||||
userWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Create and fund wallets
|
||||
userWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
user2Wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
user2Wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&userWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&user2Wallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallets funded")
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&userWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&user2Wallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallets funded")
|
||||
|
||||
// Check initial balances
|
||||
userBalance, err := client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
userBalance = "0"
|
||||
}
|
||||
user2Balance, err := client.GetXrpBalance(user2Wallet.ClassicAddress)
|
||||
if err != nil {
|
||||
user2Balance = "0"
|
||||
}
|
||||
// Check initial balances
|
||||
userBalance, err := client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
userBalance = "0"
|
||||
}
|
||||
user2Balance, err := client.GetXrpBalance(user2Wallet.ClassicAddress)
|
||||
if err != nil {
|
||||
user2Balance = "0"
|
||||
}
|
||||
|
||||
receiverBalance, err := client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
receiverBalance = "0"
|
||||
}
|
||||
receiverBalance, err := client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
receiverBalance = "0"
|
||||
}
|
||||
|
||||
fmt.Printf("💳 User initial balance: %s XRP\n", userBalance)
|
||||
fmt.Printf("💳 User2 initial balance: %s XRP\n", user2Balance)
|
||||
fmt.Printf("💳 Receiver initial balance: %s XRP\n", receiverBalance)
|
||||
fmt.Println()
|
||||
fmt.Printf("💳 User initial balance: %s XRP\n", userBalance)
|
||||
fmt.Printf("💳 User2 initial balance: %s XRP\n", user2Balance)
|
||||
fmt.Printf("💳 Receiver initial balance: %s XRP\n", receiverBalance)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("Batch transaction test\n")
|
||||
fmt.Printf("Batch transaction test\n")
|
||||
|
||||
// Create test batch transaction
|
||||
batchTx := &transaction.Batch{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: txnTypes.Address(userWallet.ClassicAddress),
|
||||
TransactionType: transaction.BatchTx,
|
||||
},
|
||||
RawTransactions: []txnTypes.RawTransaction{
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
},
|
||||
}
|
||||
batchTx.SetAllOrNothingFlag()
|
||||
// Create test batch transaction
|
||||
batchTx := &transaction.Batch{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: txnTypes.Address(userWallet.ClassicAddress),
|
||||
TransactionType: transaction.BatchTx,
|
||||
},
|
||||
RawTransactions: []txnTypes.RawTransaction{
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
},
|
||||
}
|
||||
batchTx.SetAllOrNothingFlag()
|
||||
|
||||
flattenedBatchTx := batchTx.Flatten()
|
||||
fmt.Println("⏳ Autofilling flattened batch transaction...")
|
||||
if err := client.Autofill(&flattenedBatchTx); err != nil {
|
||||
fmt.Println("Autofill error:", err)
|
||||
return
|
||||
}
|
||||
flattenedBatchTx := batchTx.Flatten()
|
||||
fmt.Println("⏳ Autofilling flattened batch transaction...")
|
||||
if err := client.Autofill(&flattenedBatchTx); err != nil {
|
||||
fmt.Println("Autofill error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Signing batch transaction...")
|
||||
response, err := client.SubmitTxAndWait(flattenedBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Signing batch transaction...")
|
||||
response, err := client.SubmitTxAndWait(flattenedBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Batch transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Batch transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
|
||||
// Check final balances
|
||||
finalUserBalance, err := client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUserBalance = "0"
|
||||
}
|
||||
finalReceiverBalance, err := client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalReceiverBalance = "0"
|
||||
}
|
||||
// Check final balances
|
||||
finalUserBalance, err := client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUserBalance = "0"
|
||||
}
|
||||
finalReceiverBalance, err := client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalReceiverBalance = "0"
|
||||
}
|
||||
|
||||
fmt.Printf("💳 User final balance: %s XRP\n", finalUserBalance)
|
||||
fmt.Printf("💳 User final balance: %s XRP\n", finalUserBalance)
|
||||
|
||||
fmt.Printf("💳 Receiver final balance: %s XRP\n", finalReceiverBalance)
|
||||
fmt.Printf("💳 Receiver final balance: %s XRP\n", finalReceiverBalance)
|
||||
|
||||
fmt.Println()
|
||||
fmt.Printf("Multisig Batch transaction test\n")
|
||||
fmt.Println()
|
||||
fmt.Printf("Multisig Batch transaction test\n")
|
||||
|
||||
// Create test batch transaction
|
||||
multiBatchTx := &transaction.Batch{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: txnTypes.Address(userWallet.ClassicAddress),
|
||||
TransactionType: transaction.BatchTx,
|
||||
},
|
||||
RawTransactions: []txnTypes.RawTransaction{
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
{RawTransaction: CreatePaymentTx(&user2Wallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
},
|
||||
BatchSigners: []txnTypes.BatchSigner{
|
||||
{
|
||||
BatchSigner: txnTypes.BatchSignerData{
|
||||
Account: txnTypes.Address(user2Wallet.ClassicAddress),
|
||||
SigningPubKey: user2Wallet.PublicKey,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
multiBatchTx.SetAllOrNothingFlag()
|
||||
// Create test batch transaction
|
||||
multiBatchTx := &transaction.Batch{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: txnTypes.Address(userWallet.ClassicAddress),
|
||||
TransactionType: transaction.BatchTx,
|
||||
},
|
||||
RawTransactions: []txnTypes.RawTransaction{
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
{RawTransaction: CreatePaymentTx(&user2Wallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
},
|
||||
BatchSigners: []txnTypes.BatchSigner{
|
||||
{
|
||||
BatchSigner: txnTypes.BatchSignerData{
|
||||
Account: txnTypes.Address(user2Wallet.ClassicAddress),
|
||||
SigningPubKey: user2Wallet.PublicKey,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
multiBatchTx.SetAllOrNothingFlag()
|
||||
|
||||
flattenedMultiBatchTx := multiBatchTx.Flatten()
|
||||
fmt.Println("⏳ Autofilling flattened multi batch transaction...")
|
||||
if err := client.AutofillMultisigned(&flattenedMultiBatchTx, 1); err != nil {
|
||||
fmt.Println("Autofill error:", err)
|
||||
return
|
||||
}
|
||||
flattenedMultiBatchTx := multiBatchTx.Flatten()
|
||||
fmt.Println("⏳ Autofilling flattened multi batch transaction...")
|
||||
if err := client.AutofillMultisigned(&flattenedMultiBatchTx, 1); err != nil {
|
||||
fmt.Println("Autofill error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Signing multi batch transaction...")
|
||||
if err := wallet.SignMultiBatch(user2Wallet, &flattenedMultiBatchTx, nil); err != nil {
|
||||
fmt.Println("Signing error:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Signing multi batch transaction...")
|
||||
if err := wallet.SignMultiBatch(user2Wallet, &flattenedMultiBatchTx, nil); err != nil {
|
||||
fmt.Println("Signing error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxAndWait(flattenedMultiBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
response, err = client.SubmitTxAndWait(flattenedMultiBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Multisig Batch transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Multisig Batch transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
|
||||
// Check final balances
|
||||
finalUser2Balance, err := client.GetXrpBalance(user2Wallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUser2Balance = "0"
|
||||
}
|
||||
finalUserBalance, err = client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUserBalance = "0"
|
||||
}
|
||||
finalReceiverBalance, err = client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalReceiverBalance = "0"
|
||||
}
|
||||
fmt.Printf("💳 User final balance: %s XRP\n", finalUserBalance)
|
||||
fmt.Printf("💳 User2 final balance: %s XRP\n", finalUser2Balance)
|
||||
fmt.Printf("💳 Receiver final balance: %s XRP\n", finalReceiverBalance)
|
||||
// Check final balances
|
||||
finalUser2Balance, err := client.GetXrpBalance(user2Wallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUser2Balance = "0"
|
||||
}
|
||||
finalUserBalance, err = client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUserBalance = "0"
|
||||
}
|
||||
finalReceiverBalance, err = client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalReceiverBalance = "0"
|
||||
}
|
||||
fmt.Printf("💳 User final balance: %s XRP\n", finalUserBalance)
|
||||
fmt.Printf("💳 User2 final balance: %s XRP\n", finalUser2Balance)
|
||||
fmt.Printf("💳 Receiver final balance: %s XRP\n", finalReceiverBalance)
|
||||
}
|
||||
|
||||
@@ -1,210 +1,210 @@
|
||||
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/transaction"
|
||||
txnTypes "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/xrpl/websocket/types"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/xrpl/websocket/types"
|
||||
)
|
||||
|
||||
var (
|
||||
CreatePaymentTx = func(sender, receiver *wallet.Wallet, amount txnTypes.CurrencyAmount) *transaction.Payment {
|
||||
return &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: sender.GetAddress(),
|
||||
TransactionType: transaction.PaymentTx,
|
||||
Flags: txnTypes.TfInnerBatchTxn,
|
||||
},
|
||||
Amount: amount,
|
||||
Destination: receiver.GetAddress(),
|
||||
}
|
||||
}
|
||||
CreatePaymentTx = func(sender, receiver *wallet.Wallet, amount txnTypes.CurrencyAmount) *transaction.Payment {
|
||||
return &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: sender.GetAddress(),
|
||||
TransactionType: transaction.PaymentTx,
|
||||
Flags: txnTypes.TfInnerBatchTxn,
|
||||
},
|
||||
Amount: amount,
|
||||
Destination: receiver.GetAddress(),
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Connect to testnet
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
// Connect to testnet
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Create and fund wallets
|
||||
userWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Create and fund wallets
|
||||
userWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
user2Wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
user2Wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&userWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&user2Wallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallets funded")
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&userWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&user2Wallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallets funded")
|
||||
|
||||
// Check initial balances
|
||||
userBalance, err := client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
userBalance = "0"
|
||||
}
|
||||
user2Balance, err := client.GetXrpBalance(user2Wallet.ClassicAddress)
|
||||
if err != nil {
|
||||
user2Balance = "0"
|
||||
}
|
||||
// Check initial balances
|
||||
userBalance, err := client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
userBalance = "0"
|
||||
}
|
||||
user2Balance, err := client.GetXrpBalance(user2Wallet.ClassicAddress)
|
||||
if err != nil {
|
||||
user2Balance = "0"
|
||||
}
|
||||
|
||||
receiverBalance, err := client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
receiverBalance = "0"
|
||||
}
|
||||
receiverBalance, err := client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
receiverBalance = "0"
|
||||
}
|
||||
|
||||
fmt.Printf("💳 User initial balance: %s XRP\n", userBalance)
|
||||
fmt.Printf("💳 User2 initial balance: %s XRP\n", user2Balance)
|
||||
fmt.Printf("💳 Receiver initial balance: %s XRP\n", receiverBalance)
|
||||
fmt.Println()
|
||||
fmt.Printf("💳 User initial balance: %s XRP\n", userBalance)
|
||||
fmt.Printf("💳 User2 initial balance: %s XRP\n", user2Balance)
|
||||
fmt.Printf("💳 Receiver initial balance: %s XRP\n", receiverBalance)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("Batch transaction test\n")
|
||||
fmt.Printf("Batch transaction test\n")
|
||||
|
||||
// Create test batch transaction
|
||||
batchTx := &transaction.Batch{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: txnTypes.Address(userWallet.ClassicAddress),
|
||||
TransactionType: transaction.BatchTx,
|
||||
},
|
||||
RawTransactions: []txnTypes.RawTransaction{
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
},
|
||||
}
|
||||
batchTx.SetAllOrNothingFlag()
|
||||
// Create test batch transaction
|
||||
batchTx := &transaction.Batch{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: txnTypes.Address(userWallet.ClassicAddress),
|
||||
TransactionType: transaction.BatchTx,
|
||||
},
|
||||
RawTransactions: []txnTypes.RawTransaction{
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
},
|
||||
}
|
||||
batchTx.SetAllOrNothingFlag()
|
||||
|
||||
flattenedBatchTx := batchTx.Flatten()
|
||||
fmt.Println("⏳ Autofilling flattened batch transaction...")
|
||||
if err := client.Autofill(&flattenedBatchTx); err != nil {
|
||||
fmt.Println("Autofill error:", err)
|
||||
return
|
||||
}
|
||||
flattenedBatchTx := batchTx.Flatten()
|
||||
fmt.Println("⏳ Autofilling flattened batch transaction...")
|
||||
if err := client.Autofill(&flattenedBatchTx); err != nil {
|
||||
fmt.Println("Autofill error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Signing batch transaction...")
|
||||
response, err := client.SubmitTxAndWait(flattenedBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Signing batch transaction...")
|
||||
response, err := client.SubmitTxAndWait(flattenedBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Batch transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Batch transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
|
||||
// Check final balances
|
||||
finalUserBalance, err := client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUserBalance = "0"
|
||||
}
|
||||
finalReceiverBalance, err := client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalReceiverBalance = "0"
|
||||
}
|
||||
// Check final balances
|
||||
finalUserBalance, err := client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUserBalance = "0"
|
||||
}
|
||||
finalReceiverBalance, err := client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalReceiverBalance = "0"
|
||||
}
|
||||
|
||||
fmt.Printf("💳 User final balance: %s XRP\n", finalUserBalance)
|
||||
fmt.Printf("💳 User final balance: %s XRP\n", finalUserBalance)
|
||||
|
||||
fmt.Printf("💳 Receiver final balance: %s XRP\n", finalReceiverBalance)
|
||||
fmt.Printf("💳 Receiver final balance: %s XRP\n", finalReceiverBalance)
|
||||
|
||||
fmt.Println()
|
||||
fmt.Printf("Multisig Batch transaction test\n")
|
||||
fmt.Println()
|
||||
fmt.Printf("Multisig Batch transaction test\n")
|
||||
|
||||
// Create test batch transaction
|
||||
multiBatchTx := &transaction.Batch{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: txnTypes.Address(userWallet.ClassicAddress),
|
||||
TransactionType: transaction.BatchTx,
|
||||
},
|
||||
RawTransactions: []txnTypes.RawTransaction{
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
{RawTransaction: CreatePaymentTx(&user2Wallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
},
|
||||
BatchSigners: []txnTypes.BatchSigner{
|
||||
{
|
||||
BatchSigner: txnTypes.BatchSignerData{
|
||||
Account: txnTypes.Address(user2Wallet.ClassicAddress),
|
||||
SigningPubKey: user2Wallet.PublicKey,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
multiBatchTx.SetAllOrNothingFlag()
|
||||
// Create test batch transaction
|
||||
multiBatchTx := &transaction.Batch{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: txnTypes.Address(userWallet.ClassicAddress),
|
||||
TransactionType: transaction.BatchTx,
|
||||
},
|
||||
RawTransactions: []txnTypes.RawTransaction{
|
||||
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
{RawTransaction: CreatePaymentTx(&user2Wallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
|
||||
},
|
||||
BatchSigners: []txnTypes.BatchSigner{
|
||||
{
|
||||
BatchSigner: txnTypes.BatchSignerData{
|
||||
Account: txnTypes.Address(user2Wallet.ClassicAddress),
|
||||
SigningPubKey: user2Wallet.PublicKey,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
multiBatchTx.SetAllOrNothingFlag()
|
||||
|
||||
flattenedMultiBatchTx := multiBatchTx.Flatten()
|
||||
fmt.Println("⏳ Autofilling flattened multi batch transaction...")
|
||||
if err := client.AutofillMultisigned(&flattenedMultiBatchTx, 1); err != nil {
|
||||
fmt.Println("Autofill error:", err)
|
||||
return
|
||||
}
|
||||
flattenedMultiBatchTx := multiBatchTx.Flatten()
|
||||
fmt.Println("⏳ Autofilling flattened multi batch transaction...")
|
||||
if err := client.AutofillMultisigned(&flattenedMultiBatchTx, 1); err != nil {
|
||||
fmt.Println("Autofill error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Signing multi batch transaction...")
|
||||
if err := wallet.SignMultiBatch(user2Wallet, &flattenedMultiBatchTx, nil); err != nil {
|
||||
fmt.Println("Signing error:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Signing multi batch transaction...")
|
||||
if err := wallet.SignMultiBatch(user2Wallet, &flattenedMultiBatchTx, nil); err != nil {
|
||||
fmt.Println("Signing error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxAndWait(flattenedMultiBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
response, err = client.SubmitTxAndWait(flattenedMultiBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Multisig Batch transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Multisig Batch transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
|
||||
// Check final balances
|
||||
finalUser2Balance, err := client.GetXrpBalance(user2Wallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUser2Balance = "0"
|
||||
}
|
||||
finalUserBalance, err = client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUserBalance = "0"
|
||||
}
|
||||
finalReceiverBalance, err = client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalReceiverBalance = "0"
|
||||
}
|
||||
fmt.Printf("💳 User final balance: %s XRP\n", finalUserBalance)
|
||||
fmt.Printf("💳 User2 final balance: %s XRP\n", finalUser2Balance)
|
||||
fmt.Printf("💳 Receiver final balance: %s XRP\n", finalReceiverBalance)
|
||||
// Check final balances
|
||||
finalUser2Balance, err := client.GetXrpBalance(user2Wallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUser2Balance = "0"
|
||||
}
|
||||
finalUserBalance, err = client.GetXrpBalance(userWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalUserBalance = "0"
|
||||
}
|
||||
finalReceiverBalance, err = client.GetXrpBalance(receiverWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalReceiverBalance = "0"
|
||||
}
|
||||
fmt.Printf("💳 User final balance: %s XRP\n", finalUserBalance)
|
||||
fmt.Printf("💳 User2 final balance: %s XRP\n", finalUser2Balance)
|
||||
fmt.Printf("💳 Receiver final balance: %s XRP\n", finalReceiverBalance)
|
||||
}
|
||||
|
||||
@@ -1,162 +1,162 @@
|
||||
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/ledger-entry-types"
|
||||
"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/ledger-entry-types"
|
||||
"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"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Setting up wallets...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Sender wallet funded!")
|
||||
fmt.Println("⏳ Setting up wallets...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Sender wallet funded!")
|
||||
|
||||
if err := client.FundWallet(&receiverWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&receiverWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Receiver wallet funded!")
|
||||
fmt.Println()
|
||||
fmt.Println("💸 Receiver wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println("💳 Sender wallet:", w.ClassicAddress)
|
||||
fmt.Println("💳 Receiver wallet:", receiverWallet.ClassicAddress)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println("💳 Sender wallet:", w.ClassicAddress)
|
||||
fmt.Println("💳 Receiver wallet:", receiverWallet.ClassicAddress)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Creating check...")
|
||||
cc := &transaction.CheckCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
},
|
||||
Destination: receiverWallet.GetAddress(),
|
||||
SendMax: types.XRPCurrencyAmount(1000000),
|
||||
InvoiceID: "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
|
||||
}
|
||||
fmt.Println("⏳ Creating check...")
|
||||
cc := &transaction.CheckCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
},
|
||||
Destination: receiverWallet.GetAddress(),
|
||||
SendMax: types.XRPCurrencyAmount(1000000),
|
||||
InvoiceID: "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
|
||||
}
|
||||
|
||||
flatCc := cc.Flatten()
|
||||
flatCc := cc.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatCc); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Autofill(&flatCc); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err := w.Sign(flatCc)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err := w.Sign(flatCc)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
if !res.Validated {
|
||||
fmt.Println("❌ Check creation failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
if !res.Validated {
|
||||
fmt.Println("❌ Check creation failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Check created!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Check created!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
meta, ok := res.Meta.(map[string]interface{})
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not of type TxObjMeta")
|
||||
return
|
||||
}
|
||||
meta, ok := res.Meta.(map[string]interface{})
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not of type TxObjMeta")
|
||||
return
|
||||
}
|
||||
|
||||
var checkID string
|
||||
var checkID string
|
||||
|
||||
affectedNodes := meta["AffectedNodes"].([]interface{})
|
||||
affectedNodes := meta["AffectedNodes"].([]interface{})
|
||||
|
||||
for _, node := range affectedNodes {
|
||||
affectedNode, ok := node.(map[string]interface{})
|
||||
if !ok {
|
||||
fmt.Println("❌ Node is not of type map[string]interface{}")
|
||||
return
|
||||
}
|
||||
for _, node := range affectedNodes {
|
||||
affectedNode, ok := node.(map[string]interface{})
|
||||
if !ok {
|
||||
fmt.Println("❌ Node is not of type map[string]interface{}")
|
||||
return
|
||||
}
|
||||
|
||||
createdNode, ok := affectedNode["CreatedNode"].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
createdNode, ok := affectedNode["CreatedNode"].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if createdNode["LedgerEntryType"] == string(ledger.CheckEntry) {
|
||||
if createdNode["LedgerEntryType"] == string(ledger.CheckEntry) {
|
||||
|
||||
checkID = createdNode["LedgerIndex"].(string)
|
||||
}
|
||||
}
|
||||
checkID = createdNode["LedgerIndex"].(string)
|
||||
}
|
||||
}
|
||||
|
||||
if checkID == "" {
|
||||
fmt.Println("Check not found")
|
||||
return
|
||||
}
|
||||
if checkID == "" {
|
||||
fmt.Println("Check not found")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Cashing out check...")
|
||||
checkCash := &transaction.CheckCash{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: receiverWallet.GetAddress(),
|
||||
},
|
||||
CheckID: types.Hash256(checkID),
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
}
|
||||
fmt.Println("⏳ Cashing out check...")
|
||||
checkCash := &transaction.CheckCash{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: receiverWallet.GetAddress(),
|
||||
},
|
||||
CheckID: types.Hash256(checkID),
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
}
|
||||
|
||||
flatCheckCash := checkCash.Flatten()
|
||||
flatCheckCash := checkCash.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatCheckCash); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Autofill(&flatCheckCash); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err = receiverWallet.Sign(flatCheckCash)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err = receiverWallet.Sign(flatCheckCash)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Check cashed out!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Check cashed out!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -1,173 +1,173 @@
|
||||
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/ledger-entry-types"
|
||||
"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/ledger-entry-types"
|
||||
"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"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Setting up wallets...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Sender wallet funded!")
|
||||
fmt.Println("⏳ Setting up wallets...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Sender wallet funded!")
|
||||
|
||||
if err := client.FundWallet(&receiverWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&receiverWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Receiver wallet funded!")
|
||||
fmt.Println()
|
||||
fmt.Println("💸 Receiver wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println("💳 Sender wallet:", w.ClassicAddress)
|
||||
fmt.Println("💳 Receiver wallet:", receiverWallet.ClassicAddress)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println("💳 Sender wallet:", w.ClassicAddress)
|
||||
fmt.Println("💳 Receiver wallet:", receiverWallet.ClassicAddress)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Creating check...")
|
||||
cc := &transaction.CheckCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
},
|
||||
Destination: receiverWallet.GetAddress(),
|
||||
SendMax: types.XRPCurrencyAmount(1000000),
|
||||
InvoiceID: "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
|
||||
}
|
||||
fmt.Println("⏳ Creating check...")
|
||||
cc := &transaction.CheckCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
},
|
||||
Destination: receiverWallet.GetAddress(),
|
||||
SendMax: types.XRPCurrencyAmount(1000000),
|
||||
InvoiceID: "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
|
||||
}
|
||||
|
||||
flatCc := cc.Flatten()
|
||||
flatCc := cc.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatCc); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Autofill(&flatCc); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err := w.Sign(flatCc)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err := w.Sign(flatCc)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
if !res.Validated {
|
||||
fmt.Println("❌ Check creation failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
if !res.Validated {
|
||||
fmt.Println("❌ Check creation failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Check created!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Check created!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
meta, ok := res.Meta.(map[string]interface{})
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not of type TxObjMeta")
|
||||
return
|
||||
}
|
||||
meta, ok := res.Meta.(map[string]interface{})
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not of type TxObjMeta")
|
||||
return
|
||||
}
|
||||
|
||||
var checkID string
|
||||
var checkID string
|
||||
|
||||
affectedNodes := meta["AffectedNodes"].([]interface{})
|
||||
affectedNodes := meta["AffectedNodes"].([]interface{})
|
||||
|
||||
for _, node := range affectedNodes {
|
||||
affectedNode, ok := node.(map[string]interface{})
|
||||
if !ok {
|
||||
fmt.Println("❌ Node is not of type map[string]interface{}")
|
||||
return
|
||||
}
|
||||
for _, node := range affectedNodes {
|
||||
affectedNode, ok := node.(map[string]interface{})
|
||||
if !ok {
|
||||
fmt.Println("❌ Node is not of type map[string]interface{}")
|
||||
return
|
||||
}
|
||||
|
||||
createdNode, ok := affectedNode["CreatedNode"].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
createdNode, ok := affectedNode["CreatedNode"].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if createdNode["LedgerEntryType"] == string(ledger.CheckEntry) {
|
||||
if createdNode["LedgerEntryType"] == string(ledger.CheckEntry) {
|
||||
|
||||
checkID = createdNode["LedgerIndex"].(string)
|
||||
}
|
||||
}
|
||||
checkID = createdNode["LedgerIndex"].(string)
|
||||
}
|
||||
}
|
||||
|
||||
if checkID == "" {
|
||||
fmt.Println("Check not found")
|
||||
return
|
||||
}
|
||||
if checkID == "" {
|
||||
fmt.Println("Check not found")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Cashing out check...")
|
||||
checkCash := &transaction.CheckCash{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: receiverWallet.GetAddress(),
|
||||
},
|
||||
CheckID: types.Hash256(checkID),
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
}
|
||||
fmt.Println("⏳ Cashing out check...")
|
||||
checkCash := &transaction.CheckCash{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: receiverWallet.GetAddress(),
|
||||
},
|
||||
CheckID: types.Hash256(checkID),
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
}
|
||||
|
||||
flatCheckCash := checkCash.Flatten()
|
||||
flatCheckCash := checkCash.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatCheckCash); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Autofill(&flatCheckCash); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err = receiverWallet.Sign(flatCheckCash)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err = receiverWallet.Sign(flatCheckCash)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Check cashed out!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Check cashed out!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -1,251 +1,251 @@
|
||||
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/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/pkg/crypto"
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
currencyCode = "FOO"
|
||||
currencyCode = "FOO"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//
|
||||
// Configure client
|
||||
//
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
//
|
||||
// Configure client
|
||||
//
|
||||
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)
|
||||
|
||||
//
|
||||
// Configure wallets
|
||||
//
|
||||
fmt.Println("⏳ Setting up wallets...")
|
||||
coldWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating cold wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = client.FundWallet(&coldWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding cold wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Cold wallet funded!")
|
||||
//
|
||||
// Configure wallets
|
||||
//
|
||||
fmt.Println("⏳ Setting up wallets...")
|
||||
coldWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating cold wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = client.FundWallet(&coldWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding cold wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Cold wallet funded!")
|
||||
|
||||
hotWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating hot wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = client.FundWallet(&hotWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding hot wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Hot wallet funded!")
|
||||
fmt.Println()
|
||||
hotWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating hot wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = client.FundWallet(&hotWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding hot wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Hot wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println("💳 Cold wallet:", coldWallet.ClassicAddress)
|
||||
fmt.Println("💳 Hot wallet:", hotWallet.ClassicAddress)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println("💳 Cold wallet:", coldWallet.ClassicAddress)
|
||||
fmt.Println("💳 Hot wallet:", hotWallet.ClassicAddress)
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Configure cold address settings
|
||||
//
|
||||
fmt.Println("⏳ Configuring cold address settings...")
|
||||
coldWalletAccountSet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
TickSize: types.TickSize(5),
|
||||
TransferRate: types.TransferRate(0),
|
||||
Domain: types.Domain("6578616D706C652E636F6D"), // example.com
|
||||
}
|
||||
//
|
||||
// Configure cold address settings
|
||||
//
|
||||
fmt.Println("⏳ Configuring cold address settings...")
|
||||
coldWalletAccountSet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
TickSize: types.TickSize(5),
|
||||
TransferRate: types.TransferRate(0),
|
||||
Domain: types.Domain("6578616D706C652E636F6D"), // example.com
|
||||
}
|
||||
|
||||
coldWalletAccountSet.SetAsfAllowTrustLineClawback()
|
||||
coldWalletAccountSet.SetDisallowXRP()
|
||||
coldWalletAccountSet.SetAsfAllowTrustLineClawback()
|
||||
coldWalletAccountSet.SetDisallowXRP()
|
||||
|
||||
coldWalletAccountSet.SetRequireDestTag()
|
||||
coldWalletAccountSet.SetRequireDestTag()
|
||||
|
||||
flattenedTx := coldWalletAccountSet.Flatten()
|
||||
flattenedTx := coldWalletAccountSet.Flatten()
|
||||
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err := coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err := coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Cold wallet unfreezing failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Cold wallet unfreezing failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Cold address settings configured!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Cold address settings configured!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Create trust line from hot to cold address
|
||||
//
|
||||
fmt.Println("⏳ Creating trust line from hot to cold address...")
|
||||
hotColdTrustSet := &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(hotWallet.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100000000000000",
|
||||
},
|
||||
}
|
||||
//
|
||||
// Create trust line from hot to cold address
|
||||
//
|
||||
fmt.Println("⏳ Creating trust line from hot to cold address...")
|
||||
hotColdTrustSet := &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(hotWallet.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100000000000000",
|
||||
},
|
||||
}
|
||||
|
||||
flattenedTx = hotColdTrustSet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
flattenedTx = hotColdTrustSet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Trust line from hot to cold address creation failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Trust line from hot to cold address creation failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Trust line from hot to cold address created!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Trust line from hot to cold address created!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Send tokens from cold wallet to hot wallet
|
||||
//
|
||||
fmt.Println("⏳ Sending tokens from cold wallet to hot wallet...")
|
||||
coldToHotPayment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "3800",
|
||||
},
|
||||
Destination: types.Address(hotWallet.ClassicAddress),
|
||||
DestinationTag: types.DestinationTag(1),
|
||||
}
|
||||
//
|
||||
// Send tokens from cold wallet to hot wallet
|
||||
//
|
||||
fmt.Println("⏳ Sending tokens from cold wallet to hot wallet...")
|
||||
coldToHotPayment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "3800",
|
||||
},
|
||||
Destination: types.Address(hotWallet.ClassicAddress),
|
||||
DestinationTag: types.DestinationTag(1),
|
||||
}
|
||||
|
||||
flattenedTx = coldToHotPayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
flattenedTx = coldToHotPayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Tokens not sent from cold wallet to hot wallet!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Tokens not sent from cold wallet to hot wallet!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Tokens sent from cold wallet to hot wallet!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Tokens sent from cold wallet to hot wallet!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Claw back tokens from customer one
|
||||
//
|
||||
fmt.Println("⏳ Clawing back tokens from hot wallet...")
|
||||
//
|
||||
// Claw back tokens from customer one
|
||||
//
|
||||
fmt.Println("⏳ Clawing back tokens from hot wallet...")
|
||||
|
||||
coldWalletClawback := &transactions.Clawback{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(hotWallet.ClassicAddress),
|
||||
Value: "50",
|
||||
},
|
||||
}
|
||||
coldWalletClawback := &transactions.Clawback{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(hotWallet.ClassicAddress),
|
||||
Value: "50",
|
||||
},
|
||||
}
|
||||
|
||||
flattenedTx = coldWalletClawback.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
flattenedTx = coldWalletClawback.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Tokens not clawed back from customer one!")
|
||||
fmt.Println("Try again!")
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Tokens not clawed back from customer one!")
|
||||
fmt.Println("Try again!")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Tokens clawed back from customer one!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Tokens clawed back from customer one!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -1,258 +1,258 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
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/websocket"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
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/websocket"
|
||||
)
|
||||
|
||||
const (
|
||||
currencyCode = "FOO"
|
||||
currencyCode = "FOO"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//
|
||||
// Configure client
|
||||
//
|
||||
fmt.Println("⏳ Setting up client...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
fmt.Println("✅ Client configured!")
|
||||
fmt.Println()
|
||||
//
|
||||
// Configure client
|
||||
//
|
||||
fmt.Println("⏳ Setting up client...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
fmt.Println("✅ Client configured!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Connection: ", client.IsConnected())
|
||||
fmt.Println("Connection: ", client.IsConnected())
|
||||
|
||||
//
|
||||
// Configure wallets
|
||||
//
|
||||
fmt.Println("⏳ Setting up wallets...")
|
||||
coldWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating cold wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = client.FundWallet(&coldWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding cold wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Cold wallet funded!")
|
||||
//
|
||||
// Configure wallets
|
||||
//
|
||||
fmt.Println("⏳ Setting up wallets...")
|
||||
coldWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating cold wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = client.FundWallet(&coldWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding cold wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Cold wallet funded!")
|
||||
|
||||
hotWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating hot wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = client.FundWallet(&hotWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding hot wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Hot wallet funded!")
|
||||
fmt.Println()
|
||||
hotWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating hot wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = client.FundWallet(&hotWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding hot wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Hot wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println("💳 Cold wallet:", coldWallet.ClassicAddress)
|
||||
fmt.Println("💳 Hot wallet:", hotWallet.ClassicAddress)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println("💳 Cold wallet:", coldWallet.ClassicAddress)
|
||||
fmt.Println("💳 Hot wallet:", hotWallet.ClassicAddress)
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Configure cold address settings
|
||||
//
|
||||
fmt.Println("⏳ Configuring cold address settings...")
|
||||
coldWalletAccountSet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
TickSize: types.TickSize(5),
|
||||
TransferRate: types.TransferRate(0),
|
||||
Domain: types.Domain("6578616D706C652E636F6D"), // example.com
|
||||
}
|
||||
//
|
||||
// Configure cold address settings
|
||||
//
|
||||
fmt.Println("⏳ Configuring cold address settings...")
|
||||
coldWalletAccountSet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
TickSize: types.TickSize(5),
|
||||
TransferRate: types.TransferRate(0),
|
||||
Domain: types.Domain("6578616D706C652E636F6D"), // example.com
|
||||
}
|
||||
|
||||
coldWalletAccountSet.SetAsfAllowTrustLineClawback()
|
||||
coldWalletAccountSet.SetDisallowXRP()
|
||||
coldWalletAccountSet.SetAsfAllowTrustLineClawback()
|
||||
coldWalletAccountSet.SetDisallowXRP()
|
||||
|
||||
coldWalletAccountSet.SetRequireDestTag()
|
||||
coldWalletAccountSet.SetRequireDestTag()
|
||||
|
||||
flattenedTx := coldWalletAccountSet.Flatten()
|
||||
flattenedTx := coldWalletAccountSet.Flatten()
|
||||
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err := coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err := coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Cold wallet unfreezing failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Cold wallet unfreezing failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Cold address settings configured!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Cold address settings configured!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Create trust line from hot to cold address
|
||||
//
|
||||
fmt.Println("⏳ Creating trust line from hot to cold address...")
|
||||
hotColdTrustSet := &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(hotWallet.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100000000000000",
|
||||
},
|
||||
}
|
||||
//
|
||||
// Create trust line from hot to cold address
|
||||
//
|
||||
fmt.Println("⏳ Creating trust line from hot to cold address...")
|
||||
hotColdTrustSet := &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(hotWallet.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100000000000000",
|
||||
},
|
||||
}
|
||||
|
||||
flattenedTx = hotColdTrustSet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
flattenedTx = hotColdTrustSet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Trust line from hot to cold address creation failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Trust line from hot to cold address creation failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Trust line from hot to cold address created!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Trust line from hot to cold address created!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Send tokens from cold wallet to hot wallet
|
||||
//
|
||||
fmt.Println("⏳ Sending tokens from cold wallet to hot wallet...")
|
||||
coldToHotPayment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "3800",
|
||||
},
|
||||
Destination: types.Address(hotWallet.ClassicAddress),
|
||||
DestinationTag: types.DestinationTag(1),
|
||||
}
|
||||
//
|
||||
// Send tokens from cold wallet to hot wallet
|
||||
//
|
||||
fmt.Println("⏳ Sending tokens from cold wallet to hot wallet...")
|
||||
coldToHotPayment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "3800",
|
||||
},
|
||||
Destination: types.Address(hotWallet.ClassicAddress),
|
||||
DestinationTag: types.DestinationTag(1),
|
||||
}
|
||||
|
||||
flattenedTx = coldToHotPayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
flattenedTx = coldToHotPayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Tokens not sent from cold wallet to hot wallet!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Tokens not sent from cold wallet to hot wallet!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Tokens sent from cold wallet to hot wallet!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Tokens sent from cold wallet to hot wallet!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Claw back tokens from customer one
|
||||
//
|
||||
fmt.Println("⏳ Clawing back tokens from hot wallet...")
|
||||
//
|
||||
// Claw back tokens from customer one
|
||||
//
|
||||
fmt.Println("⏳ Clawing back tokens from hot wallet...")
|
||||
|
||||
coldWalletClawback := &transactions.Clawback{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(hotWallet.ClassicAddress),
|
||||
Value: "50",
|
||||
},
|
||||
}
|
||||
coldWalletClawback := &transactions.Clawback{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(hotWallet.ClassicAddress),
|
||||
Value: "50",
|
||||
},
|
||||
}
|
||||
|
||||
flattenedTx = coldWalletClawback.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
flattenedTx = coldWalletClawback.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting transaction: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Tokens not clawed back from customer one!")
|
||||
fmt.Println("Try again!")
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ Tokens not clawed back from customer one!")
|
||||
fmt.Println("Try again!")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Tokens clawed back from customer one!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Tokens clawed back from customer one!")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -1,109 +1,109 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/examples/clients"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
rippleTime "github.com/Peersyst/xrpl-go/xrpl/time"
|
||||
"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/examples/clients"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
rippleTime "github.com/Peersyst/xrpl-go/xrpl/time"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// As of February 2025, Credential is only available on Devnet.
|
||||
client := clients.GetDevnetRpcClient()
|
||||
// As of February 2025, Credential is only available on Devnet.
|
||||
client := clients.GetDevnetRpcClient()
|
||||
|
||||
// Configure wallets
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Subject (destination)
|
||||
fmt.Println("⏳ Setting up Subject wallet...")
|
||||
subjectWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating subject wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Subject (destination)
|
||||
fmt.Println("⏳ Setting up Subject wallet...")
|
||||
subjectWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating subject wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&subjectWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding subject wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Subject wallet funded: %s\n", subjectWallet.ClassicAddress)
|
||||
err = client.FundWallet(&subjectWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding subject wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Subject wallet funded: %s\n", subjectWallet.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the CredentialCreate transaction
|
||||
fmt.Println("⏳ Creating CredentialCreate transaction...")
|
||||
// Creating the CredentialCreate transaction
|
||||
fmt.Println("⏳ Creating CredentialCreate transaction...")
|
||||
|
||||
expiration, err := rippleTime.IsoTimeToRippleTime(time.Now().Add(time.Hour * 24).Format(time.RFC3339))
|
||||
credentialType := types.CredentialType("6D795F63726564656E7469616C")
|
||||
expiration, err := rippleTime.IsoTimeToRippleTime(time.Now().Add(time.Hour * 24).Format(time.RFC3339))
|
||||
credentialType := types.CredentialType("6D795F63726564656E7469616C")
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error converting expiration to ripple time: %s\n", err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error converting expiration to ripple time: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
txn := &transaction.CredentialCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Subject: types.Address(subjectWallet.ClassicAddress),
|
||||
Expiration: uint32(expiration),
|
||||
URI: hex.EncodeToString([]byte("https://example.com")),
|
||||
}
|
||||
txn := &transaction.CredentialCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Subject: types.Address(subjectWallet.ClassicAddress),
|
||||
Expiration: uint32(expiration),
|
||||
URI: hex.EncodeToString([]byte("https://example.com")),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, txn, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, txn, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the CredentialAccept transaction
|
||||
fmt.Println("⏳ Creating CredentialAccept transaction...")
|
||||
// Creating the CredentialAccept transaction
|
||||
fmt.Println("⏳ Creating CredentialAccept transaction...")
|
||||
|
||||
acceptTxn := &transaction.CredentialAccept{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(subjectWallet.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
}
|
||||
acceptTxn := &transaction.CredentialAccept{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(subjectWallet.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, acceptTxn, subjectWallet)
|
||||
clients.SubmitTxBlobAndWait(client, acceptTxn, subjectWallet)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the CredentialDelete transaction
|
||||
fmt.Println("⏳ Creating CredentialDelete transaction...")
|
||||
// Creating the CredentialDelete transaction
|
||||
fmt.Println("⏳ Creating CredentialDelete transaction...")
|
||||
|
||||
deleteTxn := &transaction.CredentialDelete{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Subject: types.Address(subjectWallet.ClassicAddress),
|
||||
}
|
||||
deleteTxn := &transaction.CredentialDelete{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Subject: types.Address(subjectWallet.ClassicAddress),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, deleteTxn, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, deleteTxn, issuer)
|
||||
}
|
||||
|
||||
@@ -1,122 +1,122 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/examples/clients"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
rippleTime "github.com/Peersyst/xrpl-go/xrpl/time"
|
||||
"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/examples/clients"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
rippleTime "github.com/Peersyst/xrpl-go/xrpl/time"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Println("⏳ Setting up client...")
|
||||
fmt.Println("⏳ Setting up client...")
|
||||
|
||||
client := clients.GetDevnetWebsocketClient()
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
client := clients.GetDevnetWebsocketClient()
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Client configured!")
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Client configured!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("Connection: %t", client.IsConnected())
|
||||
fmt.Println()
|
||||
fmt.Printf("Connection: %t", client.IsConnected())
|
||||
fmt.Println()
|
||||
|
||||
// Configure wallets
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Subject (destination)
|
||||
fmt.Println("⏳ Setting up Subject wallet...")
|
||||
subjectWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating subject wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Subject (destination)
|
||||
fmt.Println("⏳ Setting up Subject wallet...")
|
||||
subjectWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating subject wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&subjectWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding subject wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Subject wallet funded: %s\n", subjectWallet.ClassicAddress)
|
||||
err = client.FundWallet(&subjectWallet)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding subject wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Subject wallet funded: %s\n", subjectWallet.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the CredentialCreate transaction
|
||||
fmt.Println("⏳ Creating CredentialCreate transaction...")
|
||||
// Creating the CredentialCreate transaction
|
||||
fmt.Println("⏳ Creating CredentialCreate transaction...")
|
||||
|
||||
expiration, err := rippleTime.IsoTimeToRippleTime(time.Now().Add(time.Hour * 24).Format(time.RFC3339))
|
||||
credentialType := types.CredentialType("6D795F63726564656E7469616C")
|
||||
expiration, err := rippleTime.IsoTimeToRippleTime(time.Now().Add(time.Hour * 24).Format(time.RFC3339))
|
||||
credentialType := types.CredentialType("6D795F63726564656E7469616C")
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error converting expiration to ripple time: %s\n", err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error converting expiration to ripple time: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
txn := &transaction.CredentialCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Subject: types.Address(subjectWallet.ClassicAddress),
|
||||
Expiration: uint32(expiration),
|
||||
URI: hex.EncodeToString([]byte("https://example.com")),
|
||||
}
|
||||
txn := &transaction.CredentialCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Subject: types.Address(subjectWallet.ClassicAddress),
|
||||
Expiration: uint32(expiration),
|
||||
URI: hex.EncodeToString([]byte("https://example.com")),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, txn, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, txn, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the CredentialAccept transaction
|
||||
fmt.Println("⏳ Creating CredentialAccept transaction...")
|
||||
// Creating the CredentialAccept transaction
|
||||
fmt.Println("⏳ Creating CredentialAccept transaction...")
|
||||
|
||||
acceptTxn := &transaction.CredentialAccept{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(subjectWallet.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
}
|
||||
acceptTxn := &transaction.CredentialAccept{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(subjectWallet.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, acceptTxn, subjectWallet)
|
||||
clients.SubmitTxBlobAndWait(client, acceptTxn, subjectWallet)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the CredentialDelete transaction
|
||||
fmt.Println("⏳ Creating CredentialDelete transaction...")
|
||||
// Creating the CredentialDelete transaction
|
||||
fmt.Println("⏳ Creating CredentialDelete transaction...")
|
||||
|
||||
deleteTxn := &transaction.CredentialDelete{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Subject: types.Address(subjectWallet.ClassicAddress),
|
||||
}
|
||||
deleteTxn := &transaction.CredentialDelete{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Subject: types.Address(subjectWallet.ClassicAddress),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, deleteTxn, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, deleteTxn, issuer)
|
||||
}
|
||||
|
||||
@@ -1,131 +1,131 @@
|
||||
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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
transactions "github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
transactions "github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Configure the client
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := rpc.NewClient(cfg)
|
||||
// Configure the client
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Create and fund wallets
|
||||
delegatorWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Create and fund wallets
|
||||
delegatorWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
delegateeWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
delegateeWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&delegatorWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&delegateeWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallets funded")
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&delegatorWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&delegateeWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallets funded")
|
||||
|
||||
// Check initial balances
|
||||
delegatorBalance, err := client.GetXrpBalance(delegatorWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
delegatorBalance = "0"
|
||||
}
|
||||
delegateeBalance, err := client.GetXrpBalance(delegateeWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
delegateeBalance = "0"
|
||||
}
|
||||
// Check initial balances
|
||||
delegatorBalance, err := client.GetXrpBalance(delegatorWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
delegatorBalance = "0"
|
||||
}
|
||||
delegateeBalance, err := client.GetXrpBalance(delegateeWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
delegateeBalance = "0"
|
||||
}
|
||||
|
||||
fmt.Printf("💳 Delegator initial balance: %s XRP\n", delegatorBalance)
|
||||
fmt.Printf("💳 Delegatee initial balance: %s XRP\n", delegateeBalance)
|
||||
fmt.Println()
|
||||
fmt.Printf("💳 Delegator initial balance: %s XRP\n", delegatorBalance)
|
||||
fmt.Printf("💳 Delegatee initial balance: %s XRP\n", delegateeBalance)
|
||||
fmt.Println()
|
||||
|
||||
// Create DelegateSet transaction
|
||||
delegateSetTx := &transactions.DelegateSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: txnTypes.Address(delegatorWallet.ClassicAddress),
|
||||
},
|
||||
Authorize: txnTypes.Address(delegateeWallet.ClassicAddress),
|
||||
Permissions: []txnTypes.Permission{
|
||||
{
|
||||
Permission: txnTypes.PermissionValue{
|
||||
PermissionValue: "Payment",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
// Create DelegateSet transaction
|
||||
delegateSetTx := &transactions.DelegateSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: txnTypes.Address(delegatorWallet.ClassicAddress),
|
||||
},
|
||||
Authorize: txnTypes.Address(delegateeWallet.ClassicAddress),
|
||||
Permissions: []txnTypes.Permission{
|
||||
{
|
||||
Permission: txnTypes.PermissionValue{
|
||||
PermissionValue: "Payment",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Submit DelegateSet transaction
|
||||
response, err := client.SubmitTxAndWait(delegateSetTx.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &delegatorWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Submit DelegateSet transaction
|
||||
response, err := client.SubmitTxAndWait(delegateSetTx.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &delegatorWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ DelegateSet transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ DelegateSet transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
|
||||
// Create delegated payment transaction
|
||||
delegatedPaymentTx := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: txnTypes.Address(delegatorWallet.ClassicAddress),
|
||||
Delegate: txnTypes.Address(delegateeWallet.ClassicAddress),
|
||||
},
|
||||
Destination: txnTypes.Address(delegateeWallet.ClassicAddress),
|
||||
Amount: txnTypes.XRPCurrencyAmount(1000000), // 1 XRP
|
||||
}
|
||||
// Create delegated payment transaction
|
||||
delegatedPaymentTx := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: txnTypes.Address(delegatorWallet.ClassicAddress),
|
||||
Delegate: txnTypes.Address(delegateeWallet.ClassicAddress),
|
||||
},
|
||||
Destination: txnTypes.Address(delegateeWallet.ClassicAddress),
|
||||
Amount: txnTypes.XRPCurrencyAmount(1000000), // 1 XRP
|
||||
}
|
||||
|
||||
// Submit delegated payment
|
||||
response2, err := client.SubmitTxAndWait(delegatedPaymentTx.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &delegateeWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Submit delegated payment
|
||||
response2, err := client.SubmitTxAndWait(delegatedPaymentTx.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &delegateeWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Delegated payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response2.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", response2.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Delegated payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response2.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", response2.Validated)
|
||||
fmt.Println()
|
||||
|
||||
// Check final balances
|
||||
finalDelegatorBalance, err := client.GetXrpBalance(delegatorWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalDelegatorBalance = "0"
|
||||
}
|
||||
finalDelegateeBalance, err := client.GetXrpBalance(delegateeWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalDelegateeBalance = "0"
|
||||
}
|
||||
// Check final balances
|
||||
finalDelegatorBalance, err := client.GetXrpBalance(delegatorWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalDelegatorBalance = "0"
|
||||
}
|
||||
finalDelegateeBalance, err := client.GetXrpBalance(delegateeWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalDelegateeBalance = "0"
|
||||
}
|
||||
|
||||
fmt.Printf("💳 Delegator final balance: %s XRP\n", finalDelegatorBalance)
|
||||
fmt.Printf("💳 Delegatee final balance: %s XRP\n", finalDelegateeBalance)
|
||||
fmt.Printf("💳 Delegator final balance: %s XRP\n", finalDelegatorBalance)
|
||||
fmt.Printf("💳 Delegatee final balance: %s XRP\n", finalDelegateeBalance)
|
||||
}
|
||||
|
||||
@@ -1,151 +1,151 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
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/websocket"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
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/websocket"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Connect to testnet
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
// Connect to testnet
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Create and fund wallets
|
||||
delegatorWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Create and fund wallets
|
||||
delegatorWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
delegateeWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
delegateeWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&delegatorWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&delegateeWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallets funded")
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&delegatorWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&delegateeWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallets funded")
|
||||
|
||||
// Check initial balances
|
||||
delegatorBalance, err := client.GetXrpBalance(delegatorWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
delegatorBalance = "0"
|
||||
}
|
||||
delegateeBalance, err := client.GetXrpBalance(delegateeWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
delegateeBalance = "0"
|
||||
}
|
||||
// Check initial balances
|
||||
delegatorBalance, err := client.GetXrpBalance(delegatorWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
delegatorBalance = "0"
|
||||
}
|
||||
delegateeBalance, err := client.GetXrpBalance(delegateeWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
delegateeBalance = "0"
|
||||
}
|
||||
|
||||
fmt.Printf("💳 Delegator initial balance: %s XRP\n", delegatorBalance)
|
||||
fmt.Printf("💳 Delegatee initial balance: %s XRP\n", delegateeBalance)
|
||||
fmt.Println()
|
||||
fmt.Printf("💳 Delegator initial balance: %s XRP\n", delegatorBalance)
|
||||
fmt.Printf("💳 Delegatee initial balance: %s XRP\n", delegateeBalance)
|
||||
fmt.Println()
|
||||
|
||||
// Create DelegateSet transaction
|
||||
delegateSetTx := &transactions.DelegateSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(delegatorWallet.ClassicAddress),
|
||||
},
|
||||
Authorize: types.Address(delegateeWallet.ClassicAddress),
|
||||
Permissions: []types.Permission{
|
||||
{
|
||||
Permission: types.PermissionValue{
|
||||
PermissionValue: "Payment",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
// Create DelegateSet transaction
|
||||
delegateSetTx := &transactions.DelegateSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(delegatorWallet.ClassicAddress),
|
||||
},
|
||||
Authorize: types.Address(delegateeWallet.ClassicAddress),
|
||||
Permissions: []types.Permission{
|
||||
{
|
||||
Permission: types.PermissionValue{
|
||||
PermissionValue: "Payment",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Submit DelegateSet transaction
|
||||
flattenedTx := delegateSetTx.Flatten()
|
||||
if err := client.Autofill(&flattenedTx); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Submit DelegateSet transaction
|
||||
flattenedTx := delegateSetTx.Flatten()
|
||||
if err := client.Autofill(&flattenedTx); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err := delegatorWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err := delegatorWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ DelegateSet transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ DelegateSet transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", response.Validated)
|
||||
fmt.Println()
|
||||
|
||||
// Create delegated payment transaction
|
||||
delegatedPaymentTx := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(delegatorWallet.ClassicAddress),
|
||||
Delegate: types.Address(delegateeWallet.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(delegateeWallet.ClassicAddress),
|
||||
Amount: types.XRPCurrencyAmount(1000000), // 1 XRP
|
||||
}
|
||||
// Create delegated payment transaction
|
||||
delegatedPaymentTx := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(delegatorWallet.ClassicAddress),
|
||||
Delegate: types.Address(delegateeWallet.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(delegateeWallet.ClassicAddress),
|
||||
Amount: types.XRPCurrencyAmount(1000000), // 1 XRP
|
||||
}
|
||||
|
||||
// Submit delegated payment
|
||||
flatDelegatedPayment := delegatedPaymentTx.Flatten()
|
||||
if err := client.Autofill(&flatDelegatedPayment); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Submit delegated payment
|
||||
flatDelegatedPayment := delegatedPaymentTx.Flatten()
|
||||
if err := client.Autofill(&flatDelegatedPayment); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob2, _, err := delegateeWallet.Sign(flatDelegatedPayment)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
txBlob2, _, err := delegateeWallet.Sign(flatDelegatedPayment)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
response2, err := client.SubmitTxBlobAndWait(txBlob2, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
response2, err := client.SubmitTxBlobAndWait(txBlob2, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Delegated payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response2.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", response2.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Delegated payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", response2.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", response2.Validated)
|
||||
fmt.Println()
|
||||
|
||||
// Check final balances
|
||||
finalDelegatorBalance, err := client.GetXrpBalance(delegatorWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalDelegatorBalance = "0"
|
||||
}
|
||||
finalDelegateeBalance, err := client.GetXrpBalance(delegateeWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalDelegateeBalance = "0"
|
||||
}
|
||||
// Check final balances
|
||||
finalDelegatorBalance, err := client.GetXrpBalance(delegatorWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalDelegatorBalance = "0"
|
||||
}
|
||||
finalDelegateeBalance, err := client.GetXrpBalance(delegateeWallet.ClassicAddress)
|
||||
if err != nil {
|
||||
finalDelegateeBalance = "0"
|
||||
}
|
||||
|
||||
fmt.Printf("💳 Delegator final balance: %s XRP\n", finalDelegatorBalance)
|
||||
fmt.Printf("💳 Delegatee final balance: %s XRP\n", finalDelegateeBalance)
|
||||
fmt.Printf("💳 Delegator final balance: %s XRP\n", finalDelegatorBalance)
|
||||
fmt.Printf("💳 Delegatee final balance: %s XRP\n", finalDelegateeBalance)
|
||||
}
|
||||
|
||||
@@ -1,220 +1,220 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/examples/clients"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/account"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
|
||||
rippletime "github.com/Peersyst/xrpl-go/xrpl/time"
|
||||
"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/examples/clients"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/account"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
|
||||
rippletime "github.com/Peersyst/xrpl-go/xrpl/time"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := clients.GetDevnetRpcClient()
|
||||
client := clients.GetDevnetRpcClient()
|
||||
|
||||
// Configure wallets
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating credential issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating credential issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding credential issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Credential issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding credential issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Credential issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Holder 1
|
||||
fmt.Println("⏳ Setting up holder 1 wallet...")
|
||||
holderWallet1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder 1 wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Holder 1
|
||||
fmt.Println("⏳ Setting up holder 1 wallet...")
|
||||
holderWallet1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder 1 wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder 1 wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder 1 wallet funded: %s\n", holderWallet1.ClassicAddress)
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder 1 wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder 1 wallet funded: %s\n", holderWallet1.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Enabling DepositAuth on the issuer account with an AccountSet transaction
|
||||
fmt.Println("⏳ Enabling DepositAuth on the issuer account...")
|
||||
accountSetTx := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.AccountSetTx,
|
||||
},
|
||||
}
|
||||
accountSetTx.SetAsfDepositAuth()
|
||||
// Enabling DepositAuth on the issuer account with an AccountSet transaction
|
||||
fmt.Println("⏳ Enabling DepositAuth on the issuer account...")
|
||||
accountSetTx := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.AccountSetTx,
|
||||
},
|
||||
}
|
||||
accountSetTx.SetAsfDepositAuth()
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, accountSetTx, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, accountSetTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the CredentialCreate transaction
|
||||
fmt.Println("⏳ Creating the CredentialCreate transaction...")
|
||||
// Creating the CredentialCreate transaction
|
||||
fmt.Println("⏳ Creating the CredentialCreate transaction...")
|
||||
|
||||
expiration, err := rippletime.IsoTimeToRippleTime(time.Now().Add(time.Hour * 24).Format(time.RFC3339))
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error converting expiration to ripple time: %s\n", err)
|
||||
return
|
||||
}
|
||||
credentialType := types.CredentialType("6D795F63726564656E7469616C") // my_credential
|
||||
expiration, err := rippletime.IsoTimeToRippleTime(time.Now().Add(time.Hour * 24).Format(time.RFC3339))
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error converting expiration to ripple time: %s\n", err)
|
||||
return
|
||||
}
|
||||
credentialType := types.CredentialType("6D795F63726564656E7469616C") // my_credential
|
||||
|
||||
credentialCreateTx := &transaction.CredentialCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.CredentialCreateTx,
|
||||
},
|
||||
Expiration: uint32(expiration),
|
||||
CredentialType: credentialType,
|
||||
Subject: types.Address(holderWallet1.ClassicAddress),
|
||||
URI: hex.EncodeToString([]byte("https://example.com")),
|
||||
}
|
||||
credentialCreateTx := &transaction.CredentialCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.CredentialCreateTx,
|
||||
},
|
||||
Expiration: uint32(expiration),
|
||||
CredentialType: credentialType,
|
||||
Subject: types.Address(holderWallet1.ClassicAddress),
|
||||
URI: hex.EncodeToString([]byte("https://example.com")),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, credentialCreateTx, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, credentialCreateTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the CredentialAccept transaction
|
||||
fmt.Println("⏳ Creating the CredentialAccept transaction...")
|
||||
// Creating the CredentialAccept transaction
|
||||
fmt.Println("⏳ Creating the CredentialAccept transaction...")
|
||||
|
||||
credentialAcceptTx := &transaction.CredentialAccept{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.CredentialAcceptTx,
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
}
|
||||
credentialAcceptTx := &transaction.CredentialAccept{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.CredentialAcceptTx,
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, credentialAcceptTx, holderWallet1)
|
||||
clients.SubmitTxBlobAndWait(client, credentialAcceptTx, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the DepositPreauth transaction
|
||||
fmt.Println("⏳ Creating the DepositPreauth transaction using AuthorizeCredentials...")
|
||||
// Creating the DepositPreauth transaction
|
||||
fmt.Println("⏳ Creating the DepositPreauth transaction using AuthorizeCredentials...")
|
||||
|
||||
depositPreauthTx := &transaction.DepositPreauth{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.DepositPreauthTx,
|
||||
},
|
||||
AuthorizeCredentials: []types.AuthorizeCredentialsWrapper{
|
||||
{
|
||||
Credential: types.AuthorizeCredentials{
|
||||
Issuer: issuer.ClassicAddress,
|
||||
CredentialType: credentialType,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
depositPreauthTx := &transaction.DepositPreauth{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.DepositPreauthTx,
|
||||
},
|
||||
AuthorizeCredentials: []types.AuthorizeCredentialsWrapper{
|
||||
{
|
||||
Credential: types.AuthorizeCredentials{
|
||||
Issuer: issuer.ClassicAddress,
|
||||
CredentialType: credentialType,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, depositPreauthTx, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, depositPreauthTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Get the credential ID
|
||||
fmt.Println("⏳ Getting the credential ID from the holder 1 account...")
|
||||
// Get the credential ID
|
||||
fmt.Println("⏳ Getting the credential ID from the holder 1 account...")
|
||||
|
||||
objectsRequest := &account.ObjectsRequest{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
Type: account.CredentialObject,
|
||||
LedgerIndex: common.Validated,
|
||||
}
|
||||
objectsRequest := &account.ObjectsRequest{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
Type: account.CredentialObject,
|
||||
LedgerIndex: common.Validated,
|
||||
}
|
||||
|
||||
objectsResponse, err := client.GetAccountObjects(objectsRequest)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error getting the credential ID: %s\n", err)
|
||||
return
|
||||
}
|
||||
objectsResponse, err := client.GetAccountObjects(objectsRequest)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error getting the credential ID: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if we have any credential objects
|
||||
if len(objectsResponse.AccountObjects) == 0 {
|
||||
fmt.Println("❌ No credential objects found")
|
||||
return
|
||||
}
|
||||
// Check if we have any credential objects
|
||||
if len(objectsResponse.AccountObjects) == 0 {
|
||||
fmt.Println("❌ No credential objects found")
|
||||
return
|
||||
}
|
||||
|
||||
// Extract the credential ID
|
||||
credentialID, ok := objectsResponse.AccountObjects[0]["index"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ Could not extract credential ID from response")
|
||||
return
|
||||
}
|
||||
// Extract the credential ID
|
||||
credentialID, ok := objectsResponse.AccountObjects[0]["index"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ Could not extract credential ID from response")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("✅ Credential ID: %s\n", credentialID)
|
||||
fmt.Println()
|
||||
fmt.Printf("✅ Credential ID: %s\n", credentialID)
|
||||
fmt.Println()
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Sending XRP to the holder 1 account
|
||||
fmt.Println("⏳ Sending XRP to the issuer account, should succeed...")
|
||||
// Sending XRP to the holder 1 account
|
||||
fmt.Println("⏳ Sending XRP to the issuer account, should succeed...")
|
||||
|
||||
sendTx := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.PaymentTx,
|
||||
},
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
Destination: issuer.ClassicAddress,
|
||||
CredentialIDs: types.CredentialIDs{credentialID},
|
||||
}
|
||||
sendTx := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.PaymentTx,
|
||||
},
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
Destination: issuer.ClassicAddress,
|
||||
CredentialIDs: types.CredentialIDs{credentialID},
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, sendTx, holderWallet1)
|
||||
clients.SubmitTxBlobAndWait(client, sendTx, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Unauthorizing the holder 1 account
|
||||
fmt.Println("⏳ Unauthorizing the holder 1 account with the DepositPreauth transaction and the UnauthorizeCredentials field...")
|
||||
// Unauthorizing the holder 1 account
|
||||
fmt.Println("⏳ Unauthorizing the holder 1 account with the DepositPreauth transaction and the UnauthorizeCredentials field...")
|
||||
|
||||
unauthorizeTx := &transaction.DepositPreauth{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.DepositPreauthTx,
|
||||
},
|
||||
UnauthorizeCredentials: []types.AuthorizeCredentialsWrapper{
|
||||
{
|
||||
Credential: types.AuthorizeCredentials{
|
||||
Issuer: issuer.ClassicAddress,
|
||||
CredentialType: credentialType,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
unauthorizeTx := &transaction.DepositPreauth{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.DepositPreauthTx,
|
||||
},
|
||||
UnauthorizeCredentials: []types.AuthorizeCredentialsWrapper{
|
||||
{
|
||||
Credential: types.AuthorizeCredentials{
|
||||
Issuer: issuer.ClassicAddress,
|
||||
CredentialType: credentialType,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, unauthorizeTx, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, unauthorizeTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Sending XRP to the holder 1 account again (which should fail)
|
||||
fmt.Println("⏳ Sending XRP to the issuer account again (which should fail)...")
|
||||
// Sending XRP to the holder 1 account again (which should fail)
|
||||
fmt.Println("⏳ Sending XRP to the issuer account again (which should fail)...")
|
||||
|
||||
sendTx2 := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.PaymentTx,
|
||||
},
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
Destination: issuer.ClassicAddress,
|
||||
CredentialIDs: types.CredentialIDs{credentialID},
|
||||
}
|
||||
sendTx2 := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.PaymentTx,
|
||||
},
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
Destination: issuer.ClassicAddress,
|
||||
CredentialIDs: types.CredentialIDs{credentialID},
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, sendTx2, holderWallet1)
|
||||
clients.SubmitTxBlobAndWait(client, sendTx2, holderWallet1)
|
||||
}
|
||||
|
||||
@@ -1,234 +1,234 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/examples/clients"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/account"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
|
||||
rippletime "github.com/Peersyst/xrpl-go/xrpl/time"
|
||||
"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/examples/clients"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/account"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
|
||||
rippletime "github.com/Peersyst/xrpl-go/xrpl/time"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Println("⏳ Setting up client...")
|
||||
fmt.Println("⏳ Setting up client...")
|
||||
|
||||
client := clients.GetDevnetWebsocketClient()
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
client := clients.GetDevnetWebsocketClient()
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Client configured!")
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Client configured!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("Connection: %t", client.IsConnected())
|
||||
fmt.Println()
|
||||
fmt.Printf("Connection: %t", client.IsConnected())
|
||||
fmt.Println()
|
||||
|
||||
// Configure wallets
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating credential issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating credential issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding credential issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Credential issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding credential issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Credential issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Holder 1
|
||||
fmt.Println("⏳ Setting up holder 1 wallet...")
|
||||
holderWallet1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder 1 wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Holder 1
|
||||
fmt.Println("⏳ Setting up holder 1 wallet...")
|
||||
holderWallet1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder 1 wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder 1 wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder 1 wallet funded: %s\n", holderWallet1.ClassicAddress)
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder 1 wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder 1 wallet funded: %s\n", holderWallet1.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Enabling DepositAuth on the issuer account with an AccountSet transaction
|
||||
fmt.Println("⏳ Enabling DepositAuth on the issuer account...")
|
||||
accountSetTx := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.AccountSetTx,
|
||||
},
|
||||
}
|
||||
accountSetTx.SetAsfDepositAuth()
|
||||
// Enabling DepositAuth on the issuer account with an AccountSet transaction
|
||||
fmt.Println("⏳ Enabling DepositAuth on the issuer account...")
|
||||
accountSetTx := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.AccountSetTx,
|
||||
},
|
||||
}
|
||||
accountSetTx.SetAsfDepositAuth()
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, accountSetTx, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, accountSetTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the CredentialCreate transaction
|
||||
fmt.Println("⏳ Creating the CredentialCreate transaction...")
|
||||
// Creating the CredentialCreate transaction
|
||||
fmt.Println("⏳ Creating the CredentialCreate transaction...")
|
||||
|
||||
expiration, err := rippletime.IsoTimeToRippleTime(time.Now().Add(time.Hour * 24).Format(time.RFC3339))
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error converting expiration to ripple time: %s\n", err)
|
||||
return
|
||||
}
|
||||
credentialType := types.CredentialType("6D795F63726564656E7469616C") // my_credential
|
||||
expiration, err := rippletime.IsoTimeToRippleTime(time.Now().Add(time.Hour * 24).Format(time.RFC3339))
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error converting expiration to ripple time: %s\n", err)
|
||||
return
|
||||
}
|
||||
credentialType := types.CredentialType("6D795F63726564656E7469616C") // my_credential
|
||||
|
||||
credentialCreateTx := &transaction.CredentialCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.CredentialCreateTx,
|
||||
},
|
||||
Expiration: uint32(expiration),
|
||||
CredentialType: credentialType,
|
||||
Subject: types.Address(holderWallet1.ClassicAddress),
|
||||
URI: hex.EncodeToString([]byte("https://example.com")),
|
||||
}
|
||||
credentialCreateTx := &transaction.CredentialCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.CredentialCreateTx,
|
||||
},
|
||||
Expiration: uint32(expiration),
|
||||
CredentialType: credentialType,
|
||||
Subject: types.Address(holderWallet1.ClassicAddress),
|
||||
URI: hex.EncodeToString([]byte("https://example.com")),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, credentialCreateTx, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, credentialCreateTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the CredentialAccept transaction
|
||||
fmt.Println("⏳ Creating the CredentialAccept transaction...")
|
||||
// Creating the CredentialAccept transaction
|
||||
fmt.Println("⏳ Creating the CredentialAccept transaction...")
|
||||
|
||||
credentialAcceptTx := &transaction.CredentialAccept{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.CredentialAcceptTx,
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
}
|
||||
credentialAcceptTx := &transaction.CredentialAccept{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.CredentialAcceptTx,
|
||||
},
|
||||
CredentialType: credentialType,
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, credentialAcceptTx, holderWallet1)
|
||||
clients.SubmitTxBlobAndWait(client, credentialAcceptTx, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Creating the DepositPreauth transaction
|
||||
fmt.Println("⏳ Creating the DepositPreauth transaction using AuthorizeCredentials...")
|
||||
// Creating the DepositPreauth transaction
|
||||
fmt.Println("⏳ Creating the DepositPreauth transaction using AuthorizeCredentials...")
|
||||
|
||||
depositPreauthTx := &transaction.DepositPreauth{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.DepositPreauthTx,
|
||||
},
|
||||
AuthorizeCredentials: []types.AuthorizeCredentialsWrapper{
|
||||
{
|
||||
Credential: types.AuthorizeCredentials{
|
||||
Issuer: issuer.ClassicAddress,
|
||||
CredentialType: credentialType,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
depositPreauthTx := &transaction.DepositPreauth{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.DepositPreauthTx,
|
||||
},
|
||||
AuthorizeCredentials: []types.AuthorizeCredentialsWrapper{
|
||||
{
|
||||
Credential: types.AuthorizeCredentials{
|
||||
Issuer: issuer.ClassicAddress,
|
||||
CredentialType: credentialType,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, depositPreauthTx, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, depositPreauthTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Get the credential ID
|
||||
fmt.Println("⏳ Getting the credential ID from the holder 1 account...")
|
||||
// Get the credential ID
|
||||
fmt.Println("⏳ Getting the credential ID from the holder 1 account...")
|
||||
|
||||
objectsRequest := &account.ObjectsRequest{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
Type: account.CredentialObject,
|
||||
LedgerIndex: common.Validated,
|
||||
}
|
||||
objectsRequest := &account.ObjectsRequest{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
Type: account.CredentialObject,
|
||||
LedgerIndex: common.Validated,
|
||||
}
|
||||
|
||||
objectsResponse, err := client.GetAccountObjects(objectsRequest)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error getting the credential ID: %s\n", err)
|
||||
return
|
||||
}
|
||||
objectsResponse, err := client.GetAccountObjects(objectsRequest)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error getting the credential ID: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if we have any credential objects
|
||||
if len(objectsResponse.AccountObjects) == 0 {
|
||||
fmt.Println("❌ No credential objects found")
|
||||
return
|
||||
}
|
||||
// Check if we have any credential objects
|
||||
if len(objectsResponse.AccountObjects) == 0 {
|
||||
fmt.Println("❌ No credential objects found")
|
||||
return
|
||||
}
|
||||
|
||||
// Extract the credential ID
|
||||
credentialID, ok := objectsResponse.AccountObjects[0]["index"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ Could not extract credential ID from response")
|
||||
return
|
||||
}
|
||||
// Extract the credential ID
|
||||
credentialID, ok := objectsResponse.AccountObjects[0]["index"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ Could not extract credential ID from response")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("✅ Credential ID: %s\n", credentialID)
|
||||
fmt.Println()
|
||||
fmt.Printf("✅ Credential ID: %s\n", credentialID)
|
||||
fmt.Println()
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Sending XRP to the holder 1 account
|
||||
fmt.Println("⏳ Sending XRP to the issuer account, should succeed...")
|
||||
// Sending XRP to the holder 1 account
|
||||
fmt.Println("⏳ Sending XRP to the issuer account, should succeed...")
|
||||
|
||||
sendTx := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.PaymentTx,
|
||||
},
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
Destination: issuer.ClassicAddress,
|
||||
CredentialIDs: types.CredentialIDs{credentialID},
|
||||
}
|
||||
sendTx := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.PaymentTx,
|
||||
},
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
Destination: issuer.ClassicAddress,
|
||||
CredentialIDs: types.CredentialIDs{credentialID},
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, sendTx, holderWallet1)
|
||||
clients.SubmitTxBlobAndWait(client, sendTx, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Unauthorize the holder 1 account
|
||||
fmt.Println("⏳ Unauthorize the holder 1 account with the DepositPreauth transaction and the UnauthorizeCredentials field...")
|
||||
// Unauthorize the holder 1 account
|
||||
fmt.Println("⏳ Unauthorize the holder 1 account with the DepositPreauth transaction and the UnauthorizeCredentials field...")
|
||||
|
||||
unauthorizeTx := &transaction.DepositPreauth{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.DepositPreauthTx,
|
||||
},
|
||||
UnauthorizeCredentials: []types.AuthorizeCredentialsWrapper{
|
||||
{
|
||||
Credential: types.AuthorizeCredentials{
|
||||
Issuer: issuer.ClassicAddress,
|
||||
CredentialType: credentialType,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
unauthorizeTx := &transaction.DepositPreauth{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: issuer.ClassicAddress,
|
||||
TransactionType: transaction.DepositPreauthTx,
|
||||
},
|
||||
UnauthorizeCredentials: []types.AuthorizeCredentialsWrapper{
|
||||
{
|
||||
Credential: types.AuthorizeCredentials{
|
||||
Issuer: issuer.ClassicAddress,
|
||||
CredentialType: credentialType,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, unauthorizeTx, issuer)
|
||||
clients.SubmitTxBlobAndWait(client, unauthorizeTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Sending XRP to the holder 1 account again (which should fail)
|
||||
fmt.Println("⏳ Sending XRP to the issuer account again (which should fail)...")
|
||||
// Sending XRP to the holder 1 account again (which should fail)
|
||||
fmt.Println("⏳ Sending XRP to the issuer account again (which should fail)...")
|
||||
|
||||
sendTx2 := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.PaymentTx,
|
||||
},
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
Destination: issuer.ClassicAddress,
|
||||
CredentialIDs: types.CredentialIDs{credentialID},
|
||||
}
|
||||
sendTx2 := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: holderWallet1.ClassicAddress,
|
||||
TransactionType: transaction.PaymentTx,
|
||||
},
|
||||
Amount: types.XRPCurrencyAmount(1000000),
|
||||
Destination: issuer.ClassicAddress,
|
||||
CredentialIDs: types.CredentialIDs{credentialID},
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, sendTx2, holderWallet1)
|
||||
clients.SubmitTxBlobAndWait(client, sendTx2, holderWallet1)
|
||||
}
|
||||
|
||||
@@ -1,347 +1,347 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"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/pkg/crypto"
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
currencyCode = "USDA"
|
||||
currencyCode = "USDA"
|
||||
)
|
||||
|
||||
type SubmittableTransaction interface {
|
||||
TxType() transactions.TxType
|
||||
Flatten() transactions.FlatTransaction // Ensures all transactions can be flattened
|
||||
TxType() transactions.TxType
|
||||
Flatten() transactions.FlatTransaction // Ensures all transactions can be flattened
|
||||
}
|
||||
|
||||
func main() {
|
||||
client := getRpcClient()
|
||||
client := getRpcClient()
|
||||
|
||||
// Configure wallets
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Holder 1
|
||||
fmt.Println("⏳ Setting up holder 1 wallet...")
|
||||
holderWallet1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder wallet 1: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Holder 1
|
||||
fmt.Println("⏳ Setting up holder 1 wallet...")
|
||||
holderWallet1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder wallet 1: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder wallet 1: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder wallet 1 funded: %s\n", holderWallet1.ClassicAddress)
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder wallet 1: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder wallet 1 funded: %s\n", holderWallet1.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Holder 2
|
||||
fmt.Println("⏳ Setting up holder 2 wallet...")
|
||||
holderWallet2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder wallet 2: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Holder 2
|
||||
fmt.Println("⏳ Setting up holder 2 wallet...")
|
||||
holderWallet2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder wallet 2: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet2)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder wallet 2: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder wallet 2 funded: %s\n", holderWallet2.ClassicAddress)
|
||||
fmt.Println()
|
||||
err = client.FundWallet(&holderWallet2)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder wallet 2: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder wallet 2 funded: %s\n", holderWallet2.ClassicAddress)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println()
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Configuring Issuing account
|
||||
fmt.Println("⏳ Configuring issuer address settings...")
|
||||
accountSet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Domain: types.Domain("697373756572"), // issuer
|
||||
}
|
||||
// Configuring Issuing account
|
||||
fmt.Println("⏳ Configuring issuer address settings...")
|
||||
accountSet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Domain: types.Domain("697373756572"), // issuer
|
||||
}
|
||||
|
||||
accountSet.SetAsfDefaultRipple()
|
||||
submitAndWait(client, accountSet, issuer)
|
||||
accountSet.SetAsfDefaultRipple()
|
||||
submitAndWait(client, accountSet, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Trustline from the holder 1 to the issuer
|
||||
fmt.Println("⏳ Setting up trustline from holder 1 to the issuer...")
|
||||
trustSet := &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "1000000000",
|
||||
}}
|
||||
trustSet.SetSetNoRippleFlag()
|
||||
submitAndWait(client, trustSet, holderWallet1)
|
||||
// Trustline from the holder 1 to the issuer
|
||||
fmt.Println("⏳ Setting up trustline from holder 1 to the issuer...")
|
||||
trustSet := &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "1000000000",
|
||||
}}
|
||||
trustSet.SetSetNoRippleFlag()
|
||||
submitAndWait(client, trustSet, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Trustline from the holder 2 to the issuer
|
||||
fmt.Println("⏳ Setting up trustline from holder 2 to the issuer...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "1000000000",
|
||||
},
|
||||
}
|
||||
trustSet.SetSetNoRippleFlag()
|
||||
submitAndWait(client, trustSet, holderWallet2)
|
||||
// Trustline from the holder 2 to the issuer
|
||||
fmt.Println("⏳ Setting up trustline from holder 2 to the issuer...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "1000000000",
|
||||
},
|
||||
}
|
||||
trustSet.SetSetNoRippleFlag()
|
||||
submitAndWait(client, trustSet, holderWallet2)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Minting to Holder 1
|
||||
fmt.Println("⏳ Minting to Holder 1...")
|
||||
payment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "50000",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, issuer)
|
||||
// Minting to Holder 1
|
||||
fmt.Println("⏳ Minting to Holder 1...")
|
||||
payment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "50000",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Minting to Holder 2
|
||||
fmt.Println("⏳ Minting to Holder 2...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "40000",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, issuer)
|
||||
// Minting to Holder 2
|
||||
fmt.Println("⏳ Minting to Holder 2...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "40000",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Sending payment from Holder 1 to Holder 2
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "20",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
// Sending payment from Holder 1 to Holder 2
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "20",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Freezing and Deep Freezing holder1
|
||||
fmt.Println("⏳ Freezing and Deep Freezing holder 1 trustline...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(holderWallet1.ClassicAddress),
|
||||
Value: "0",
|
||||
},
|
||||
}
|
||||
trustSet.SetSetFreezeFlag()
|
||||
trustSet.SetSetDeepFreezeFlag()
|
||||
// Freezing and Deep Freezing holder1
|
||||
fmt.Println("⏳ Freezing and Deep Freezing holder 1 trustline...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(holderWallet1.ClassicAddress),
|
||||
Value: "0",
|
||||
},
|
||||
}
|
||||
trustSet.SetSetFreezeFlag()
|
||||
trustSet.SetSetDeepFreezeFlag()
|
||||
|
||||
submitAndWait(client, trustSet, issuer)
|
||||
submitAndWait(client, trustSet, issuer)
|
||||
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
|
||||
// Sending payment from Holder 1 to Holder 2 (which should fail), Holder 1 can't decrease its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2 (which should fail). Holder 1 can't decrease its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
// Sending payment from Holder 1 to Holder 2 (which should fail), Holder 1 can't decrease its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2 (which should fail). Holder 1 can't decrease its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
|
||||
// Sending payment from Holder 2 to Holder 1 (which should fail), Holder 1 can't increase its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 2 to Holder 1 (which should fail). Holder 1 can't increase its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet2)
|
||||
// Sending payment from Holder 2 to Holder 1 (which should fail), Holder 1 can't increase its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 2 to Holder 1 (which should fail). Holder 1 can't increase its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet2)
|
||||
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
|
||||
// Creating OfferCreate transaction (which should fail), Holder 1 can't create an offer
|
||||
fmt.Println("⏳ Creating OfferCreate transaction (which should fail). Holder 1 can't create an offer...")
|
||||
offerCreate := &transactions.OfferCreate{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
TakerPays: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
TakerGets: types.XRPCurrencyAmount(10),
|
||||
}
|
||||
submitAndWait(client, offerCreate, holderWallet1)
|
||||
// Creating OfferCreate transaction (which should fail), Holder 1 can't create an offer
|
||||
fmt.Println("⏳ Creating OfferCreate transaction (which should fail). Holder 1 can't create an offer...")
|
||||
offerCreate := &transactions.OfferCreate{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
TakerPays: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
TakerGets: types.XRPCurrencyAmount(10),
|
||||
}
|
||||
submitAndWait(client, offerCreate, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Unfreezing and Deep Unfreezing holder 1
|
||||
fmt.Println("⏳ Unfreezing and Deep Unfreezing holder 1 trustline...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(holderWallet1.ClassicAddress),
|
||||
Value: "0",
|
||||
},
|
||||
}
|
||||
trustSet.SetClearFreezeFlag()
|
||||
trustSet.SetClearDeepFreezeFlag()
|
||||
submitAndWait(client, trustSet, issuer)
|
||||
// Unfreezing and Deep Unfreezing holder 1
|
||||
fmt.Println("⏳ Unfreezing and Deep Unfreezing holder 1 trustline...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(holderWallet1.ClassicAddress),
|
||||
Value: "0",
|
||||
},
|
||||
}
|
||||
trustSet.SetClearFreezeFlag()
|
||||
trustSet.SetClearDeepFreezeFlag()
|
||||
submitAndWait(client, trustSet, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Sending payment from Holder 1 to Holder 2 (which should succeed), Holder 1 can decrease its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2 (which should succeed). Holder 1 can decrease its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
// Sending payment from Holder 1 to Holder 2 (which should succeed), Holder 1 can decrease its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2 (which should succeed). Holder 1 can decrease its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Sending payment from Holder 2 to Holder 1 (which should succeed), Holder 1 can increase its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 2 to Holder 1 (which should succeed). Holder 1 can increase its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet2)
|
||||
// Sending payment from Holder 2 to Holder 1 (which should succeed), Holder 1 can increase its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 2 to Holder 1 (which should succeed). Holder 1 can increase its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet2)
|
||||
}
|
||||
|
||||
// getRpcClient returns a new rpc client
|
||||
func getRpcClient() *rpc.Client {
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
// DeepFreeze only available on Devnet as of February 2025, change to testnet/mainnet once the amendment passes.
|
||||
"https://s.devnet.rippletest.net:51234",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
// DeepFreeze only available on Devnet as of February 2025, change to testnet/mainnet once the amendment passes.
|
||||
"https://s.devnet.rippletest.net:51234",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return rpc.NewClient(cfg)
|
||||
return rpc.NewClient(cfg)
|
||||
}
|
||||
|
||||
// submitAndWait submits a transaction and waits for it to be included in a validated ledger
|
||||
func submitAndWait(client *rpc.Client, txn SubmittableTransaction, wallet wallet.Wallet) {
|
||||
fmt.Printf("⏳ Submitting %s transaction...\n", txn.TxType())
|
||||
fmt.Printf("⏳ Submitting %s transaction...\n", txn.TxType())
|
||||
|
||||
flattenedTx := txn.Flatten()
|
||||
flattenedTx := txn.Flatten()
|
||||
|
||||
err := client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
err := client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err := wallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
txBlob, _, err := wallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("✅ %s transaction submitted\n", txn.TxType())
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Printf("✅ %s transaction submitted\n", txn.TxType())
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -1,357 +1,357 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/currency"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
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/websocket"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/currency"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
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/websocket"
|
||||
)
|
||||
|
||||
const (
|
||||
currencyCode = "USDA"
|
||||
currencyCode = "USDA"
|
||||
)
|
||||
|
||||
type SubmittableTransaction interface {
|
||||
TxType() transactions.TxType
|
||||
Flatten() transactions.FlatTransaction // Ensures all transactions can be flattened
|
||||
TxType() transactions.TxType
|
||||
Flatten() transactions.FlatTransaction // Ensures all transactions can be flattened
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("⏳ Setting up client...")
|
||||
fmt.Println("⏳ Setting up client...")
|
||||
|
||||
client := getClient()
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
client := getClient()
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Client configured!")
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Client configured!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("Connection: %t", client.IsConnected())
|
||||
fmt.Println()
|
||||
fmt.Printf("Connection: %t", client.IsConnected())
|
||||
fmt.Println()
|
||||
|
||||
// Configure wallets
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Issuer
|
||||
fmt.Println("⏳ Setting up issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding issuer wallet: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Issuer wallet funded: %s\n", issuer.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Holder 1
|
||||
fmt.Println("⏳ Setting up holder 1 wallet...")
|
||||
holderWallet1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder wallet 1: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Holder 1
|
||||
fmt.Println("⏳ Setting up holder 1 wallet...")
|
||||
holderWallet1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder wallet 1: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder wallet 1: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder wallet 1 funded: %s\n", holderWallet1.ClassicAddress)
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder wallet 1: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder wallet 1 funded: %s\n", holderWallet1.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Holder 2
|
||||
fmt.Println("⏳ Setting up holder 2 wallet...")
|
||||
holderWallet2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder wallet 2: %s\n", err)
|
||||
return
|
||||
}
|
||||
// Holder 2
|
||||
fmt.Println("⏳ Setting up holder 2 wallet...")
|
||||
holderWallet2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error creating holder wallet 2: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet2)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder wallet 2: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder wallet 2 funded: %s\n", holderWallet2.ClassicAddress)
|
||||
fmt.Println()
|
||||
err = client.FundWallet(&holderWallet2)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error funding holder wallet 2: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("✅ Holder wallet 2 funded: %s\n", holderWallet2.ClassicAddress)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Wallets setup complete!")
|
||||
fmt.Println()
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Configuring Issuing account
|
||||
fmt.Println("⏳ Configuring issuer address settings...")
|
||||
accountSet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Domain: types.Domain("697373756572"), // issuer
|
||||
}
|
||||
// Configuring Issuing account
|
||||
fmt.Println("⏳ Configuring issuer address settings...")
|
||||
accountSet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Domain: types.Domain("697373756572"), // issuer
|
||||
}
|
||||
|
||||
accountSet.SetAsfDefaultRipple()
|
||||
submitAndWait(client, accountSet, issuer)
|
||||
accountSet.SetAsfDefaultRipple()
|
||||
submitAndWait(client, accountSet, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Trustline from the holder 1 to the issuer
|
||||
fmt.Println("⏳ Setting up trustline from holder 1 to the issuer...")
|
||||
trustSet := &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "1000000000",
|
||||
}}
|
||||
trustSet.SetSetNoRippleFlag()
|
||||
submitAndWait(client, trustSet, holderWallet1)
|
||||
// Trustline from the holder 1 to the issuer
|
||||
fmt.Println("⏳ Setting up trustline from holder 1 to the issuer...")
|
||||
trustSet := &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "1000000000",
|
||||
}}
|
||||
trustSet.SetSetNoRippleFlag()
|
||||
submitAndWait(client, trustSet, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Trustline from the holder 2 to the issuer
|
||||
fmt.Println("⏳ Setting up trustline from holder 2 to the issuer...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "1000000000",
|
||||
},
|
||||
}
|
||||
trustSet.SetSetNoRippleFlag()
|
||||
submitAndWait(client, trustSet, holderWallet2)
|
||||
// Trustline from the holder 2 to the issuer
|
||||
fmt.Println("⏳ Setting up trustline from holder 2 to the issuer...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "1000000000",
|
||||
},
|
||||
}
|
||||
trustSet.SetSetNoRippleFlag()
|
||||
submitAndWait(client, trustSet, holderWallet2)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Minting to Holder 1
|
||||
fmt.Println("⏳ Minting to Holder 1...")
|
||||
payment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "50000",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, issuer)
|
||||
// Minting to Holder 1
|
||||
fmt.Println("⏳ Minting to Holder 1...")
|
||||
payment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "50000",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Minting to Holder 2
|
||||
fmt.Println("⏳ Minting to Holder 2...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "40000",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, issuer)
|
||||
// Minting to Holder 2
|
||||
fmt.Println("⏳ Minting to Holder 2...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "40000",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Sending payment from Holder 1 to Holder 2
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "20",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
// Sending payment from Holder 1 to Holder 2
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "20",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Freezing and Deep Freezing holder1
|
||||
fmt.Println("⏳ Freezing and Deep Freezing holder 1 trustline...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(holderWallet1.ClassicAddress),
|
||||
Value: "0",
|
||||
},
|
||||
}
|
||||
trustSet.SetSetFreezeFlag()
|
||||
trustSet.SetSetDeepFreezeFlag()
|
||||
// Freezing and Deep Freezing holder1
|
||||
fmt.Println("⏳ Freezing and Deep Freezing holder 1 trustline...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(holderWallet1.ClassicAddress),
|
||||
Value: "0",
|
||||
},
|
||||
}
|
||||
trustSet.SetSetFreezeFlag()
|
||||
trustSet.SetSetDeepFreezeFlag()
|
||||
|
||||
submitAndWait(client, trustSet, issuer)
|
||||
submitAndWait(client, trustSet, issuer)
|
||||
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
|
||||
// Sending payment from Holder 1 to Holder 2 (which should fail), Holder 1 can't decrease its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2 (which should fail). Holder 1 can't decrease its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
// Sending payment from Holder 1 to Holder 2 (which should fail), Holder 1 can't decrease its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2 (which should fail). Holder 1 can't decrease its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
|
||||
// Sending payment from Holder 2 to Holder 1 (which should fail), Holder 1 can't increase its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 2 to Holder 1 (which should fail). Holder 1 can't increase its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet2)
|
||||
// Sending payment from Holder 2 to Holder 1 (which should fail), Holder 1 can't increase its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 2 to Holder 1 (which should fail). Holder 1 can't increase its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet2)
|
||||
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
// ------------------- SHOULD FAIL ⬇️ ------------------
|
||||
|
||||
// Creating OfferCreate transaction (which should fail), Holder 1 can't create an offer
|
||||
fmt.Println("⏳ Creating OfferCreate transaction (which should fail). Holder 1 can't create an offer...")
|
||||
offerCreate := &transactions.OfferCreate{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
TakerPays: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
TakerGets: types.XRPCurrencyAmount(10),
|
||||
}
|
||||
submitAndWait(client, offerCreate, holderWallet1)
|
||||
// Creating OfferCreate transaction (which should fail), Holder 1 can't create an offer
|
||||
fmt.Println("⏳ Creating OfferCreate transaction (which should fail). Holder 1 can't create an offer...")
|
||||
offerCreate := &transactions.OfferCreate{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
TakerPays: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
TakerGets: types.XRPCurrencyAmount(10),
|
||||
}
|
||||
submitAndWait(client, offerCreate, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Unfreezing and Deep Unfreezing holder 1
|
||||
fmt.Println("⏳ Unfreezing and Deep Unfreezing holder 1 trustline...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(holderWallet1.ClassicAddress),
|
||||
Value: "0",
|
||||
},
|
||||
}
|
||||
trustSet.SetClearFreezeFlag()
|
||||
trustSet.SetClearDeepFreezeFlag()
|
||||
submitAndWait(client, trustSet, issuer)
|
||||
// Unfreezing and Deep Unfreezing holder 1
|
||||
fmt.Println("⏳ Unfreezing and Deep Unfreezing holder 1 trustline...")
|
||||
trustSet = &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(issuer.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(holderWallet1.ClassicAddress),
|
||||
Value: "0",
|
||||
},
|
||||
}
|
||||
trustSet.SetClearFreezeFlag()
|
||||
trustSet.SetClearDeepFreezeFlag()
|
||||
submitAndWait(client, trustSet, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Sending payment from Holder 1 to Holder 2 (which should succeed), Holder 1 can decrease its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2 (which should succeed). Holder 1 can decrease its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
// Sending payment from Holder 1 to Holder 2 (which should succeed), Holder 1 can decrease its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 1 to Holder 2 (which should succeed). Holder 1 can decrease its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet1.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet2.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Sending payment from Holder 2 to Holder 1 (which should succeed), Holder 1 can increase its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 2 to Holder 1 (which should succeed). Holder 1 can increase its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet2)
|
||||
// Sending payment from Holder 2 to Holder 1 (which should succeed), Holder 1 can increase its balance
|
||||
fmt.Println("⏳ Sending payment from Holder 2 to Holder 1 (which should succeed). Holder 1 can increase its balance...")
|
||||
payment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(holderWallet2.ClassicAddress),
|
||||
},
|
||||
Destination: types.Address(holderWallet1.ClassicAddress),
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currency.ConvertStringToHex(currencyCode),
|
||||
Issuer: types.Address(issuer.ClassicAddress),
|
||||
Value: "10",
|
||||
},
|
||||
}
|
||||
submitAndWait(client, payment, holderWallet2)
|
||||
}
|
||||
|
||||
// getRpcClient returns a new rpc client
|
||||
func getClient() *websocket.Client {
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
|
||||
return client
|
||||
return client
|
||||
}
|
||||
|
||||
// submitAndWait submits a transaction and waits for it to be included in a validated ledger
|
||||
func submitAndWait(client *websocket.Client, txn SubmittableTransaction, wallet wallet.Wallet) {
|
||||
fmt.Printf("⏳ Submitting %s transaction...\n", txn.TxType())
|
||||
fmt.Printf("⏳ Submitting %s transaction...\n", txn.TxType())
|
||||
|
||||
flattenedTx := txn.Flatten()
|
||||
flattenedTx := txn.Flatten()
|
||||
|
||||
err := client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
err := client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error autofilling %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err := wallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
txBlob, _, err := wallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error signing %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Error submitting %s transaction: %s\n", txn.TxType(), err)
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("✅ %s transaction submitted\n", txn.TxType())
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Printf("✅ %s transaction submitted\n", txn.TxType())
|
||||
fmt.Printf("🌐 Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/utility"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/utility"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Define the network client configuration
|
||||
cfg, err := rpc.NewClientConfig("https://s.altnet.rippletest.net:51234/")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Define the network client configuration
|
||||
cfg, err := rpc.NewClientConfig("https://s.altnet.rippletest.net:51234/")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Initiate the network client
|
||||
client := rpc.NewClient(cfg)
|
||||
// Initiate the network client
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Ping the network (used to avoid Go unused variable error, but useful to check connectivity)
|
||||
_, err = client.Ping(&utility.PingRequest{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Ping the network (used to avoid Go unused variable error, but useful to check connectivity)
|
||||
_, err = client.Ping(&utility.PingRequest{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// ... custom code goes here
|
||||
// ... custom code goes here
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/xrpl/websocket"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/websocket"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Define the network client
|
||||
client := websocket.NewClient(websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net:51233"))
|
||||
// Define the network client
|
||||
client := websocket.NewClient(websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net:51233"))
|
||||
|
||||
// Disconnect the client when done. (Defer executes at the end of the function)
|
||||
defer client.Disconnect()
|
||||
// Disconnect the client when done. (Defer executes at the end of the function)
|
||||
defer client.Disconnect()
|
||||
|
||||
// Connect to the network
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Connect to the network
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// ... custom code goes here
|
||||
// ... custom code goes here
|
||||
}
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
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/account"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/ledger"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
"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/account"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/ledger"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Define the network client with a faucet provider
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := rpc.NewClient(cfg)
|
||||
// Define the network client with a faucet provider
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Create a new wallet
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("New wallet created:")
|
||||
fmt.Println("Address:", w.ClassicAddress)
|
||||
// Create a new wallet
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("New wallet created:")
|
||||
fmt.Println("Address:", w.ClassicAddress)
|
||||
|
||||
// Fund the wallet with testnet XRP
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Fund the wallet with testnet XRP
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Get info from the ledger about the address we just funded
|
||||
acc_info, err := client.GetAccountInfo(&account.InfoRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Account Balance:", acc_info.AccountData.Balance)
|
||||
fmt.Println("Account Sequence:", acc_info.AccountData.Sequence)
|
||||
// Get info from the ledger about the address we just funded
|
||||
acc_info, err := client.GetAccountInfo(&account.InfoRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Account Balance:", acc_info.AccountData.Balance)
|
||||
fmt.Println("Account Sequence:", acc_info.AccountData.Sequence)
|
||||
|
||||
// Get info about the ledger
|
||||
ledger, err := client.GetLedger(&ledger.Request{LedgerIndex: common.Current})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Ledger Index:", ledger.Ledger.LedgerIndex)
|
||||
// Get info about the ledger
|
||||
ledger, err := client.GetLedger(&ledger.Request{LedgerIndex: common.Current})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Ledger Index:", ledger.Ledger.LedgerIndex)
|
||||
}
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
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/account"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/ledger"
|
||||
"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/account"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/ledger"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/websocket"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Define the network client with a faucet provider
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
// Define the network client with a faucet provider
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
|
||||
// Disconnect the client when done. (Defer executes at the end of the function)
|
||||
defer client.Disconnect()
|
||||
// Disconnect the client when done. (Defer executes at the end of the function)
|
||||
defer client.Disconnect()
|
||||
|
||||
// Connect to the network
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Connect to the network
|
||||
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()
|
||||
|
||||
// Create a new wallet
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("New wallet created:")
|
||||
fmt.Println("Address:", w.ClassicAddress)
|
||||
// Create a new wallet
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("New wallet created:")
|
||||
fmt.Println("Address:", w.ClassicAddress)
|
||||
|
||||
// Fund the wallet with testnet XRP
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Fund the wallet with testnet XRP
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Get info from the ledger about the address we just funded
|
||||
acc_info, err := client.GetAccountInfo(&account.InfoRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Account Balance:", acc_info.AccountData.Balance)
|
||||
fmt.Println("Account Sequence:", acc_info.AccountData.Sequence)
|
||||
// Get info from the ledger about the address we just funded
|
||||
acc_info, err := client.GetAccountInfo(&account.InfoRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Account Balance:", acc_info.AccountData.Balance)
|
||||
fmt.Println("Account Sequence:", acc_info.AccountData.Sequence)
|
||||
|
||||
// Get info about the ledger
|
||||
ledger, err := client.GetLedger(&ledger.Request{LedgerIndex: common.Current})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Ledger Index:", ledger.Ledger.LedgerIndex)
|
||||
// Get info about the ledger
|
||||
ledger, err := client.GetLedger(&ledger.Request{LedgerIndex: common.Current})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Ledger Index:", ledger.Ledger.LedgerIndex)
|
||||
}
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/ledger"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/transactions"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/common"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/ledger"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/transactions"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Get the latest validated ledger
|
||||
led, err := client.GetLedger(&ledger.Request{
|
||||
Transactions: true,
|
||||
LedgerIndex: common.Validated,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Latest validated ledger:", led)
|
||||
// Get the latest validated ledger
|
||||
led, err := client.GetLedger(&ledger.Request{
|
||||
Transactions: true,
|
||||
LedgerIndex: common.Validated,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Latest validated ledger:", led)
|
||||
|
||||
// Get the first transaction hash from the ledger
|
||||
if len(led.Ledger.Transactions) > 0 {
|
||||
txHash := led.Ledger.Transactions[0].(string) // type assertion may be needed
|
||||
// Get the first transaction hash from the ledger
|
||||
if len(led.Ledger.Transactions) > 0 {
|
||||
txHash := led.Ledger.Transactions[0].(string) // type assertion may be needed
|
||||
|
||||
// Query the transaction details
|
||||
txResp, err := client.Request(&transactions.TxRequest{
|
||||
Transaction: txHash,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("First transaction in the ledger:")
|
||||
fmt.Println(txResp)
|
||||
}
|
||||
// Query the transaction details
|
||||
txResp, err := client.Request(&transactions.TxRequest{
|
||||
Transaction: txHash,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("First transaction in the ledger:")
|
||||
fmt.Println(txResp)
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -7,15 +7,15 @@ package main
|
||||
// install: go get github.com/gorilla/websocket
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// websocket address
|
||||
@@ -23,75 +23,75 @@ var addr = flag.String("addr", "s.altnet.rippletest.net:51233", "http service ad
|
||||
|
||||
// Payload object
|
||||
type message struct {
|
||||
Command string `json:"command"`
|
||||
Accounts []string `json:"accounts"`
|
||||
Command string `json:"command"`
|
||||
Accounts []string `json:"accounts"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
log.SetFlags(0)
|
||||
flag.Parse()
|
||||
log.SetFlags(0)
|
||||
|
||||
var m message
|
||||
var m message
|
||||
|
||||
// check for interrupts and cleanly close the connection
|
||||
interrupt := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt, os.Interrupt)
|
||||
// check for interrupts and cleanly close the connection
|
||||
interrupt := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt, os.Interrupt)
|
||||
|
||||
u := url.URL{Scheme: "ws", Host: *addr, Path: "/"}
|
||||
log.Printf("connecting to %s", u.String())
|
||||
u := url.URL{Scheme: "ws", Host: *addr, Path: "/"}
|
||||
log.Printf("connecting to %s", u.String())
|
||||
|
||||
// make the connection
|
||||
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
||||
if err != nil {
|
||||
log.Fatal("dial:", err)
|
||||
}
|
||||
// on exit close
|
||||
defer c.Close()
|
||||
// make the connection
|
||||
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
||||
if err != nil {
|
||||
log.Fatal("dial:", err)
|
||||
}
|
||||
// on exit close
|
||||
defer c.Close()
|
||||
|
||||
done := make(chan struct{})
|
||||
done := make(chan struct{})
|
||||
|
||||
// send a subscribe command and a target XRPL account
|
||||
m.Command = "subscribe"
|
||||
m.Accounts = append(m.Accounts, "rUCzEr6jrEyMpjhs4wSdQdz4g8Y382NxfM")
|
||||
// send a subscribe command and a target XRPL account
|
||||
m.Command = "subscribe"
|
||||
m.Accounts = append(m.Accounts, "rUCzEr6jrEyMpjhs4wSdQdz4g8Y382NxfM")
|
||||
|
||||
// struct to JSON marshalling
|
||||
msg, _ := json.Marshal(m)
|
||||
// write to the websocket
|
||||
err = c.WriteMessage(websocket.TextMessage, []byte(string(msg)))
|
||||
if err != nil {
|
||||
log.Println("write:", err)
|
||||
return
|
||||
}
|
||||
// struct to JSON marshalling
|
||||
msg, _ := json.Marshal(m)
|
||||
// write to the websocket
|
||||
err = c.WriteMessage(websocket.TextMessage, []byte(string(msg)))
|
||||
if err != nil {
|
||||
log.Println("write:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// read from the websocket
|
||||
_, message, err := c.ReadMessage()
|
||||
if err != nil {
|
||||
log.Println("read:", err)
|
||||
return
|
||||
}
|
||||
// print the response from the XRP Ledger
|
||||
log.Printf("recv: %s", message)
|
||||
// read from the websocket
|
||||
_, message, err := c.ReadMessage()
|
||||
if err != nil {
|
||||
log.Println("read:", err)
|
||||
return
|
||||
}
|
||||
// print the response from the XRP Ledger
|
||||
log.Printf("recv: %s", message)
|
||||
|
||||
// handle interrupt
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
return
|
||||
case <-interrupt:
|
||||
log.Println("interrupt")
|
||||
// handle interrupt
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
return
|
||||
case <-interrupt:
|
||||
log.Println("interrupt")
|
||||
|
||||
// Cleanly close the connection by sending a close message and then
|
||||
// waiting (with timeout) for the server to close the connection.
|
||||
err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
||||
if err != nil {
|
||||
log.Println("write close:", err)
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(time.Second):
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
// Cleanly close the connection by sending a close message and then
|
||||
// waiting (with timeout) for the server to close the connection.
|
||||
err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
||||
if err != nil {
|
||||
log.Println("write close:", err)
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(time.Second):
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,166 +1,166 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"maps"
|
||||
"strings"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"maps"
|
||||
"strings"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/xrpl"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/ledger-entry-types"
|
||||
"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/xrpl"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/ledger-entry-types"
|
||||
"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"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
w1, err := wallet.FromSeed("sEdTtvLmJmrb7GaivhWoXRkvU4NDjVf", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w1, err := wallet.FromSeed("sEdTtvLmJmrb7GaivhWoXRkvU4NDjVf", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
w2, err := wallet.FromSeed("sEdSFiKMQp7RvYLgH7t7FEpwNRWv2Gr", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w2, err := wallet.FromSeed("sEdSFiKMQp7RvYLgH7t7FEpwNRWv2Gr", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
master, err := wallet.FromSeed("sEdTMm2yv8c8Rg8YHFHQA9TxVMFy1ze", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
master, err := wallet.FromSeed("sEdTMm2yv8c8Rg8YHFHQA9TxVMFy1ze", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
|
||||
if err := client.FundWallet(&master); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Master wallet funded")
|
||||
fmt.Println()
|
||||
fmt.Println("⏳ Setting up signer list...")
|
||||
if err := client.FundWallet(&master); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Master wallet funded")
|
||||
fmt.Println()
|
||||
fmt.Println("⏳ Setting up signer list...")
|
||||
|
||||
ss := &transaction.SignerListSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: master.GetAddress(),
|
||||
},
|
||||
SignerQuorum: uint32(2),
|
||||
SignerEntries: []ledger.SignerEntryWrapper{
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: w1.GetAddress(),
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: w2.GetAddress(),
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: "XVYRdEocC28DRx94ZFGP3qNJ1D5Ln7ecXFMd3vREB5Pesju",
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
ss := &transaction.SignerListSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: master.GetAddress(),
|
||||
},
|
||||
SignerQuorum: uint32(2),
|
||||
SignerEntries: []ledger.SignerEntryWrapper{
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: w1.GetAddress(),
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: w2.GetAddress(),
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: "XVYRdEocC28DRx94ZFGP3qNJ1D5Ln7ecXFMd3vREB5Pesju",
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
flatSs := ss.Flatten()
|
||||
flatSs := ss.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatSs); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Autofill(&flatSs); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err := master.Sign(flatSs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err := master.Sign(flatSs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ SignerListSet transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ SignerListSet transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Setting up AccountSet multisign transaction...")
|
||||
fmt.Println("⏳ Setting up AccountSet multisign transaction...")
|
||||
|
||||
as := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: master.GetAddress(),
|
||||
},
|
||||
Domain: types.Domain(strings.ToUpper(hex.EncodeToString([]byte("example.com")))),
|
||||
}
|
||||
as := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: master.GetAddress(),
|
||||
},
|
||||
Domain: types.Domain(strings.ToUpper(hex.EncodeToString([]byte("example.com")))),
|
||||
}
|
||||
|
||||
flatAs := as.Flatten()
|
||||
flatAs := as.Flatten()
|
||||
|
||||
if err := client.AutofillMultisigned(&flatAs, 2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.AutofillMultisigned(&flatAs, 2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
w1As := maps.Clone(flatAs)
|
||||
w1As := maps.Clone(flatAs)
|
||||
|
||||
blob1, _, err := w1.Multisign(w1As)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob1, _, err := w1.Multisign(w1As)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
w2As := maps.Clone(flatAs)
|
||||
w2As := maps.Clone(flatAs)
|
||||
|
||||
blob2, _, err := w2.Multisign(w2As)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob2, _, err := w2.Multisign(w2As)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, err = xrpl.Multisign(blob1, blob2)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, err = xrpl.Multisign(blob1, blob2)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
mRes, err := client.SubmitMultisigned(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
mRes, err := client.SubmitMultisigned(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Multisigned transaction submitted!")
|
||||
fmt.Printf("🌐 Result: %s\n", mRes.EngineResult)
|
||||
fmt.Println("✅ Multisigned transaction submitted!")
|
||||
fmt.Printf("🌐 Result: %s\n", mRes.EngineResult)
|
||||
}
|
||||
|
||||
@@ -1,181 +1,181 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"maps"
|
||||
"strings"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"maps"
|
||||
"strings"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/xrpl"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/ledger-entry-types"
|
||||
"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/xrpl"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/ledger-entry-types"
|
||||
"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"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
w1, err := wallet.FromSeed("sEdTtvLmJmrb7GaivhWoXRkvU4NDjVf", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w1, err := wallet.FromSeed("sEdTtvLmJmrb7GaivhWoXRkvU4NDjVf", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
w2, err := wallet.FromSeed("sEdSFiKMQp7RvYLgH7t7FEpwNRWv2Gr", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w2, err := wallet.FromSeed("sEdSFiKMQp7RvYLgH7t7FEpwNRWv2Gr", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
master, err := wallet.FromSeed("sEdTMm2yv8c8Rg8YHFHQA9TxVMFy1ze", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
master, err := wallet.FromSeed("sEdTMm2yv8c8Rg8YHFHQA9TxVMFy1ze", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
|
||||
if err := client.FundWallet(&master); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Master wallet funded")
|
||||
fmt.Println()
|
||||
fmt.Println("⏳ Setting up signer list...")
|
||||
if err := client.FundWallet(&master); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Master wallet funded")
|
||||
fmt.Println()
|
||||
fmt.Println("⏳ Setting up signer list...")
|
||||
|
||||
ss := &transaction.SignerListSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: master.GetAddress(),
|
||||
},
|
||||
SignerQuorum: uint32(2),
|
||||
SignerEntries: []ledger.SignerEntryWrapper{
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: w1.GetAddress(),
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: w2.GetAddress(),
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: "XVYRdEocC28DRx94ZFGP3qNJ1D5Ln7ecXFMd3vREB5Pesju",
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
ss := &transaction.SignerListSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: master.GetAddress(),
|
||||
},
|
||||
SignerQuorum: uint32(2),
|
||||
SignerEntries: []ledger.SignerEntryWrapper{
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: w1.GetAddress(),
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: w2.GetAddress(),
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
SignerEntry: ledger.SignerEntry{
|
||||
Account: "XVYRdEocC28DRx94ZFGP3qNJ1D5Ln7ecXFMd3vREB5Pesju",
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Flattening transaction...")
|
||||
flatSs := ss.Flatten()
|
||||
fmt.Println("⏳ Flattening transaction...")
|
||||
flatSs := ss.Flatten()
|
||||
|
||||
fmt.Println("⏳ Autofilling transaction...")
|
||||
if err := client.Autofill(&flatSs); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Autofilling transaction...")
|
||||
if err := client.Autofill(&flatSs); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Signing transaction...")
|
||||
blob, _, err := master.Sign(flatSs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Signing transaction...")
|
||||
blob, _, err := master.Sign(flatSs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Submitting transaction...")
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Submitting transaction...")
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ SignerListSet transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
fmt.Println("✅ SignerListSet transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Setting up AccountSet multisign transaction...")
|
||||
fmt.Println("⏳ Setting up AccountSet multisign transaction...")
|
||||
|
||||
as := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: master.GetAddress(),
|
||||
},
|
||||
Domain: types.Domain(strings.ToUpper(hex.EncodeToString([]byte("example.com")))),
|
||||
}
|
||||
as := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: master.GetAddress(),
|
||||
},
|
||||
Domain: types.Domain(strings.ToUpper(hex.EncodeToString([]byte("example.com")))),
|
||||
}
|
||||
|
||||
flatAs := as.Flatten()
|
||||
flatAs := as.Flatten()
|
||||
|
||||
if err := client.AutofillMultisigned(&flatAs, 2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.AutofillMultisigned(&flatAs, 2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
w1As := maps.Clone(flatAs)
|
||||
w1As := maps.Clone(flatAs)
|
||||
|
||||
blob1, _, err := w1.Multisign(w1As)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob1, _, err := w1.Multisign(w1As)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
w2As := maps.Clone(flatAs)
|
||||
w2As := maps.Clone(flatAs)
|
||||
|
||||
blob2, _, err := w2.Multisign(w2As)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob2, _, err := w2.Multisign(w2As)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, err = xrpl.Multisign(blob1, blob2)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, err = xrpl.Multisign(blob1, blob2)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
mRes, err := client.SubmitMultisigned(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
mRes, err := client.SubmitMultisigned(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Multisigned transaction submitted!")
|
||||
fmt.Printf("🌐 Result: %s\n", mRes.EngineResult)
|
||||
fmt.Println("✅ Multisigned transaction submitted!")
|
||||
fmt.Printf("🌐 Result: %s\n", mRes.EngineResult)
|
||||
}
|
||||
|
||||
@@ -1,128 +1,128 @@
|
||||
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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize the RPC client configuration
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Initialize the RPC client configuration
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Create the RPC client
|
||||
client := rpc.NewClient(cfg)
|
||||
// Create the RPC client
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Step 1: Fund wallets
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
// Step 1: Fund wallets
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
|
||||
// Create and fund the NFT buyer wallet
|
||||
nftBuyer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT buyer wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftBuyer); err != nil {
|
||||
fmt.Println("❌ Error funding NFT buyer wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT buyer wallet funded!")
|
||||
fmt.Println()
|
||||
// Create and fund the NFT buyer wallet
|
||||
nftBuyer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT buyer wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftBuyer); err != nil {
|
||||
fmt.Println("❌ Error funding NFT buyer wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT buyer wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
// Step 2: Mint an NFT
|
||||
fmt.Println("⏳ Minting NFT...")
|
||||
// Step 2: Mint an NFT
|
||||
fmt.Println("⏳ Minting NFT...")
|
||||
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
Destination: nftBuyer.ClassicAddress,
|
||||
Amount: txnTypes.XRPCurrencyAmount(1000000), // 1 XRP
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
Destination: nftBuyer.ClassicAddress,
|
||||
Amount: txnTypes.XRPCurrencyAmount(1000000), // 1 XRP
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint txn is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint txn is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
|
||||
// Step 3: Retrieve the NFT token offer ID
|
||||
fmt.Println("⏳ Retrieving NFT offer ID...")
|
||||
// Step 3: Retrieve the NFT token offer ID
|
||||
fmt.Println("⏳ Retrieving NFT offer ID...")
|
||||
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
|
||||
offerID, ok := metaMap["offer_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ offer_id not found or not a string")
|
||||
return
|
||||
}
|
||||
offerID, ok := metaMap["offer_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ offer_id not found or not a string")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌎 offer_id:", offerID)
|
||||
fmt.Println()
|
||||
fmt.Println("🌎 offer_id:", offerID)
|
||||
fmt.Println()
|
||||
|
||||
// Step 4: Accept the NFT offer
|
||||
fmt.Println("⏳ Accepting NFT offer...")
|
||||
// Step 4: Accept the NFT offer
|
||||
fmt.Println("⏳ Accepting NFT offer...")
|
||||
|
||||
nftAccept := transaction.NFTokenAcceptOffer{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftBuyer.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenSellOffer: txnTypes.Hash256(offerID),
|
||||
}
|
||||
nftAccept := transaction.NFTokenAcceptOffer{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftBuyer.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenSellOffer: txnTypes.Hash256(offerID),
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxAndWait(nftAccept.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftBuyer,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error accepting NFT offer:", err)
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ NFTokenAcceptOffer txn is not in a validated ledger", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT offer accepted successfully! - 🌎 Hash: ", response.Hash)
|
||||
response, err := client.SubmitTxAndWait(nftAccept.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftBuyer,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error accepting NFT offer:", err)
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ NFTokenAcceptOffer txn is not in a validated ledger", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT offer accepted successfully! - 🌎 Hash: ", response.Hash)
|
||||
}
|
||||
|
||||
@@ -1,133 +1,133 @@
|
||||
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/transaction"
|
||||
txnTypes "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/xrpl/websocket/types"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/xrpl/websocket/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Connect to the XRPL devnet
|
||||
fmt.Println("⏳ Connecting to devnet...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
// Connect to the XRPL devnet
|
||||
fmt.Println("⏳ Connecting to devnet...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println("❌ Error connecting to devnet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println("❌ Error connecting to devnet:", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("❌ Failed to connect to devnet")
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ Connected to devnet")
|
||||
fmt.Println()
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("❌ Failed to connect to devnet")
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ Connected to devnet")
|
||||
fmt.Println()
|
||||
|
||||
// Fund wallets
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
// Fund wallets
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
|
||||
// Create and fund the NFT buyer wallet
|
||||
nftBuyer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT buyer wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftBuyer); err != nil {
|
||||
fmt.Println("❌ Error funding NFT buyer wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT buyer wallet funded!")
|
||||
fmt.Println()
|
||||
// Create and fund the NFT buyer wallet
|
||||
nftBuyer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT buyer wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftBuyer); err != nil {
|
||||
fmt.Println("❌ Error funding NFT buyer wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT buyer wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
// Mint an NFT
|
||||
fmt.Println("⏳ Minting NFT...")
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
Destination: nftBuyer.ClassicAddress,
|
||||
Amount: txnTypes.XRPCurrencyAmount(1000000), // 1 XRP
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
// Mint an NFT
|
||||
fmt.Println("⏳ Minting NFT...")
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
Destination: nftBuyer.ClassicAddress,
|
||||
Amount: txnTypes.XRPCurrencyAmount(1000000), // 1 XRP
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint transaction is not in a validated ledger:", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash:", responseMint.Hash)
|
||||
fmt.Println()
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint transaction is not in a validated ledger:", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash:", responseMint.Hash)
|
||||
fmt.Println()
|
||||
|
||||
// Extract the NFT token offer ID from the transaction metadata
|
||||
fmt.Println("⏳ Extracting offer ID...")
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
// Extract the NFT token offer ID from the transaction metadata
|
||||
fmt.Println("⏳ Extracting offer ID...")
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
|
||||
offerID, ok := metaMap["offer_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ offer_id not found or not a string")
|
||||
return
|
||||
}
|
||||
fmt.Println("🌎 offer_id:", offerID)
|
||||
fmt.Println()
|
||||
offerID, ok := metaMap["offer_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ offer_id not found or not a string")
|
||||
return
|
||||
}
|
||||
fmt.Println("🌎 offer_id:", offerID)
|
||||
fmt.Println()
|
||||
|
||||
// Accept the NFT offer
|
||||
fmt.Println("⏳ Accepting NFT offer...")
|
||||
nftAccept := transaction.NFTokenAcceptOffer{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftBuyer.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenSellOffer: txnTypes.Hash256(offerID),
|
||||
}
|
||||
// Accept the NFT offer
|
||||
fmt.Println("⏳ Accepting NFT offer...")
|
||||
nftAccept := transaction.NFTokenAcceptOffer{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftBuyer.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenSellOffer: txnTypes.Hash256(offerID),
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxAndWait(nftAccept.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftBuyer,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error accepting NFT offer:", err)
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ NFTokenAcceptOffer transaction is not in a validated ledger:", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT offer accepted successfully! - 🌎 Hash:", response.Hash)
|
||||
response, err := client.SubmitTxAndWait(nftAccept.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftBuyer,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error accepting NFT offer:", err)
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ NFTokenAcceptOffer transaction is not in a validated ledger:", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT offer accepted successfully! - 🌎 Hash:", response.Hash)
|
||||
}
|
||||
|
||||
@@ -1,114 +1,114 @@
|
||||
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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize the RPC client configuration
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Initialize the RPC client configuration
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Create the RPC client
|
||||
client := rpc.NewClient(cfg)
|
||||
// Create the RPC client
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Step 1: Fund wallets
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
// Step 1: Fund wallets
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
fmt.Println()
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
// Step 2: Mint an NFT
|
||||
fmt.Println("⏳ Minting NFT...")
|
||||
// Step 2: Mint an NFT
|
||||
fmt.Println("⏳ Minting NFT...")
|
||||
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint txn is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint txn is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
|
||||
// Step 3: Retrieve the token ID
|
||||
fmt.Println("⏳ Retrieving NFT ID...")
|
||||
// Step 3: Retrieve the token ID
|
||||
fmt.Println("⏳ Retrieving NFT ID...")
|
||||
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
|
||||
nftokenID, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
nftokenID, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID)
|
||||
fmt.Println()
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID)
|
||||
fmt.Println()
|
||||
|
||||
// Step 4: Burn the NFT
|
||||
fmt.Println("⏳ Burn the NFT...")
|
||||
// Step 4: Burn the NFT
|
||||
fmt.Println("⏳ Burn the NFT...")
|
||||
|
||||
nftBurn := transaction.NFTokenBurn{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenID: txnTypes.NFTokenID(nftokenID),
|
||||
}
|
||||
nftBurn := transaction.NFTokenBurn{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenID: txnTypes.NFTokenID(nftokenID),
|
||||
}
|
||||
|
||||
responseBurn, err := client.SubmitTxAndWait(nftBurn.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error burning NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseBurn.Validated {
|
||||
fmt.Println("❌ NFTokenBurn transactiob is not in a validated ledger", responseBurn)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT burned successfully! - 🌎 Hash: ", responseBurn.Hash)
|
||||
responseBurn, err := client.SubmitTxAndWait(nftBurn.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error burning NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseBurn.Validated {
|
||||
fmt.Println("❌ NFTokenBurn transactiob is not in a validated ledger", responseBurn)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT burned successfully! - 🌎 Hash: ", responseBurn.Hash)
|
||||
}
|
||||
|
||||
@@ -1,123 +1,123 @@
|
||||
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/transaction"
|
||||
txnTypes "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/xrpl/websocket/types"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/xrpl/websocket/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Connect to the XRPL devnet
|
||||
fmt.Println("⏳ Connecting to devnet...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
// Connect to the XRPL devnet
|
||||
fmt.Println("⏳ Connecting to devnet...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println("❌ Error connecting to devnet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println("❌ Error connecting to devnet:", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("❌ Failed to connect to devnet")
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ Connected to devnet")
|
||||
fmt.Println()
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("❌ Failed to connect to devnet")
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ Connected to devnet")
|
||||
fmt.Println()
|
||||
|
||||
// Step 1: Fund wallets
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
// Step 1: Fund wallets
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
fmt.Println()
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
// Step 2: Mint an NFT
|
||||
fmt.Println("⏳ Minting NFT...")
|
||||
// Step 2: Mint an NFT
|
||||
fmt.Println("⏳ Minting NFT...")
|
||||
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint txn is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint txn is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
|
||||
// Step 3: Retrieve the token ID
|
||||
fmt.Println("⏳ Retrieving NFT ID...")
|
||||
// Step 3: Retrieve the token ID
|
||||
fmt.Println("⏳ Retrieving NFT ID...")
|
||||
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
|
||||
nftokenID, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
nftokenID, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID)
|
||||
fmt.Println()
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID)
|
||||
fmt.Println()
|
||||
|
||||
// Step 4: Burn the NFT
|
||||
fmt.Println("⏳ Burn the NFT...")
|
||||
// Step 4: Burn the NFT
|
||||
fmt.Println("⏳ Burn the NFT...")
|
||||
|
||||
nftBurn := transaction.NFTokenBurn{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenID: txnTypes.NFTokenID(nftokenID),
|
||||
}
|
||||
nftBurn := transaction.NFTokenBurn{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenID: txnTypes.NFTokenID(nftokenID),
|
||||
}
|
||||
|
||||
responseBurn, err := client.SubmitTxAndWait(nftBurn.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error burning NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseBurn.Validated {
|
||||
fmt.Println("❌ NFTokenBurn transactiob is not in a validated ledger", responseBurn)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT burned successfully! - 🌎 Hash: ", responseBurn.Hash)
|
||||
responseBurn, err := client.SubmitTxAndWait(nftBurn.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error burning NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseBurn.Validated {
|
||||
fmt.Println("❌ NFTokenBurn transactiob is not in a validated ledger", responseBurn)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT burned successfully! - 🌎 Hash: ", responseBurn.Hash)
|
||||
}
|
||||
|
||||
@@ -1,163 +1,163 @@
|
||||
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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize the RPC client configuration
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Initialize the RPC client configuration
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Create the RPC client
|
||||
client := rpc.NewClient(cfg)
|
||||
// Create the RPC client
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Step 1: Fund wallet
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
// Step 1: Fund wallet
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
|
||||
// Step 2: Mint two NFTs
|
||||
fmt.Println("⏳ Minting first NFT...")
|
||||
// Step 2: Mint two NFTs
|
||||
fmt.Println("⏳ Minting first NFT...")
|
||||
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting first NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ First NFTokenMint transaction is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ First NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting first NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ First NFTokenMint transaction is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ First NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
|
||||
// Step 3: Retrieve the NFT token ID
|
||||
fmt.Println("⏳ Retrieving NFT ID...")
|
||||
// Step 3: Retrieve the NFT token ID
|
||||
fmt.Println("⏳ Retrieving NFT ID...")
|
||||
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
|
||||
nftokenID1, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
nftokenID1, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID1)
|
||||
fmt.Println()
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID1)
|
||||
fmt.Println()
|
||||
|
||||
// ------
|
||||
// ------
|
||||
|
||||
fmt.Println("⏳ Minting second NFT...")
|
||||
fmt.Println("⏳ Minting second NFT...")
|
||||
|
||||
nftMint2 := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint2.SetTransferableFlag()
|
||||
nftMint2 := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint2.SetTransferableFlag()
|
||||
|
||||
responseMint2, err := client.SubmitTxAndWait(nftMint2.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting second NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ Second NFTokenMint transaction is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ Second NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
responseMint2, err := client.SubmitTxAndWait(nftMint2.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting second NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ Second NFTokenMint transaction is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ Second NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
|
||||
// Step 3: Retrieve the second NFT token ID
|
||||
fmt.Println("⏳ Retrieving second NFT ID...")
|
||||
// Step 3: Retrieve the second NFT token ID
|
||||
fmt.Println("⏳ Retrieving second NFT ID...")
|
||||
|
||||
metaMap2, ok := responseMint2.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
metaMap2, ok := responseMint2.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
|
||||
nftokenID2, ok := metaMap2["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
nftokenID2, ok := metaMap2["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID2)
|
||||
fmt.Println()
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID2)
|
||||
fmt.Println()
|
||||
|
||||
// Step 4: Cancel the NFT offers
|
||||
fmt.Println("⏳ Canceling NFT offers...")
|
||||
// Step 4: Cancel the NFT offers
|
||||
fmt.Println("⏳ Canceling NFT offers...")
|
||||
|
||||
nftCancel := transaction.NFTokenCancelOffer{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenOffers: []txnTypes.NFTokenID{
|
||||
txnTypes.NFTokenID(nftokenID1),
|
||||
txnTypes.NFTokenID(nftokenID2),
|
||||
},
|
||||
}
|
||||
nftCancel := transaction.NFTokenCancelOffer{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenOffers: []txnTypes.NFTokenID{
|
||||
txnTypes.NFTokenID(nftokenID1),
|
||||
txnTypes.NFTokenID(nftokenID2),
|
||||
},
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxAndWait(nftCancel.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error canceling NFT offers:", err)
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ NFTokenCancelOffer transaction is not in a validated ledger", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT offers canceled successfully! - 🌎 Hash: ", response.Hash)
|
||||
response, err := client.SubmitTxAndWait(nftCancel.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error canceling NFT offers:", err)
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ NFTokenCancelOffer transaction is not in a validated ledger", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT offers canceled successfully! - 🌎 Hash: ", response.Hash)
|
||||
}
|
||||
|
||||
@@ -1,172 +1,172 @@
|
||||
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/transaction"
|
||||
txnTypes "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/xrpl/websocket/types"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/xrpl/websocket/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Connect to the XRPL devnet
|
||||
fmt.Println("⏳ Connecting to devnet...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
// Connect to the XRPL devnet
|
||||
fmt.Println("⏳ Connecting to devnet...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println("❌ Error connecting to devnet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println("❌ Error connecting to devnet:", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("❌ Failed to connect to devnet")
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ Connected to devnet")
|
||||
fmt.Println()
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("❌ Failed to connect to devnet")
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ Connected to devnet")
|
||||
fmt.Println()
|
||||
|
||||
// Step 1: Fund wallet
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
// Step 1: Fund wallet
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
fmt.Println("❌ Error funding NFT minter wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT minter wallet funded!")
|
||||
|
||||
// Step 2: Mint two NFTs
|
||||
fmt.Println("⏳ Minting first NFT...")
|
||||
// Step 2: Mint two NFTs
|
||||
fmt.Println("⏳ Minting first NFT...")
|
||||
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetTransferableFlag()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting first NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ First NFTokenMint transaction is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ First NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting first NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ First NFTokenMint transaction is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ First NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
|
||||
// Step 3: Retrieve the NFT token ID
|
||||
fmt.Println("⏳ Retrieving NFT ID...")
|
||||
// Step 3: Retrieve the NFT token ID
|
||||
fmt.Println("⏳ Retrieving NFT ID...")
|
||||
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
|
||||
nftokenID1, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
nftokenID1, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID1)
|
||||
fmt.Println()
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID1)
|
||||
fmt.Println()
|
||||
|
||||
// ------
|
||||
// ------
|
||||
|
||||
fmt.Println("⏳ Minting second NFT...")
|
||||
fmt.Println("⏳ Minting second NFT...")
|
||||
|
||||
nftMint2 := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint2.SetTransferableFlag()
|
||||
nftMint2 := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint2.SetTransferableFlag()
|
||||
|
||||
responseMint2, err := client.SubmitTxAndWait(nftMint2.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting second NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ Second NFTokenMint transaction is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ Second NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
responseMint2, err := client.SubmitTxAndWait(nftMint2.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting second NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ Second NFTokenMint transaction is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ Second NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
|
||||
// Step 3: Retrieve the second NFT token ID
|
||||
fmt.Println("⏳ Retrieving second NFT ID...")
|
||||
// Step 3: Retrieve the second NFT token ID
|
||||
fmt.Println("⏳ Retrieving second NFT ID...")
|
||||
|
||||
metaMap2, ok := responseMint2.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
metaMap2, ok := responseMint2.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
|
||||
nftokenID2, ok := metaMap2["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
nftokenID2, ok := metaMap2["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID2)
|
||||
fmt.Println()
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID2)
|
||||
fmt.Println()
|
||||
|
||||
// Step 4: Cancel the NFT offers
|
||||
fmt.Println("⏳ Canceling NFT offers...")
|
||||
// Step 4: Cancel the NFT offers
|
||||
fmt.Println("⏳ Canceling NFT offers...")
|
||||
|
||||
nftCancel := transaction.NFTokenCancelOffer{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenOffers: []txnTypes.NFTokenID{
|
||||
txnTypes.NFTokenID(nftokenID1),
|
||||
txnTypes.NFTokenID(nftokenID2),
|
||||
},
|
||||
}
|
||||
nftCancel := transaction.NFTokenCancelOffer{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftMinter.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenAcceptOfferTx,
|
||||
},
|
||||
NFTokenOffers: []txnTypes.NFTokenID{
|
||||
txnTypes.NFTokenID(nftokenID1),
|
||||
txnTypes.NFTokenID(nftokenID2),
|
||||
},
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxAndWait(nftCancel.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error canceling NFT offers:", err)
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ NFTokenCancelOffer transaction is not in a validated ledger", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT offers canceled successfully! - 🌎 Hash: ", response.Hash)
|
||||
response, err := client.SubmitTxAndWait(nftCancel.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error canceling NFT offers:", err)
|
||||
return
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("❌ NFTokenCancelOffer transaction is not in a validated ledger", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT offers canceled successfully! - 🌎 Hash: ", response.Hash)
|
||||
}
|
||||
|
||||
@@ -1,107 +1,107 @@
|
||||
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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.devnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
fmt.Println()
|
||||
client := rpc.NewClient(cfg)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
|
||||
// Create and fund the nft wallet
|
||||
nftWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating nft wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftWallet); err != nil {
|
||||
fmt.Println("❌ Error funding nft wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT wallet funded! - #️⃣: ", nftWallet.ClassicAddress)
|
||||
fmt.Println()
|
||||
// Create and fund the nft wallet
|
||||
nftWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating nft wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftWallet); err != nil {
|
||||
fmt.Println("❌ Error funding nft wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT wallet funded! - #️⃣: ", nftWallet.ClassicAddress)
|
||||
fmt.Println()
|
||||
|
||||
// Mint NFT
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftWallet.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetMutableFlag()
|
||||
nftMint.SetTransferableFlag()
|
||||
// Mint NFT
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftWallet.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetMutableFlag()
|
||||
nftMint.SetTransferableFlag()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint txn is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint txn is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
|
||||
nftokenID, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
nftokenID, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID)
|
||||
fmt.Println()
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID)
|
||||
fmt.Println()
|
||||
|
||||
// Update NFT
|
||||
nftModify := transaction.NFTokenModify{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftWallet.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenModifyTx,
|
||||
},
|
||||
URI: "68747470733A2F2F7961686F6F2E636F6D", // https://yahoo.com
|
||||
NFTokenID: txnTypes.NFTokenID(nftokenID),
|
||||
}
|
||||
// nftoken_id
|
||||
responseModify, err := client.SubmitTxAndWait(nftModify.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error modifying NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseModify.Validated {
|
||||
fmt.Println("❌ NFTokenModify txn is not in a validated ledger", responseModify)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT URI modified successfully! - 🌎 Hash: ", responseModify.Hash)
|
||||
// Update NFT
|
||||
nftModify := transaction.NFTokenModify{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftWallet.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenModifyTx,
|
||||
},
|
||||
URI: "68747470733A2F2F7961686F6F2E636F6D", // https://yahoo.com
|
||||
NFTokenID: txnTypes.NFTokenID(nftokenID),
|
||||
}
|
||||
// nftoken_id
|
||||
responseModify, err := client.SubmitTxAndWait(nftModify.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error modifying NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseModify.Validated {
|
||||
fmt.Println("❌ NFTokenModify txn is not in a validated ledger", responseModify)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT URI modified successfully! - 🌎 Hash: ", responseModify.Hash)
|
||||
}
|
||||
|
||||
@@ -1,117 +1,117 @@
|
||||
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/transaction"
|
||||
txnTypes "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/xrpl/websocket/types"
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
txnTypes "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/xrpl/websocket/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("⏳ Connecting to devnet...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
fmt.Println("⏳ Connecting to devnet...")
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.devnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
|
||||
)
|
||||
|
||||
defer client.Disconnect()
|
||||
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 devnet")
|
||||
return
|
||||
}
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("❌ Failed to connect to devnet")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Connected to devnet")
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Connected to devnet")
|
||||
fmt.Println()
|
||||
|
||||
// Create and fund the nft wallet
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
nftWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating nft wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftWallet); err != nil {
|
||||
fmt.Println("❌ Error funding nft wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT wallet funded!")
|
||||
fmt.Println()
|
||||
// Create and fund the nft wallet
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
nftWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error creating nft wallet:", err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&nftWallet); err != nil {
|
||||
fmt.Println("❌ Error funding nft wallet:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 NFT wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
// Mint NFT
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftWallet.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetMutableFlag()
|
||||
nftMint.SetTransferableFlag()
|
||||
// Mint NFT
|
||||
nftMint := transaction.NFTokenMint{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftWallet.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenMintTx,
|
||||
},
|
||||
NFTokenTaxon: 0,
|
||||
URI: txnTypes.NFTokenURI("68747470733A2F2F676F6F676C652E636F6D"), // https://google.com
|
||||
}
|
||||
nftMint.SetMutableFlag()
|
||||
nftMint.SetTransferableFlag()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint txn is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error minting NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseMint.Validated {
|
||||
fmt.Println("❌ NFTokenMint txn is not in a validated ledger", responseMint)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT minted successfully! - 🌎 Hash: ", responseMint.Hash)
|
||||
fmt.Println()
|
||||
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
metaMap, ok := responseMint.Meta.(map[string]any)
|
||||
if !ok {
|
||||
fmt.Println("❌ Meta is not a map[string]any")
|
||||
return
|
||||
}
|
||||
|
||||
nftokenID, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
nftokenID, ok := metaMap["nftoken_id"].(string)
|
||||
if !ok {
|
||||
fmt.Println("❌ nftoken_id not found or not a string")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID)
|
||||
fmt.Println()
|
||||
fmt.Println("🌎 nftoken_id:", nftokenID)
|
||||
fmt.Println()
|
||||
|
||||
// Update NFT
|
||||
nftModify := transaction.NFTokenModify{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftWallet.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenModifyTx,
|
||||
},
|
||||
URI: "68747470733A2F2F7961686F6F2E636F6D", // https://yahoo.com
|
||||
NFTokenID: txnTypes.NFTokenID(nftokenID),
|
||||
}
|
||||
// Update NFT
|
||||
nftModify := transaction.NFTokenModify{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: nftWallet.ClassicAddress,
|
||||
TransactionType: transaction.NFTokenModifyTx,
|
||||
},
|
||||
URI: "68747470733A2F2F7961686F6F2E636F6D", // https://yahoo.com
|
||||
NFTokenID: txnTypes.NFTokenID(nftokenID),
|
||||
}
|
||||
|
||||
responseModify, err := client.SubmitTxAndWait(nftModify.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error modifying NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseModify.Validated {
|
||||
fmt.Println("❌ NFTokenModify txn is not in a validated ledger", responseModify)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT URI modified successfully! - 🌎 Hash: ", responseModify.Hash)
|
||||
responseModify, err := client.SubmitTxAndWait(nftModify.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftWallet,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("❌ Error modifying NFT:", err)
|
||||
return
|
||||
}
|
||||
if !responseModify.Validated {
|
||||
fmt.Println("❌ NFTokenModify txn is not in a validated ledger", responseModify)
|
||||
return
|
||||
}
|
||||
fmt.Println("✅ NFT URI modified successfully! - 🌎 Hash: ", responseModify.Hash)
|
||||
}
|
||||
|
||||
@@ -1,168 +1,168 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
fmt.Println()
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
fmt.Println()
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
fmt.Println("⏳ Sending TrustSet transaction...")
|
||||
ts := &transaction.TrustSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w2.ClassicAddress,
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.ClassicAddress,
|
||||
Value: "10000000000",
|
||||
},
|
||||
}
|
||||
fmt.Println("⏳ Sending TrustSet transaction...")
|
||||
ts := &transaction.TrustSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w2.ClassicAddress,
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.ClassicAddress,
|
||||
Value: "10000000000",
|
||||
},
|
||||
}
|
||||
|
||||
flatTs := ts.Flatten()
|
||||
flatTs := ts.Flatten()
|
||||
|
||||
err = client.Autofill(&flatTs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatTs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err := w2.Sign(flatTs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err := w2.Sign(flatTs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ TrustSet transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ TrustSet transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Issuing tokens for wallet 2...")
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.GetAddress(),
|
||||
Value: "50",
|
||||
},
|
||||
Destination: w2.GetAddress(),
|
||||
}
|
||||
fmt.Println("⏳ Issuing tokens for wallet 2...")
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.GetAddress(),
|
||||
Value: "50",
|
||||
},
|
||||
Destination: w2.GetAddress(),
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
flatP := p.Flatten()
|
||||
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err = w1.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err = w1.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Payment transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Payment transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Submitting Partial Payment transaction...")
|
||||
pp := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w2.GetAddress(),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.GetAddress(),
|
||||
Value: "10",
|
||||
},
|
||||
Destination: w1.GetAddress(),
|
||||
}
|
||||
fmt.Println("⏳ Submitting Partial Payment transaction...")
|
||||
pp := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w2.GetAddress(),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.GetAddress(),
|
||||
Value: "10",
|
||||
},
|
||||
Destination: w1.GetAddress(),
|
||||
}
|
||||
|
||||
pp.SetPartialPaymentFlag()
|
||||
pp.SetPartialPaymentFlag()
|
||||
|
||||
flatPP := pp.Flatten()
|
||||
flatPP := pp.Flatten()
|
||||
|
||||
err = client.Autofill(&flatPP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatPP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err = w2.Sign(flatPP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err = w2.Sign(flatPP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Partial Payment transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Partial Payment transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -1,179 +1,179 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"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/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/websocket"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
fmt.Println()
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
fmt.Println()
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
fmt.Println("⏳ Sending TrustSet transaction...")
|
||||
ts := &transaction.TrustSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w2.ClassicAddress,
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.ClassicAddress,
|
||||
Value: "10000000000",
|
||||
},
|
||||
}
|
||||
fmt.Println("⏳ Sending TrustSet transaction...")
|
||||
ts := &transaction.TrustSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w2.ClassicAddress,
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.ClassicAddress,
|
||||
Value: "10000000000",
|
||||
},
|
||||
}
|
||||
|
||||
flatTs := ts.Flatten()
|
||||
flatTs := ts.Flatten()
|
||||
|
||||
err = client.Autofill(&flatTs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatTs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err := w2.Sign(flatTs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err := w2.Sign(flatTs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ TrustSet transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ TrustSet transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Issuing tokens for wallet 2...")
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.GetAddress(),
|
||||
Value: "50",
|
||||
},
|
||||
Destination: w2.GetAddress(),
|
||||
}
|
||||
fmt.Println("⏳ Issuing tokens for wallet 2...")
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.GetAddress(),
|
||||
Value: "50",
|
||||
},
|
||||
Destination: w2.GetAddress(),
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
flatP := p.Flatten()
|
||||
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err = w1.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err = w1.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Payment transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Payment transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Submitting Partial Payment transaction...")
|
||||
pp := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w2.GetAddress(),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.GetAddress(),
|
||||
Value: "10",
|
||||
},
|
||||
Destination: w1.GetAddress(),
|
||||
}
|
||||
fmt.Println("⏳ Submitting Partial Payment transaction...")
|
||||
pp := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w2.GetAddress(),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: "FOO",
|
||||
Issuer: w1.GetAddress(),
|
||||
Value: "10",
|
||||
},
|
||||
Destination: w1.GetAddress(),
|
||||
}
|
||||
|
||||
pp.SetPartialPaymentFlag()
|
||||
pp.SetPartialPaymentFlag()
|
||||
|
||||
flatPP := pp.Flatten()
|
||||
flatPP := pp.Flatten()
|
||||
|
||||
err = client.Autofill(&flatPP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatPP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err = w2.Sign(flatPP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err = w2.Sign(flatPP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Partial Payment transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Partial Payment transaction submitted!")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"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/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
func main() {
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(w.GetAddress()),
|
||||
Fee: types.XRPCurrencyAmount(13),
|
||||
Sequence: 1,
|
||||
Flags: 2147483648,
|
||||
LastLedgerSequence: 7835923,
|
||||
},
|
||||
Destination: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
Amount: types.XRPCurrencyAmount(10000),
|
||||
DeliverMax: types.XRPCurrencyAmount(10000),
|
||||
}
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(w.GetAddress()),
|
||||
Fee: types.XRPCurrencyAmount(13),
|
||||
Sequence: 1,
|
||||
Flags: 2147483648,
|
||||
LastLedgerSequence: 7835923,
|
||||
},
|
||||
Destination: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
Amount: types.XRPCurrencyAmount(10000),
|
||||
DeliverMax: types.XRPCurrencyAmount(10000),
|
||||
}
|
||||
|
||||
flattenedTx := p.Flatten()
|
||||
flattenedTx := p.Flatten()
|
||||
|
||||
fmt.Println("Payment object created:", flattenedTx)
|
||||
fmt.Println("Payment object created:", flattenedTx)
|
||||
|
||||
signedTx, txHash, err := w.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
signedTx, txHash, err := w.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Transaction signed successfully:", signedTx)
|
||||
fmt.Println("Transaction hash:", txHash)
|
||||
fmt.Println("Transaction signed successfully:", signedTx)
|
||||
fmt.Println("Transaction hash:", txHash)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -1,121 +1,121 @@
|
||||
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"
|
||||
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/websocket"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/currency"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
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/websocket"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
|
||||
fmt.Println("⏳ Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Connected to server")
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Connected to server")
|
||||
fmt.Println()
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -1,111 +1,111 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/xrpl/currency"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"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/xrpl/currency"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"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"
|
||||
|
||||
rpctypes "github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
rpctypes "github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
)
|
||||
|
||||
const (
|
||||
WalletSeed = "sn3nxiW7v8KXzPzAqzyHXbSSKNuN9"
|
||||
WalletSeed = "sn3nxiW7v8KXzPzAqzyHXbSSKNuN9"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithMaxFeeXRP(5.0),
|
||||
rpc.WithFeeCushion(1.5),
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithMaxFeeXRP(5.0),
|
||||
rpc.WithFeeCushion(1.5),
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
w, err := wallet.FromSeed(WalletSeed, "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w, err := wallet.FromSeed(WalletSeed, "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet funded")
|
||||
fmt.Println()
|
||||
fmt.Println("💸 Wallet funded")
|
||||
fmt.Println()
|
||||
|
||||
xrpAmount, err := currency.XrpToDrops("1")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
xrpAmount, err := currency.XrpToDrops("1")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
xrpAmountInt, err := strconv.ParseInt(xrpAmount, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
xrpAmountInt, err := strconv.ParseInt(xrpAmount, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Sending 1 XRP to rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe...")
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(w.GetAddress()),
|
||||
},
|
||||
Destination: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
Amount: types.XRPCurrencyAmount(xrpAmountInt),
|
||||
DeliverMax: types.XRPCurrencyAmount(xrpAmountInt),
|
||||
}
|
||||
fmt.Println("⏳ Sending 1 XRP to rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe...")
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(w.GetAddress()),
|
||||
},
|
||||
Destination: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
Amount: types.XRPCurrencyAmount(xrpAmountInt),
|
||||
DeliverMax: types.XRPCurrencyAmount(xrpAmountInt),
|
||||
}
|
||||
|
||||
flattenedTx := p.Flatten()
|
||||
flattenedTx := p.Flatten()
|
||||
|
||||
if err := client.Autofill(&flattenedTx); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Autofill(&flattenedTx); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
txBlob, _, err := w.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
txBlob, _, err := w.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("⏳ Using SubmitTxAndWait with wallet")
|
||||
fmt.Println()
|
||||
fmt.Println("✅ Payment submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("⏳ Using SubmitTxAndWait with wallet")
|
||||
fmt.Println()
|
||||
|
||||
flattenedTx2 := p.Flatten()
|
||||
resp, err := client.SubmitTxAndWait(flattenedTx2, &rpctypes.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &w,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
flattenedTx2 := p.Flatten()
|
||||
resp, err := client.SubmitTxAndWait(flattenedTx2, &rpctypes.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &w,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Payment submitted via SubmitTxAndWait")
|
||||
fmt.Printf("🌐 Hash: %s\n", resp.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", resp.Validated)
|
||||
fmt.Println("✅ Payment submitted via SubmitTxAndWait")
|
||||
fmt.Printf("🌐 Hash: %s\n", resp.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", resp.Validated)
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/xrpl/currency"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/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/websocket"
|
||||
wstypes "github.com/Peersyst/xrpl-go/xrpl/websocket/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/currency"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/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/websocket"
|
||||
wstypes "github.com/Peersyst/xrpl-go/xrpl/websocket/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
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
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("❌ Failed to connect to testnet")
|
||||
return
|
||||
fmt.Println("❌ Failed to connect to testnet")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Connected to testnet")
|
||||
@@ -39,15 +39,15 @@ fmt.Println()
|
||||
const WalletSeed = "sEd7zwWAu7vXMCBkkzokJHEXiKw2B2s"
|
||||
w, err := wallet.FromSeed(WalletSeed, "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Funding the wallet
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet funded")
|
||||
@@ -55,56 +55,56 @@ fmt.Println()
|
||||
|
||||
xrpAmount, err := currency.XrpToDrops("1")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
xrpAmountInt, err := strconv.ParseInt(xrpAmount, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Prepare a payment transaction
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(w.GetAddress()),
|
||||
},
|
||||
Destination: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
Amount: types.XRPCurrencyAmount(xrpAmountInt),
|
||||
DeliverMax: types.XRPCurrencyAmount(xrpAmountInt),
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: types.Address(w.GetAddress()),
|
||||
},
|
||||
Destination: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||
Amount: types.XRPCurrencyAmount(xrpAmountInt),
|
||||
DeliverMax: types.XRPCurrencyAmount(xrpAmountInt),
|
||||
}
|
||||
|
||||
flattenedTx := p.Flatten()
|
||||
|
||||
if err := client.Autofill(&flattenedTx); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Sign the transaction using the wallet
|
||||
txBlob, _, err := w.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Submit the transaction and wait for the result
|
||||
res_blob, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Example with SubmitTxAndWait
|
||||
flattenedTx2 := p.Flatten()
|
||||
res_flat, err := client.SubmitTxAndWait(flattenedTx2, &wstypes.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &w,
|
||||
Autofill: true,
|
||||
Wallet: &w,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Wait for validation -------------------------------------------------------
|
||||
// SubmitTxBlobAndWait() handles this automatically, but it can take 4-7s.
|
||||
@@ -113,7 +113,7 @@ if err != nil {
|
||||
fmt.Printf("🌐 Hash: %s\n", res_blob.Hash)
|
||||
fmt.Printf("🌐 Meta: %t\n", res_blob.Meta)
|
||||
res, _ := client.Request(&transactions.TxRequest{
|
||||
Transaction: res_flat.Hash.String(),
|
||||
Transaction: res_flat.Hash.String(),
|
||||
})
|
||||
fmt.Printf("🌐 Result: %s\n", res.Result)
|
||||
}
|
||||
|
||||
@@ -1,131 +1,131 @@
|
||||
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/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/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
regularKeyWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
regularKeyWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
|
||||
if err := client.FundWallet(®ularKeyWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(®ularKeyWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Regular key wallet funded")
|
||||
fmt.Println()
|
||||
fmt.Println("💸 Regular key wallet funded")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Setting regular key...")
|
||||
rk := &transaction.SetRegularKey{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
RegularKey: regularKeyWallet.GetAddress(),
|
||||
}
|
||||
fmt.Println("⏳ Setting regular key...")
|
||||
rk := &transaction.SetRegularKey{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
RegularKey: regularKeyWallet.GetAddress(),
|
||||
}
|
||||
|
||||
flatRk := rk.Flatten()
|
||||
flatRk := rk.Flatten()
|
||||
|
||||
err = client.Autofill(&flatRk)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatRk)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err := w1.Sign(flatRk)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err := w1.Sign(flatRk)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ SetRegularKey transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ SetRegularKey transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Checking if regular key is set...")
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
Destination: w2.GetAddress(),
|
||||
Amount: types.XRPCurrencyAmount(10000),
|
||||
}
|
||||
fmt.Println("⏳ Checking if regular key is set...")
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
Destination: w2.GetAddress(),
|
||||
Amount: types.XRPCurrencyAmount(10000),
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
flatP := p.Flatten()
|
||||
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err = regularKeyWallet.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err = regularKeyWallet.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Payment transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println("✅ Payment transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
}
|
||||
|
||||
@@ -1,142 +1,142 @@
|
||||
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/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/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/websocket"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
regularKeyWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
regularKeyWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Funding wallets...")
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
fmt.Println("💸 Wallet 1 funded")
|
||||
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
fmt.Println("💸 Wallet 2 funded")
|
||||
|
||||
if err := client.FundWallet(®ularKeyWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(®ularKeyWallet); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Regular key wallet funded")
|
||||
fmt.Println()
|
||||
fmt.Println("💸 Regular key wallet funded")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Setting regular key...")
|
||||
rk := &transaction.SetRegularKey{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
RegularKey: regularKeyWallet.GetAddress(),
|
||||
}
|
||||
fmt.Println("⏳ Setting regular key...")
|
||||
rk := &transaction.SetRegularKey{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
RegularKey: regularKeyWallet.GetAddress(),
|
||||
}
|
||||
|
||||
flatRk := rk.Flatten()
|
||||
flatRk := rk.Flatten()
|
||||
|
||||
err = client.Autofill(&flatRk)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatRk)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err := w1.Sign(flatRk)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err := w1.Sign(flatRk)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ SetRegularKey transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ SetRegularKey transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Checking if regular key is set...")
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
Destination: w2.GetAddress(),
|
||||
Amount: types.XRPCurrencyAmount(10000),
|
||||
}
|
||||
fmt.Println("⏳ Checking if regular key is set...")
|
||||
p := &transaction.Payment{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w1.GetAddress(),
|
||||
},
|
||||
Destination: w2.GetAddress(),
|
||||
Amount: types.XRPCurrencyAmount(10000),
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
flatP := p.Flatten()
|
||||
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err = regularKeyWallet.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err = regularKeyWallet.Sign(flatP)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ Payment transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println("✅ Payment transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
}
|
||||
|
||||
@@ -1,134 +1,134 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/Peersyst/xrpl-go/pkg/crypto"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/queries/account"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"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/account"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/rpc"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/transaction"
|
||||
"github.com/Peersyst/xrpl-go/xrpl/wallet"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("⏳ Funding wallet...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("💸 Wallet funded")
|
||||
fmt.Println()
|
||||
fmt.Println("💸 Wallet funded")
|
||||
fmt.Println()
|
||||
|
||||
info, err := client.GetAccountInfo(&account.InfoRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
info, err := client.GetAccountInfo(&account.InfoRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌐 Current wallet sequence:", info.AccountData.Sequence)
|
||||
fmt.Println()
|
||||
fmt.Println("🌐 Current wallet sequence:", info.AccountData.Sequence)
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("⏳ Submitting TicketCreate transaction...")
|
||||
tc := &transaction.TicketCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
Sequence: info.AccountData.Sequence,
|
||||
},
|
||||
TicketCount: 10,
|
||||
}
|
||||
fmt.Println("⏳ Submitting TicketCreate transaction...")
|
||||
tc := &transaction.TicketCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
Sequence: info.AccountData.Sequence,
|
||||
},
|
||||
TicketCount: 10,
|
||||
}
|
||||
|
||||
flatTc := tc.Flatten()
|
||||
flatTc := tc.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatTc); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Autofill(&flatTc); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
blob, _, err := w.Sign(flatTc)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err := w.Sign(flatTc)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ TicketCreate transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
fmt.Println("✅ TicketCreate transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
|
||||
objects, err := client.GetAccountObjects(&account.ObjectsRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
objects, err := client.GetAccountObjects(&account.ObjectsRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("🌐 Account objects:", objects.AccountObjects[0]["TicketSequence"])
|
||||
fmt.Println("🌐 Account objects:", objects.AccountObjects[0]["TicketSequence"])
|
||||
|
||||
seq, err := objects.AccountObjects[0]["TicketSequence"].(json.Number).Int64()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
seq, err := objects.AccountObjects[0]["TicketSequence"].(json.Number).Int64()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("⏳ Submitting AccountSet transaction...")
|
||||
as := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
Sequence: 0,
|
||||
TicketSequence: uint32(seq),
|
||||
},
|
||||
}
|
||||
fmt.Println("⏳ Submitting AccountSet transaction...")
|
||||
as := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
Sequence: 0,
|
||||
TicketSequence: uint32(seq),
|
||||
},
|
||||
}
|
||||
|
||||
flatAs := as.Flatten()
|
||||
flatAs := as.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatAs); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.Autofill(&flatAs); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
flatAs["Sequence"] = uint32(0)
|
||||
flatAs["Sequence"] = uint32(0)
|
||||
|
||||
blob, _, err = w.Sign(flatAs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
blob, _, err = w.Sign(flatAs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("✅ AccountSet transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
fmt.Println("✅ AccountSet transaction submitted")
|
||||
fmt.Printf("🌐 Hash: %s\n", res.Hash)
|
||||
fmt.Printf("🌐 Validated: %t\n", res.Validated)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user