mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2026-08-23 11:10:54 +00:00
Merge pull request #3211 from banasa44/docs/feat/add-go-to-docs
Add xrpl-go examples and references to xrpl-dev-portal
This commit is contained in:
4
_code-samples/batch/README.md
Normal file
4
_code-samples/batch/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Batch
|
||||
|
||||
Code samples showing how to create and submit a [Batch transaction](../../docs/concepts/transactions/batch-transactions.md).
|
||||
Both for simple and multi account batch transactions.
|
||||
24
_code-samples/batch/go/go.mod
Normal file
24
_code-samples/batch/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/batch/go/go.sum
Normal file
58
_code-samples/batch/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
198
_code-samples/batch/go/rpc/main.go
Normal file
198
_code-samples/batch/go/rpc/main.go
Normal file
@@ -0,0 +1,198 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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(),
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
// Create and fund wallets
|
||||
userWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
user2Wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallets...")
|
||||
if err := client.FundWallet(&userWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&user2Wallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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"
|
||||
}
|
||||
|
||||
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("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()
|
||||
|
||||
flattenedBatchTx := batchTx.Flatten()
|
||||
fmt.Println("Autofilling flattened batch transaction...")
|
||||
if err := client.Autofill(&flattenedBatchTx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Signing batch transaction...")
|
||||
response, err := client.SubmitTxAndWait(flattenedBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
fmt.Printf("User final balance: %s XRP\n", finalUserBalance)
|
||||
|
||||
fmt.Printf("Receiver final balance: %s XRP\n", finalReceiverBalance)
|
||||
|
||||
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()
|
||||
|
||||
flattenedMultiBatchTx := multiBatchTx.Flatten()
|
||||
fmt.Println("Autofilling flattened multi batch transaction...")
|
||||
if err := client.AutofillMultisigned(&flattenedMultiBatchTx, 1); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Signing multi batch transaction...")
|
||||
if err := wallet.SignMultiBatch(user2Wallet, &flattenedMultiBatchTx, nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxAndWait(flattenedMultiBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
199
_code-samples/batch/go/ws/main.go
Normal file
199
_code-samples/batch/go/ws/main.go
Normal file
@@ -0,0 +1,199 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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(),
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Create and fund wallets
|
||||
userWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
user2Wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallets...")
|
||||
if err := client.FundWallet(&userWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&user2Wallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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"
|
||||
}
|
||||
|
||||
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("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()
|
||||
|
||||
flattenedBatchTx := batchTx.Flatten()
|
||||
fmt.Println("Autofilling flattened batch transaction...")
|
||||
if err := client.Autofill(&flattenedBatchTx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Signing batch transaction...")
|
||||
response, err := client.SubmitTxAndWait(flattenedBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
fmt.Printf("User final balance: %s XRP\n", finalUserBalance)
|
||||
|
||||
fmt.Printf("Receiver final balance: %s XRP\n", finalReceiverBalance)
|
||||
|
||||
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()
|
||||
|
||||
flattenedMultiBatchTx := multiBatchTx.Flatten()
|
||||
fmt.Println("Autofilling flattened multi batch transaction...")
|
||||
if err := client.AutofillMultisigned(&flattenedMultiBatchTx, 1); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Signing multi batch transaction...")
|
||||
if err := wallet.SignMultiBatch(user2Wallet, &flattenedMultiBatchTx, nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxAndWait(flattenedMultiBatchTx, &types.SubmitOptions{
|
||||
Autofill: false,
|
||||
Wallet: &userWallet,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
24
_code-samples/checks/go/go.mod
Normal file
24
_code-samples/checks/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/checks/go/go.sum
Normal file
58
_code-samples/checks/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
152
_code-samples/checks/go/rpc/main.go
Normal file
152
_code-samples/checks/go/rpc/main.go
Normal file
@@ -0,0 +1,152 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Setting up wallets...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Sender wallet funded!")
|
||||
|
||||
if err := client.FundWallet(&receiverWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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("Creating check...")
|
||||
cc := &transaction.CheckCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
},
|
||||
Destination: receiverWallet.GetAddress(),
|
||||
SendMax: types.XRPCurrencyAmount(1000000),
|
||||
InvoiceID: "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
|
||||
}
|
||||
|
||||
flatCc := cc.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatCc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err := w.Sign(flatCc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
meta, ok := res.Meta.(map[string]interface{})
|
||||
if !ok {
|
||||
fmt.Println("Meta is not of type TxObjMeta")
|
||||
return
|
||||
}
|
||||
|
||||
var checkID string
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
createdNode, ok := affectedNode["CreatedNode"].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if createdNode["LedgerEntryType"] == string(ledger.CheckEntry) {
|
||||
|
||||
checkID = createdNode["LedgerIndex"].(string)
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
|
||||
flatCheckCash := checkCash.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatCheckCash); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err = receiverWallet.Sign(flatCheckCash)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Check cashed out!")
|
||||
fmt.Printf("Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
163
_code-samples/checks/go/ws/main.go
Normal file
163
_code-samples/checks/go/ws/main.go
Normal file
@@ -0,0 +1,163 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("Failed to connect to testnet")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Connected to testnet")
|
||||
fmt.Println()
|
||||
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
receiverWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Setting up wallets...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Sender wallet funded!")
|
||||
|
||||
if err := client.FundWallet(&receiverWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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("Creating check...")
|
||||
cc := &transaction.CheckCreate{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
},
|
||||
Destination: receiverWallet.GetAddress(),
|
||||
SendMax: types.XRPCurrencyAmount(1000000),
|
||||
InvoiceID: "46060241FABCF692D4D934BA2A6C4427CD4279083E38C77CBE642243E43BE291",
|
||||
}
|
||||
|
||||
flatCc := cc.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatCc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
||||
blob, _, err := w.Sign(flatCc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
meta, ok := res.Meta.(map[string]interface{})
|
||||
if !ok {
|
||||
fmt.Println("Meta is not of type TxObjMeta")
|
||||
return
|
||||
}
|
||||
|
||||
var checkID string
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
createdNode, ok := affectedNode["CreatedNode"].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if createdNode["LedgerEntryType"] == string(ledger.CheckEntry) {
|
||||
|
||||
checkID = createdNode["LedgerIndex"].(string)
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
|
||||
flatCheckCash := checkCash.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatCheckCash); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err = receiverWallet.Sign(flatCheckCash)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Check cashed out!")
|
||||
fmt.Printf("Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
3
_code-samples/clawback/README.md
Normal file
3
_code-samples/clawback/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Clawback
|
||||
|
||||
Create, configure, and execute a Clawback transaction to reclaim issued tokens from a trust line on the XRPL.
|
||||
24
_code-samples/clawback/go/go.mod
Normal file
24
_code-samples/clawback/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/clawback/go/go.sum
Normal file
58
_code-samples/clawback/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
235
_code-samples/clawback/go/rpc/main.go
Normal file
235
_code-samples/clawback/go/rpc/main.go
Normal file
@@ -0,0 +1,235 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
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)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
//
|
||||
// Configure wallets
|
||||
//
|
||||
fmt.Println("Setting up wallets...")
|
||||
coldWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = client.FundWallet(&coldWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Cold wallet funded!")
|
||||
|
||||
hotWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = client.FundWallet(&hotWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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()
|
||||
|
||||
//
|
||||
// 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.SetRequireDestTag()
|
||||
|
||||
flattenedTx := coldWalletAccountSet.Flatten()
|
||||
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err := coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//
|
||||
// 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",
|
||||
},
|
||||
}
|
||||
|
||||
flattenedTx = coldWalletClawback.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
241
_code-samples/clawback/go/ws/main.go
Normal file
241
_code-samples/clawback/go/ws/main.go
Normal file
@@ -0,0 +1,241 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
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()
|
||||
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Connection: ", client.IsConnected())
|
||||
|
||||
//
|
||||
// Configure wallets
|
||||
//
|
||||
fmt.Println("Setting up wallets...")
|
||||
coldWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = client.FundWallet(&coldWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Cold wallet funded!")
|
||||
|
||||
hotWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = client.FundWallet(&hotWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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()
|
||||
|
||||
//
|
||||
// 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.SetRequireDestTag()
|
||||
|
||||
flattenedTx := coldWalletAccountSet.Flatten()
|
||||
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err := coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//
|
||||
// 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",
|
||||
},
|
||||
}
|
||||
|
||||
flattenedTx = coldWalletClawback.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
3
_code-samples/credential/README.md
Normal file
3
_code-samples/credential/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Credential
|
||||
|
||||
Create, accept, and delete a credential on the XRPL using dedicated transactions between issuer and subject wallets.
|
||||
24
_code-samples/credential/go/go.mod
Normal file
24
_code-samples/credential/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/credential/go/go.sum
Normal file
58
_code-samples/credential/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
104
_code-samples/credential/go/rpc/main.go
Normal file
104
_code-samples/credential/go/rpc/main.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// As of February 2025, Credential is only available on Devnet.
|
||||
client := clients.GetDevnetRpcClient()
|
||||
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&subjectWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Subject wallet funded: %s\n", subjectWallet.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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")
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, acceptTxn, subjectWallet)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, deleteTxn, issuer)
|
||||
}
|
||||
116
_code-samples/credential/go/ws/main.go
Normal file
116
_code-samples/credential/go/ws/main.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Println("Setting up client...")
|
||||
|
||||
client := clients.GetDevnetWebsocketClient()
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Client configured!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("Connection: %t", client.IsConnected())
|
||||
fmt.Println()
|
||||
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&subjectWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Subject wallet funded: %s\n", subjectWallet.ClassicAddress)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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")
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, acceptTxn, subjectWallet)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, deleteTxn, issuer)
|
||||
}
|
||||
3
_code-samples/delegate-set/README.md
Normal file
3
_code-samples/delegate-set/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Delegate
|
||||
|
||||
Example delegating payment permission to an account and executing on behalf the delegator.
|
||||
24
_code-samples/delegate-set/go/go.mod
Normal file
24
_code-samples/delegate-set/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/delegate-set/go/go.sum
Normal file
58
_code-samples/delegate-set/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
125
_code-samples/delegate-set/go/rpc/main.go
Normal file
125
_code-samples/delegate-set/go/rpc/main.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
// Create and fund wallets
|
||||
delegatorWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
delegateeWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallets...")
|
||||
if err := client.FundWallet(&delegatorWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&delegateeWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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"
|
||||
}
|
||||
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Submit DelegateSet transaction
|
||||
response, err := client.SubmitTxAndWait(delegateSetTx.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &delegatorWallet,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Submit delegated payment
|
||||
response2, err := client.SubmitTxAndWait(delegatedPaymentTx.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &delegateeWallet,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
fmt.Printf("Delegator final balance: %s XRP\n", finalDelegatorBalance)
|
||||
fmt.Printf("Delegatee final balance: %s XRP\n", finalDelegateeBalance)
|
||||
}
|
||||
140
_code-samples/delegate-set/go/ws/main.go
Normal file
140
_code-samples/delegate-set/go/ws/main.go
Normal file
@@ -0,0 +1,140 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Create and fund wallets
|
||||
delegatorWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
delegateeWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallets...")
|
||||
if err := client.FundWallet(&delegatorWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&delegateeWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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"
|
||||
}
|
||||
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Submit DelegateSet transaction
|
||||
flattenedTx := delegateSetTx.Flatten()
|
||||
if err := client.Autofill(&flattenedTx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err := delegatorWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Submit delegated payment
|
||||
flatDelegatedPayment := delegatedPaymentTx.Flatten()
|
||||
if err := client.Autofill(&flatDelegatedPayment); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob2, _, err := delegateeWallet.Sign(flatDelegatedPayment)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response2, err := client.SubmitTxBlobAndWait(txBlob2, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
fmt.Printf("Delegator final balance: %s XRP\n", finalDelegatorBalance)
|
||||
fmt.Printf("Delegatee final balance: %s XRP\n", finalDelegateeBalance)
|
||||
}
|
||||
3
_code-samples/deposit-preauth/README.md
Normal file
3
_code-samples/deposit-preauth/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# DepositPreauth
|
||||
|
||||
Example of DepositPreauth transaction demonstrating how deposit permissions can be managed.
|
||||
24
_code-samples/deposit-preauth/go/go.mod
Normal file
24
_code-samples/deposit-preauth/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/deposit-preauth/go/go.sum
Normal file
58
_code-samples/deposit-preauth/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
214
_code-samples/deposit-preauth/go/rpc/main.go
Normal file
214
_code-samples/deposit-preauth/go/rpc/main.go
Normal file
@@ -0,0 +1,214 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := clients.GetDevnetRpcClient()
|
||||
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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()
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, accountSetTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
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")),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, credentialCreateTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, credentialAcceptTx, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, depositPreauthTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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,
|
||||
}
|
||||
|
||||
objectsResponse, err := client.GetAccountObjects(objectsRequest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
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...")
|
||||
|
||||
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)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
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)...")
|
||||
|
||||
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)
|
||||
}
|
||||
227
_code-samples/deposit-preauth/go/ws/main.go
Normal file
227
_code-samples/deposit-preauth/go/ws/main.go
Normal file
@@ -0,0 +1,227 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Println("Setting up client...")
|
||||
|
||||
client := clients.GetDevnetWebsocketClient()
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Client configured!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("Connection: %t", client.IsConnected())
|
||||
fmt.Println()
|
||||
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("Setting up credential issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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()
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, accountSetTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
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")),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, credentialCreateTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, credentialAcceptTx, holderWallet1)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
clients.SubmitTxBlobAndWait(client, depositPreauthTx, issuer)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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,
|
||||
}
|
||||
|
||||
objectsResponse, err := client.GetAccountObjects(objectsRequest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
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...")
|
||||
|
||||
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)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
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)...")
|
||||
|
||||
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)
|
||||
}
|
||||
24
_code-samples/freeze/go/go.mod
Normal file
24
_code-samples/freeze/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/freeze/go/go.sum
Normal file
58
_code-samples/freeze/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
335
_code-samples/freeze/go/rpc/main.go
Normal file
335
_code-samples/freeze/go/rpc/main.go
Normal file
@@ -0,0 +1,335 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
currencyCode = "USDA"
|
||||
)
|
||||
|
||||
type SubmittableTransaction interface {
|
||||
TxType() transactions.TxType
|
||||
Flatten() transactions.FlatTransaction // Ensures all transactions can be flattened
|
||||
}
|
||||
|
||||
func main() {
|
||||
client := getRpcClient()
|
||||
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("Setting up issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Holder wallet 2 funded: %s\n", holderWallet2.ClassicAddress)
|
||||
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
|
||||
}
|
||||
|
||||
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 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 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)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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)
|
||||
|
||||
// ------------------- 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)
|
||||
|
||||
// ------------------- 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)
|
||||
|
||||
// ------------------- 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)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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 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)
|
||||
}
|
||||
|
||||
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())
|
||||
|
||||
flattenedTx := txn.Flatten()
|
||||
|
||||
err := client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err := wallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("%s transaction submitted\n", txn.TxType())
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
344
_code-samples/freeze/go/ws/main.go
Normal file
344
_code-samples/freeze/go/ws/main.go
Normal file
@@ -0,0 +1,344 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
currencyCode = "USDA"
|
||||
)
|
||||
|
||||
type SubmittableTransaction interface {
|
||||
TxType() transactions.TxType
|
||||
Flatten() transactions.FlatTransaction // Ensures all transactions can be flattened
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Setting up client...")
|
||||
|
||||
client := getClient()
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Client configured!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("Connection: %t", client.IsConnected())
|
||||
fmt.Println()
|
||||
|
||||
// Configure wallets
|
||||
|
||||
// Issuer
|
||||
fmt.Println("Setting up issuer wallet...")
|
||||
issuer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&issuer)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.FundWallet(&holderWallet2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Holder wallet 2 funded: %s\n", holderWallet2.ClassicAddress)
|
||||
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
|
||||
}
|
||||
|
||||
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 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 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)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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)
|
||||
|
||||
// ------------------- 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)
|
||||
|
||||
// ------------------- 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)
|
||||
|
||||
// ------------------- 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)
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
||||
// 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 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()),
|
||||
)
|
||||
|
||||
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())
|
||||
|
||||
flattenedTx := txn.Flatten()
|
||||
|
||||
err := client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err := wallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("%s transaction submitted\n", txn.TxType())
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
@@ -8,3 +8,4 @@ For more context, see the Get Started tutorial for your preferred language:
|
||||
- [Java](https://xrpl.org/get-started-using-java.html)
|
||||
- [JavaScript](https://xrpl.org/get-started-using-javascript.html)
|
||||
- [PHP](https://xrpl.org/get-started-using-php.html)
|
||||
- [Go](https://xrpl.org/get-started-using-go.html)
|
||||
|
||||
30
_code-samples/get-started/go/base/rpc/main.go
Normal file
30
_code-samples/get-started/go/base/rpc/main.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"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/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// ... custom code goes here
|
||||
|
||||
}
|
||||
25
_code-samples/get-started/go/base/ws/main.go
Normal file
25
_code-samples/get-started/go/base/ws/main.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/Peersyst/xrpl-go/xrpl/faucet"
|
||||
"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").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// ... custom code goes here
|
||||
}
|
||||
55
_code-samples/get-started/go/get-acc-info/rpc/main.go
Normal file
55
_code-samples/get-started/go/get-acc-info/rpc/main.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
// Create a new wallet
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("New wallet created:")
|
||||
fmt.Println("Address:", w.ClassicAddress)
|
||||
|
||||
// Fund the wallet with testnet XRP
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Get info from the ledger about the address we just funded
|
||||
acc_info, err := client.GetAccountInfo(&account.InfoRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Ledger Index:", ledger.Ledger.LedgerIndex)
|
||||
}
|
||||
69
_code-samples/get-started/go/get-acc-info/ws/main.go
Normal file
69
_code-samples/get-started/go/get-acc-info/ws/main.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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()),
|
||||
)
|
||||
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("Failed to connect to testnet")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Connected to testnet")
|
||||
fmt.Println()
|
||||
|
||||
// Create a new wallet
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("New wallet created:")
|
||||
fmt.Println("Address:", w.ClassicAddress)
|
||||
|
||||
// Fund the wallet with testnet XRP
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Get info from the ledger about the address we just funded
|
||||
acc_info, err := client.GetAccountInfo(&account.InfoRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Ledger Index:", ledger.Ledger.LedgerIndex)
|
||||
}
|
||||
24
_code-samples/get-started/go/go.mod
Normal file
24
_code-samples/get-started/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/get-started/go/go.sum
Normal file
58
_code-samples/get-started/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
23
_code-samples/get-tx/go/go.mod
Normal file
23
_code-samples/get-tx/go/go.mod
Normal file
@@ -0,0 +1,23 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
56
_code-samples/get-tx/go/go.sum
Normal file
56
_code-samples/get-tx/go/go.sum
Normal file
@@ -0,0 +1,56 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
46
_code-samples/get-tx/go/main.go
Normal file
46
_code-samples/get-tx/go/main.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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 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)
|
||||
}
|
||||
}
|
||||
24
_code-samples/issue-a-token/go/go.mod
Normal file
24
_code-samples/issue-a-token/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/issue-a-token/go/go.sum
Normal file
58
_code-samples/issue-a-token/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
488
_code-samples/issue-a-token/go/rpc/main.go
Normal file
488
_code-samples/issue-a-token/go/rpc/main.go
Normal file
@@ -0,0 +1,488 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
currencyCode = "FOO"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//
|
||||
// Configure client
|
||||
//
|
||||
fmt.Println("Setting up client...")
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
fmt.Println("Client configured!")
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Configure wallets
|
||||
//
|
||||
fmt.Println("Setting up wallets...")
|
||||
coldWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = client.FundWallet(&coldWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Cold wallet funded!")
|
||||
|
||||
hotWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = client.FundWallet(&hotWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Hot wallet funded!")
|
||||
|
||||
customerOneWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = client.FundWallet(&customerOneWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Customer one wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("Wallets setup complete!")
|
||||
fmt.Println("Cold wallet:", coldWallet.ClassicAddress)
|
||||
fmt.Println("Hot wallet:", hotWallet.ClassicAddress)
|
||||
fmt.Println("Customer one wallet:", customerOneWallet.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
|
||||
}
|
||||
|
||||
coldWalletAccountSet.SetAsfDefaultRipple()
|
||||
coldWalletAccountSet.SetDisallowXRP()
|
||||
|
||||
coldWalletAccountSet.SetRequireDestTag()
|
||||
|
||||
flattenedTx := coldWalletAccountSet.Flatten()
|
||||
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err := coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Cold address settings configuration failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Cold address settings configured!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Configure hot address settings
|
||||
//
|
||||
fmt.Println("Configuring hot address settings...")
|
||||
hotWalletAccountSet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(hotWallet.ClassicAddress),
|
||||
},
|
||||
Domain: types.Domain("6578616D706C652E636F6D"), // example.com
|
||||
}
|
||||
|
||||
hotWalletAccountSet.SetAsfRequireAuth()
|
||||
hotWalletAccountSet.SetDisallowXRP()
|
||||
hotWalletAccountSet.SetRequireDestTag()
|
||||
|
||||
flattenedTx = hotWalletAccountSet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Hot address settings configuration failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Hot 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",
|
||||
},
|
||||
}
|
||||
|
||||
flattenedTx = hotColdTrustSet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//
|
||||
// Create trust line from costumer one to cold address
|
||||
//
|
||||
fmt.Println("Creating trust line from customer one to cold address...")
|
||||
customerOneColdTrustSet := &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(customerOneWallet.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100000000000000",
|
||||
},
|
||||
}
|
||||
|
||||
flattenedTx = customerOneColdTrustSet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = customerOneWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Trust line from customer one to cold address creation failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Trust line from customer one 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),
|
||||
}
|
||||
|
||||
flattenedTx = coldToHotPayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//
|
||||
// Send tokens from hot wallet to customer one
|
||||
//
|
||||
fmt.Println("Sending tokens from cold wallet to customer one...")
|
||||
coldToCustomerOnePayment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100",
|
||||
},
|
||||
Destination: types.Address(customerOneWallet.ClassicAddress),
|
||||
}
|
||||
|
||||
flattenedTx = coldToCustomerOnePayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Tokens not sent from cold wallet to customer one!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Tokens sent from cold wallet to customer one!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Freeze cold wallet
|
||||
//
|
||||
fmt.Println("Freezing cold wallet...")
|
||||
freezeColdWallet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
}
|
||||
|
||||
freezeColdWallet.SetAsfGlobalFreeze()
|
||||
|
||||
flattenedTx = freezeColdWallet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Cold wallet freezing failed!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Cold wallet frozen!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Try to send tokens from hot wallet to customer one
|
||||
//
|
||||
fmt.Println("Trying to send tokens from hot wallet to customer one...")
|
||||
hotToCustomerOnePayment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(hotWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100",
|
||||
},
|
||||
Destination: types.Address(customerOneWallet.ClassicAddress),
|
||||
}
|
||||
|
||||
flattenedTx = hotToCustomerOnePayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Tokens not sent from hot wallet to customer one!")
|
||||
fmt.Println()
|
||||
|
||||
// //
|
||||
// // Unfreeze cold wallet
|
||||
// //
|
||||
fmt.Println("Unfreezing cold wallet...")
|
||||
unfreezeColdWallet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
}
|
||||
|
||||
unfreezeColdWallet.ClearAsfGlobalFreeze()
|
||||
|
||||
flattenedTx = unfreezeColdWallet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Cold wallet unfreezing failed!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Cold wallet unfrozen!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Try to send tokens from hot wallet to customer one
|
||||
//
|
||||
fmt.Println("Trying to send tokens from hot wallet to customer one...")
|
||||
hotToCustomerOnePayment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(hotWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100",
|
||||
},
|
||||
Destination: types.Address(customerOneWallet.ClassicAddress),
|
||||
}
|
||||
|
||||
flattenedTx = hotToCustomerOnePayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Tokens not sent from hot wallet to customer one!")
|
||||
fmt.Println("Try again!")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Tokens sent from hot wallet to customer one!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
493
_code-samples/issue-a-token/go/ws/main.go
Normal file
493
_code-samples/issue-a-token/go/ws/main.go
Normal file
@@ -0,0 +1,493 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
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()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
fmt.Println("Client configured!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("Connecting to server...")
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Connection: ", client.IsConnected())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Configure wallets
|
||||
//
|
||||
fmt.Println("Setting up wallets...")
|
||||
coldWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = client.FundWallet(&coldWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Cold wallet funded!")
|
||||
|
||||
hotWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = client.FundWallet(&hotWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Hot wallet funded!")
|
||||
|
||||
customerOneWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = client.FundWallet(&customerOneWallet)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Customer one wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("Wallets setup complete!")
|
||||
fmt.Println("Cold wallet:", coldWallet.ClassicAddress)
|
||||
fmt.Println("Hot wallet:", hotWallet.ClassicAddress)
|
||||
fmt.Println("Customer one wallet:", customerOneWallet.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
|
||||
}
|
||||
|
||||
coldWalletAccountSet.SetAsfDefaultRipple()
|
||||
coldWalletAccountSet.SetDisallowXRP()
|
||||
|
||||
coldWalletAccountSet.SetRequireDestTag()
|
||||
|
||||
flattenedTx := coldWalletAccountSet.Flatten()
|
||||
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err := coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Cold address settings configuration failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Cold address settings configured!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Configure hot address settings
|
||||
//
|
||||
fmt.Println("Configuring hot address settings...")
|
||||
hotWalletAccountSet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(hotWallet.ClassicAddress),
|
||||
},
|
||||
Domain: types.Domain("6578616D706C652E636F6D"), // example.com
|
||||
}
|
||||
|
||||
hotWalletAccountSet.SetAsfRequireAuth()
|
||||
hotWalletAccountSet.SetDisallowXRP()
|
||||
hotWalletAccountSet.SetRequireDestTag()
|
||||
|
||||
flattenedTx = hotWalletAccountSet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Hot address settings configuration failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Hot 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",
|
||||
},
|
||||
}
|
||||
|
||||
flattenedTx = hotColdTrustSet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//
|
||||
// Create trust line from costumer one to cold address
|
||||
//
|
||||
fmt.Println("Creating trust line from customer one to cold address...")
|
||||
customerOneColdTrustSet := &transactions.TrustSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(customerOneWallet.ClassicAddress),
|
||||
},
|
||||
LimitAmount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100000000000000",
|
||||
},
|
||||
}
|
||||
|
||||
flattenedTx = customerOneColdTrustSet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = customerOneWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Trust line from customer one to cold address creation failed!")
|
||||
fmt.Println("Try again!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Trust line from customer one 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),
|
||||
}
|
||||
|
||||
flattenedTx = coldToHotPayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
//
|
||||
// Send tokens from hot wallet to customer one
|
||||
//
|
||||
fmt.Println("Sending tokens from cold wallet to customer one...")
|
||||
coldToCustomerOnePayment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100",
|
||||
},
|
||||
Destination: types.Address(customerOneWallet.ClassicAddress),
|
||||
}
|
||||
|
||||
flattenedTx = coldToCustomerOnePayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Tokens not sent from cold wallet to customer one!")
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Tokens sent from cold wallet to customer one!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Freeze cold wallet
|
||||
//
|
||||
fmt.Println("Freezing cold wallet...")
|
||||
freezeColdWallet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
}
|
||||
|
||||
freezeColdWallet.SetAsfGlobalFreeze()
|
||||
|
||||
flattenedTx = freezeColdWallet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Cold wallet freezing failed!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Cold wallet frozen!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Try to send tokens from hot wallet to customer one
|
||||
//
|
||||
fmt.Println("Trying to send tokens from hot wallet to customer one...")
|
||||
hotToCustomerOnePayment := &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(hotWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100",
|
||||
},
|
||||
Destination: types.Address(customerOneWallet.ClassicAddress),
|
||||
}
|
||||
|
||||
flattenedTx = hotToCustomerOnePayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Tokens not sent from hot wallet to customer one!")
|
||||
fmt.Println()
|
||||
|
||||
// //
|
||||
// // Unfreeze cold wallet
|
||||
// //
|
||||
fmt.Println("Unfreezing cold wallet...")
|
||||
unfreezeColdWallet := &transactions.AccountSet{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(coldWallet.ClassicAddress),
|
||||
},
|
||||
}
|
||||
|
||||
unfreezeColdWallet.ClearAsfGlobalFreeze()
|
||||
|
||||
flattenedTx = unfreezeColdWallet.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = coldWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Cold wallet unfreezing failed!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Cold wallet unfrozen!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
//
|
||||
// Try to send tokens from hot wallet to customer one
|
||||
//
|
||||
fmt.Println("Trying to send tokens from hot wallet to customer one...")
|
||||
hotToCustomerOnePayment = &transactions.Payment{
|
||||
BaseTx: transactions.BaseTx{
|
||||
Account: types.Address(hotWallet.ClassicAddress),
|
||||
},
|
||||
Amount: types.IssuedCurrencyAmount{
|
||||
Currency: currencyCode,
|
||||
Issuer: types.Address(coldWallet.ClassicAddress),
|
||||
Value: "100",
|
||||
},
|
||||
Destination: types.Address(customerOneWallet.ClassicAddress),
|
||||
}
|
||||
|
||||
flattenedTx = hotToCustomerOnePayment.Flatten()
|
||||
err = client.Autofill(&flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err = hotWallet.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err = client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !response.Validated {
|
||||
fmt.Println("Tokens not sent from hot wallet to customer one!")
|
||||
fmt.Println("Try again!")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Tokens sent from hot wallet to customer one!")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Println()
|
||||
}
|
||||
@@ -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,72 @@ 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 {
|
||||
panic(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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(time.Second):
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
_code-samples/multisigning/go/go.mod
Normal file
24
_code-samples/multisigning/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/multisigning/go/go.sum
Normal file
58
_code-samples/multisigning/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
152
_code-samples/multisigning/go/rpc/main.go
Normal file
152
_code-samples/multisigning/go/rpc/main.go
Normal file
@@ -0,0 +1,152 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
w1, err := wallet.FromSeed("sEdTtvLmJmrb7GaivhWoXRkvU4NDjVf", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
w2, err := wallet.FromSeed("sEdSFiKMQp7RvYLgH7t7FEpwNRWv2Gr", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
master, err := wallet.FromSeed("sEdTMm2yv8c8Rg8YHFHQA9TxVMFy1ze", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallets...")
|
||||
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Wallet 1 funded")
|
||||
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet 2 funded")
|
||||
|
||||
if err := client.FundWallet(&master); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
flatSs := ss.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatSs); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err := master.Sign(flatSs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("SignerListSet transaction submitted!")
|
||||
fmt.Printf("Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
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")))),
|
||||
}
|
||||
|
||||
flatAs := as.Flatten()
|
||||
|
||||
if err := client.AutofillMultisigned(&flatAs, 2); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
w1As := maps.Clone(flatAs)
|
||||
|
||||
blob1, _, err := w1.Multisign(w1As)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
w2As := maps.Clone(flatAs)
|
||||
|
||||
blob2, _, err := w2.Multisign(w2As)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, err = xrpl.Multisign(blob1, blob2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
mRes, err := client.SubmitMultisigned(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Multisigned transaction submitted!")
|
||||
fmt.Printf("Result: %s\n", mRes.EngineResult)
|
||||
}
|
||||
166
_code-samples/multisigning/go/ws/main.go
Normal file
166
_code-samples/multisigning/go/ws/main.go
Normal file
@@ -0,0 +1,166 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("Failed to connect to testnet")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Connected to testnet")
|
||||
fmt.Println()
|
||||
|
||||
w1, err := wallet.FromSeed("sEdTtvLmJmrb7GaivhWoXRkvU4NDjVf", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
w2, err := wallet.FromSeed("sEdSFiKMQp7RvYLgH7t7FEpwNRWv2Gr", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
master, err := wallet.FromSeed("sEdTMm2yv8c8Rg8YHFHQA9TxVMFy1ze", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallets...")
|
||||
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Wallet 1 funded")
|
||||
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet 2 funded")
|
||||
|
||||
if err := client.FundWallet(&master); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Println("Flattening transaction...")
|
||||
flatSs := ss.Flatten()
|
||||
|
||||
fmt.Println("Autofilling transaction...")
|
||||
if err := client.Autofill(&flatSs); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Signing transaction...")
|
||||
blob, _, err := master.Sign(flatSs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Submitting transaction...")
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("SignerListSet transaction submitted!")
|
||||
fmt.Printf("Hash: %s\n", res.Hash.String())
|
||||
fmt.Println()
|
||||
|
||||
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")))),
|
||||
}
|
||||
|
||||
flatAs := as.Flatten()
|
||||
|
||||
if err := client.AutofillMultisigned(&flatAs, 2); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
w1As := maps.Clone(flatAs)
|
||||
|
||||
blob1, _, err := w1.Multisign(w1As)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
w2As := maps.Clone(flatAs)
|
||||
|
||||
blob2, _, err := w2.Multisign(w2As)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, err = xrpl.Multisign(blob1, blob2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
mRes, err := client.SubmitMultisigned(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Multisigned transaction submitted!")
|
||||
fmt.Printf("Result: %s\n", mRes.EngineResult)
|
||||
}
|
||||
24
_code-samples/non-fungible-token/go/go.mod
Normal file
24
_code-samples/non-fungible-token/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/non-fungible-token/go/go.sum
Normal file
58
_code-samples/non-fungible-token/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
122
_code-samples/non-fungible-token/go/nft-accept/rpc/main.go
Normal file
122
_code-samples/non-fungible-token/go/nft-accept/rpc/main.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// Create the RPC client
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Step 1: Fund wallets
|
||||
fmt.Println("Funding wallets...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("NFT minter wallet funded!")
|
||||
|
||||
// Create and fund the NFT buyer wallet
|
||||
nftBuyer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&nftBuyer); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("NFT buyer wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
// 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()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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...")
|
||||
|
||||
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()
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxAndWait(nftAccept.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftBuyer,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("NFTokenAcceptOffer txn is not in a validated ledger", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("NFT offer accepted successfully! - Hash: ", response.Hash)
|
||||
}
|
||||
126
_code-samples/non-fungible-token/go/nft-accept/ws/main.go
Normal file
126
_code-samples/non-fungible-token/go/nft-accept/ws/main.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("Failed to connect to devnet")
|
||||
return
|
||||
}
|
||||
fmt.Println("Connected to devnet")
|
||||
fmt.Println()
|
||||
|
||||
// Fund wallets
|
||||
fmt.Println("Funding wallets...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("NFT minter wallet funded!")
|
||||
|
||||
// Create and fund the NFT buyer wallet
|
||||
nftBuyer, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&nftBuyer); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxAndWait(nftAccept.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftBuyer,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("NFTokenAcceptOffer transaction is not in a validated ledger:", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("NFT offer accepted successfully! - Hash:", response.Hash)
|
||||
}
|
||||
110
_code-samples/non-fungible-token/go/nft-burn/rpc/main.go
Normal file
110
_code-samples/non-fungible-token/go/nft-burn/rpc/main.go
Normal file
@@ -0,0 +1,110 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// Create the RPC client
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Step 1: Fund wallets
|
||||
fmt.Println("Funding wallets...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("NFT minter wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
// 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()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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...")
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
fmt.Println("nftoken_id:", nftokenID)
|
||||
fmt.Println()
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
responseBurn, err := client.SubmitTxAndWait(nftBurn.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !responseBurn.Validated {
|
||||
fmt.Println("NFTokenBurn transactiob is not in a validated ledger", responseBurn)
|
||||
return
|
||||
}
|
||||
fmt.Println("NFT burned successfully! - Hash: ", responseBurn.Hash)
|
||||
}
|
||||
118
_code-samples/non-fungible-token/go/nft-burn/ws/main.go
Normal file
118
_code-samples/non-fungible-token/go/nft-burn/ws/main.go
Normal file
@@ -0,0 +1,118 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("NFT minter wallet funded!")
|
||||
fmt.Println()
|
||||
|
||||
// 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()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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...")
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
fmt.Println("nftoken_id:", nftokenID)
|
||||
fmt.Println()
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
responseBurn, err := client.SubmitTxAndWait(nftBurn.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !responseBurn.Validated {
|
||||
fmt.Println("NFTokenBurn transactiob is not in a validated ledger", responseBurn)
|
||||
return
|
||||
}
|
||||
fmt.Println("NFT burned successfully! - Hash: ", responseBurn.Hash)
|
||||
}
|
||||
158
_code-samples/non-fungible-token/go/nft-cancel/rpc/main.go
Normal file
158
_code-samples/non-fungible-token/go/nft-cancel/rpc/main.go
Normal file
@@ -0,0 +1,158 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// Create the RPC client
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
// Step 1: Fund wallet
|
||||
fmt.Println("Funding wallet...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("NFT minter wallet funded!")
|
||||
|
||||
// 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()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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...")
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
fmt.Println("nftoken_id:", nftokenID1)
|
||||
fmt.Println()
|
||||
|
||||
// ------
|
||||
|
||||
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()
|
||||
|
||||
responseMint2, err := client.SubmitTxAndWait(nftMint2.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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...")
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
fmt.Println("nftoken_id:", nftokenID2)
|
||||
fmt.Println()
|
||||
|
||||
// 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),
|
||||
},
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxAndWait(nftCancel.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("NFTokenCancelOffer transaction is not in a validated ledger", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("NFT offers canceled successfully! - Hash: ", response.Hash)
|
||||
}
|
||||
166
_code-samples/non-fungible-token/go/nft-cancel/ws/main.go
Normal file
166
_code-samples/non-fungible-token/go/nft-cancel/ws/main.go
Normal file
@@ -0,0 +1,166 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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...")
|
||||
|
||||
// Create and fund the NFT minter wallet
|
||||
nftMinter, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&nftMinter); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("NFT minter wallet funded!")
|
||||
|
||||
// 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()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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...")
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
fmt.Println("nftoken_id:", nftokenID1)
|
||||
fmt.Println()
|
||||
|
||||
// ------
|
||||
|
||||
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()
|
||||
|
||||
responseMint2, err := client.SubmitTxAndWait(nftMint2.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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...")
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
fmt.Println("nftoken_id:", nftokenID2)
|
||||
fmt.Println()
|
||||
|
||||
// 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),
|
||||
},
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxAndWait(nftCancel.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftMinter,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !response.Validated {
|
||||
fmt.Println("NFTokenCancelOffer transaction is not in a validated ledger", response)
|
||||
return
|
||||
}
|
||||
fmt.Println("NFT offers canceled successfully! - Hash: ", response.Hash)
|
||||
}
|
||||
103
_code-samples/non-fungible-token/go/nft-modify/rpc/main.go
Normal file
103
_code-samples/non-fungible-token/go/nft-modify/rpc/main.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
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()
|
||||
|
||||
fmt.Println("Funding wallet...")
|
||||
|
||||
// Create and fund the nft wallet
|
||||
nftWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&nftWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftWallet,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
if !responseModify.Validated {
|
||||
fmt.Println("NFTokenModify txn is not in a validated ledger", responseModify)
|
||||
return
|
||||
}
|
||||
fmt.Println("NFT URI modified successfully! - Hash: ", responseModify.Hash)
|
||||
}
|
||||
112
_code-samples/non-fungible-token/go/nft-modify/ws/main.go
Normal file
112
_code-samples/non-fungible-token/go/nft-modify/ws/main.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("Failed to connect to devnet")
|
||||
return
|
||||
}
|
||||
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&nftWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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()
|
||||
|
||||
responseMint, err := client.SubmitTxAndWait(nftMint.Flatten(), &types.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &nftWallet,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
// 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 {
|
||||
panic(err)
|
||||
}
|
||||
if !responseModify.Validated {
|
||||
fmt.Println("NFTokenModify txn is not in a validated ledger", responseModify)
|
||||
return
|
||||
}
|
||||
fmt.Println("NFT URI modified successfully! - Hash: ", responseModify.Hash)
|
||||
}
|
||||
24
_code-samples/partial-payment/go/go.mod
Normal file
24
_code-samples/partial-payment/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/partial-payment/go/go.sum
Normal file
58
_code-samples/partial-payment/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
155
_code-samples/partial-payment/go/rpc/main.go
Normal file
155
_code-samples/partial-payment/go/rpc/main.go
Normal file
@@ -0,0 +1,155 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
fmt.Println("Funding wallets...")
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet 1 funded")
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet 2 funded")
|
||||
fmt.Println()
|
||||
|
||||
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",
|
||||
},
|
||||
}
|
||||
|
||||
flatTs := ts.Flatten()
|
||||
|
||||
err = client.Autofill(&flatTs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err := w2.Sign(flatTs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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(),
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err = w1.Sign(flatP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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(),
|
||||
}
|
||||
|
||||
pp.SetPartialPaymentFlag()
|
||||
|
||||
flatPP := pp.Flatten()
|
||||
|
||||
err = client.Autofill(&flatPP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err = w2.Sign(flatPP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Partial Payment transaction submitted!")
|
||||
fmt.Printf("Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
}
|
||||
165
_code-samples/partial-payment/go/ws/main.go
Normal file
165
_code-samples/partial-payment/go/ws/main.go
Normal file
@@ -0,0 +1,165 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("Failed to connect to testnet")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Connected to testnet")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("Funding wallets...")
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet 1 funded")
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet 2 funded")
|
||||
fmt.Println()
|
||||
|
||||
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",
|
||||
},
|
||||
}
|
||||
|
||||
flatTs := ts.Flatten()
|
||||
|
||||
err = client.Autofill(&flatTs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err := w2.Sign(flatTs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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(),
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err = w1.Sign(flatP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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(),
|
||||
}
|
||||
|
||||
pp.SetPartialPaymentFlag()
|
||||
|
||||
flatPP := pp.Flatten()
|
||||
|
||||
err = client.Autofill(&flatPP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err = w2.Sign(flatPP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Partial Payment transaction submitted!")
|
||||
fmt.Printf("Hash: %s\n", res.Hash.String())
|
||||
fmt.Printf("Validated: %t\n", res.Validated)
|
||||
fmt.Println()
|
||||
}
|
||||
24
_code-samples/paths/go/go.mod
Normal file
24
_code-samples/paths/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/paths/go/go.sum
Normal file
58
_code-samples/paths/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
105
_code-samples/paths/go/rpc/main.go
Normal file
105
_code-samples/paths/go/rpc/main.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
|
||||
pathtypes "github.com/Peersyst/xrpl-go/xrpl/queries/path/types"
|
||||
)
|
||||
|
||||
const (
|
||||
DestinationAccount = types.Address("rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj")
|
||||
)
|
||||
|
||||
var (
|
||||
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)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallet...")
|
||||
if err := client.FundWallet(&wallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Computed paths: %d\n", len(res.Alternatives))
|
||||
fmt.Println()
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatP); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, hash, err := wallet.Sign(flatP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txRes, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Payment submitted")
|
||||
fmt.Printf("Hash: %s\n", hash)
|
||||
fmt.Printf("Validated: %t\n", txRes.Validated)
|
||||
}
|
||||
115
_code-samples/paths/go/ws/main.go
Normal file
115
_code-samples/paths/go/ws/main.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
|
||||
pathtypes "github.com/Peersyst/xrpl-go/xrpl/queries/path/types"
|
||||
)
|
||||
|
||||
const (
|
||||
DestinationAccount = types.Address("rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj")
|
||||
)
|
||||
|
||||
var (
|
||||
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()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("Failed to connect to testnet")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Connected to testnet")
|
||||
fmt.Println()
|
||||
|
||||
wallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallet...")
|
||||
if err := client.FundWallet(&wallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Computed paths: %d\n", len(res.Alternatives))
|
||||
fmt.Println()
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatP); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, hash, err := wallet.Sign(flatP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txRes, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Payment submitted")
|
||||
fmt.Printf("Hash: %s\n", hash)
|
||||
fmt.Printf("Validated: %t\n", txRes.Validated)
|
||||
}
|
||||
19
_code-samples/secure-signing/go/go.mod
Normal file
19
_code-samples/secure-signing/go/go.mod
Normal file
@@ -0,0 +1,19 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
45
_code-samples/secure-signing/go/go.sum
Normal file
45
_code-samples/secure-signing/go/go.sum
Normal file
@@ -0,0 +1,45 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
42
_code-samples/secure-signing/go/main.go
Normal file
42
_code-samples/secure-signing/go/main.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
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),
|
||||
}
|
||||
|
||||
flattenedTx := p.Flatten()
|
||||
|
||||
fmt.Println("Payment object created:", flattenedTx)
|
||||
|
||||
signedTx, txHash, err := w.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Transaction signed successfully:", signedTx)
|
||||
fmt.Println("Transaction hash:", txHash)
|
||||
}
|
||||
24
_code-samples/send-a-memo/go/go.mod
Normal file
24
_code-samples/send-a-memo/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/send-a-memo/go/go.sum
Normal file
58
_code-samples/send-a-memo/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
107
_code-samples/send-a-memo/go/rpc/main.go
Normal file
107
_code-samples/send-a-memo/go/rpc/main.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
w, err := wallet.FromSeed("sEdSMVV4dJ1JbdBxmakRR4Puu3XVZz2", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
receiverWallet, err := wallet.FromSeed("sEd7d8Ci9nevdLCeUMctF3uGXp9WQqJ", "")
|
||||
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)
|
||||
|
||||
balance, err := client.GetXrpBalance(w.GetAddress())
|
||||
|
||||
if err != nil || balance == "0" {
|
||||
fmt.Println("Funding wallet...")
|
||||
err = client.FundWallet(&w)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Wallet funded")
|
||||
}
|
||||
|
||||
balance, _ = client.GetXrpBalance(w.GetAddress())
|
||||
|
||||
fmt.Printf("Balance: %s\n", balance)
|
||||
|
||||
amount, err := currency.XrpToDrops("1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
amountUint, err := strconv.ParseUint(amount, 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
err = client.Autofill(&flatTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err := w.Sign(flatTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Payment submitted")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("Validated: %t\n", response.Validated)
|
||||
}
|
||||
112
_code-samples/send-a-memo/go/ws/main.go
Normal file
112
_code-samples/send-a-memo/go/ws/main.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
w, err := wallet.FromSeed("sEdSMVV4dJ1JbdBxmakRR4Puu3XVZz2", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
receiverWallet, err := wallet.FromSeed("sEd7d8Ci9nevdLCeUMctF3uGXp9WQqJ", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Connected to server")
|
||||
fmt.Println()
|
||||
|
||||
balance, err := client.GetXrpBalance(w.GetAddress())
|
||||
|
||||
if err != nil || balance == "0" {
|
||||
fmt.Println("Funding wallet...")
|
||||
err = client.FundWallet(&w)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Wallet funded")
|
||||
}
|
||||
|
||||
balance, _ = client.GetXrpBalance(w.GetAddress())
|
||||
|
||||
fmt.Printf("Balance: %s\n", balance)
|
||||
|
||||
amount, err := currency.XrpToDrops("1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
amountUint, err := strconv.ParseUint(amount, 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
err = client.Autofill(&flatTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err := w.Sign(flatTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
response, err := client.SubmitTxBlobAndWait(txBlob, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Payment submitted")
|
||||
fmt.Printf("Hash: %s\n", response.Hash.String())
|
||||
fmt.Printf("Validated: %t\n", response.Validated)
|
||||
}
|
||||
24
_code-samples/send-xrp/go/go.mod
Normal file
24
_code-samples/send-xrp/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/send-xrp/go/go.sum
Normal file
58
_code-samples/send-xrp/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
103
_code-samples/send-xrp/go/rpc/main.go
Normal file
103
_code-samples/send-xrp/go/rpc/main.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
|
||||
rpctypes "github.com/Peersyst/xrpl-go/xrpl/rpc/types"
|
||||
)
|
||||
|
||||
const (
|
||||
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)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
w, err := wallet.FromSeed(WalletSeed, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallet...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet funded")
|
||||
fmt.Println()
|
||||
|
||||
xrpAmount, err := currency.XrpToDrops("1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
xrpAmountInt, err := strconv.ParseInt(xrpAmount, 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
if err := client.Autofill(&flattenedTx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txBlob, _, err := w.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Payment submitted via SubmitTxAndWait")
|
||||
fmt.Printf("Hash: %s\n", resp.Hash)
|
||||
fmt.Printf("Validated: %t\n", resp.Validated)
|
||||
}
|
||||
110
_code-samples/send-xrp/go/ws/main.go
Normal file
110
_code-samples/send-xrp/go/ws/main.go
Normal file
@@ -0,0 +1,110 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://s.altnet.rippletest.net:51233").
|
||||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
defer client.Disconnect()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("Failed to connect to testnet")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Connected to testnet")
|
||||
fmt.Println()
|
||||
|
||||
// Example credentials
|
||||
const WalletSeed = "sEd7zwWAu7vXMCBkkzokJHEXiKw2B2s"
|
||||
w, err := wallet.FromSeed(WalletSeed, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Funding the wallet
|
||||
fmt.Println("Funding wallet...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet funded")
|
||||
fmt.Println()
|
||||
|
||||
xrpAmount, err := currency.XrpToDrops("1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
xrpAmountInt, err := strconv.ParseInt(xrpAmount, 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
flattenedTx := p.Flatten()
|
||||
|
||||
if err := client.Autofill(&flattenedTx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Sign the transaction using the wallet
|
||||
txBlob, _, err := w.Sign(flattenedTx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Submit the transaction and wait for the result
|
||||
res_blob, err := client.SubmitTxBlobAndWait(txBlob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Example with SubmitTxAndWait
|
||||
flattenedTx2 := p.Flatten()
|
||||
res_flat, err := client.SubmitTxAndWait(flattenedTx2, &wstypes.SubmitOptions{
|
||||
Autofill: true,
|
||||
Wallet: &w,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Wait for validation -------------------------------------------------------
|
||||
// SubmitTxBlobAndWait() handles this automatically, but it can take 4-7s.
|
||||
|
||||
// Check transaction results -------------------------------------------------
|
||||
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(),
|
||||
})
|
||||
fmt.Printf("Result: %s\n", res.Result)
|
||||
}
|
||||
24
_code-samples/set-regular-key/go/go.mod
Normal file
24
_code-samples/set-regular-key/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/set-regular-key/go/go.sum
Normal file
58
_code-samples/set-regular-key/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
119
_code-samples/set-regular-key/go/rpc/main.go
Normal file
119
_code-samples/set-regular-key/go/rpc/main.go
Normal file
@@ -0,0 +1,119 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
regularKeyWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallets...")
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet 1 funded")
|
||||
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet 2 funded")
|
||||
|
||||
if err := client.FundWallet(®ularKeyWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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(),
|
||||
}
|
||||
|
||||
flatRk := rk.Flatten()
|
||||
|
||||
err = client.Autofill(&flatRk)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err := w1.Sign(flatRk)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err = regularKeyWallet.Sign(flatP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Payment transaction submitted")
|
||||
fmt.Printf("Hash: %s\n", res.Hash)
|
||||
fmt.Printf("Validated: %t\n", res.Validated)
|
||||
}
|
||||
129
_code-samples/set-regular-key/go/ws/main.go
Normal file
129
_code-samples/set-regular-key/go/ws/main.go
Normal file
@@ -0,0 +1,129 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !client.IsConnected() {
|
||||
fmt.Println("Failed to connect to testnet")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Connected to testnet")
|
||||
fmt.Println()
|
||||
|
||||
w1, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
w2, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
regularKeyWallet, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallets...")
|
||||
if err := client.FundWallet(&w1); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet 1 funded")
|
||||
|
||||
if err := client.FundWallet(&w2); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet 2 funded")
|
||||
|
||||
if err := client.FundWallet(®ularKeyWallet); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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(),
|
||||
}
|
||||
|
||||
flatRk := rk.Flatten()
|
||||
|
||||
err = client.Autofill(&flatRk)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err := w1.Sign(flatRk)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
|
||||
flatP := p.Flatten()
|
||||
|
||||
err = client.Autofill(&flatP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err = regularKeyWallet.Sign(flatP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Payment transaction submitted")
|
||||
fmt.Printf("Hash: %s\n", res.Hash)
|
||||
fmt.Printf("Validated: %t\n", res.Validated)
|
||||
}
|
||||
24
_code-samples/use-tickets/go/go.mod
Normal file
24
_code-samples/use-tickets/go/go.mod
Normal file
@@ -0,0 +1,24 @@
|
||||
module github.com/XRPLF
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/Peersyst/xrpl-go v0.1.11
|
||||
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
)
|
||||
58
_code-samples/use-tickets/go/go.sum
Normal file
58
_code-samples/use-tickets/go/go.sum
Normal file
@@ -0,0 +1,58 @@
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
|
||||
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
|
||||
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
|
||||
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
|
||||
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
|
||||
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
|
||||
123
_code-samples/use-tickets/go/main.go
Normal file
123
_code-samples/use-tickets/go/main.go
Normal file
@@ -0,0 +1,123 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := rpc.NewClientConfig(
|
||||
"https://s.altnet.rippletest.net:51234/",
|
||||
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rpc.NewClient(cfg)
|
||||
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Funding wallet...")
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Wallet funded")
|
||||
fmt.Println()
|
||||
|
||||
info, err := client.GetAccountInfo(&account.InfoRequest{
|
||||
Account: w.GetAddress(),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
flatTc := tc.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatTc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
blob, _, err := w.Sign(flatTc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err := client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Account objects:", objects.AccountObjects[0]["TicketSequence"])
|
||||
|
||||
seq, err := objects.AccountObjects[0]["TicketSequence"].(json.Number).Int64()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Submitting AccountSet transaction...")
|
||||
as := &transaction.AccountSet{
|
||||
BaseTx: transaction.BaseTx{
|
||||
Account: w.GetAddress(),
|
||||
Sequence: 0,
|
||||
TicketSequence: uint32(seq),
|
||||
},
|
||||
}
|
||||
|
||||
flatAs := as.Flatten()
|
||||
|
||||
if err := client.Autofill(&flatAs); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
flatAs["Sequence"] = uint32(0)
|
||||
|
||||
blob, _, err = w.Sign(flatAs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err = client.SubmitTxBlobAndWait(blob, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("AccountSet transaction submitted")
|
||||
fmt.Printf("Hash: %s\n", res.Hash)
|
||||
fmt.Printf("Validated: %t\n", res.Validated)
|
||||
}
|
||||
@@ -334,6 +334,16 @@ export default function Docs() {
|
||||
<h5 className="btn-arrow">{translate('Java')}</h5>
|
||||
</Link>
|
||||
</div>
|
||||
<div className="col langs">
|
||||
<Link to="/docs/tutorials/go/">
|
||||
<img
|
||||
alt="Go Logo"
|
||||
src={require("../static/img/logos/golang.svg")}
|
||||
className="circled-logo"
|
||||
/>
|
||||
<h5 className="btn-arrow">{translate("GoLang")}</h5>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col center-image">
|
||||
|
||||
@@ -14,6 +14,7 @@ These client libraries simplify some of the common work of accessing and process
|
||||
| Language | Library Name | Get Started | API Reference | Source Code |
|
||||
|---------------------------------|---------------------------|-------------|--------------|-------------|
|
||||
| **Python** | `xrpl-py` | [Get Started Using Python](../tutorials/python/build-apps/get-started.md) | [API Reference](https://xrpl-py.readthedocs.io/) | [Repo](https://github.com/XRPLF/xrpl-py) |
|
||||
| **Go** | `xrpl-go` | [Get Started Using Go](../tutorials/go/build-apps/get-started.md) | [API Reference](https://pkg.go.dev/github.com/Peersyst/xrpl-go) | [Repo](https://github.com/Peersyst/xrpl-go) |
|
||||
| **JavaScript** / **TypeScript** | `xrpl.js` | [Get Started](../tutorials/javascript/build-apps/get-started.md) | [API Reference](https://js.xrpl.org/) | [Repo](https://github.com/XRPLF/xrpl.js) |
|
||||
| **JavaScript** / **TypeScript** | `xrpl-client` | [Get Started](https://jsfiddle.net/WietseWind/35az6p1b/) | [NPM Reference](https://www.npmjs.com/package/xrpl-client) | [Repo](https://github.com/XRPL-Labs/xrpl-client) |
|
||||
| **JavaScript** / **TypeScript** | `xrpl-accountlib` | [Get Started](https://jsfiddle.net/WietseWind/gkefpnu0/) | [NPM Reference](https://www.npmjs.com/package/xrpl-accountlib) | [Repo](https://github.com/WietseWind/xrpl-accountlib) |
|
||||
|
||||
@@ -16,6 +16,8 @@ Use these libraries to access the XRP Ledger from your programming language of c
|
||||
|
||||
{% xrpl-card title="Python" body="xrpl.py - a pure Python library" href="https://xrpl-py.readthedocs.io/" image="/img/logos/python.svg" imageAlt="Python logo" /%}
|
||||
|
||||
{% xrpl-card title="Go" body="xrpl.go - a pure Go library" href="https://pkg.go.dev/github.com/Peersyst/xrpl-go" image="/img/logos/golang.svg" imageAlt="Go logo" /%}
|
||||
|
||||
{% xrpl-card title="Java" body="xrpl4j - a pure Java library" href="https://javadoc.io/doc/org.xrpl/" image="/img/logos/java.svg" imageAlt="Java logo" /%}
|
||||
|
||||
{% /card-grid %}
|
||||
|
||||
151
docs/tutorials/go/build-apps/get-started.md
Normal file
151
docs/tutorials/go/build-apps/get-started.md
Normal file
@@ -0,0 +1,151 @@
|
||||
---
|
||||
seo:
|
||||
description: Build a Go application that interacts with the XRP Ledger.
|
||||
labels:
|
||||
- Development
|
||||
---
|
||||
|
||||
# Get Started Using Go Library
|
||||
|
||||
This tutorial walks you through the basics of building an XRP Ledger-connected application using [`xrpl-go`](https://github.com/Peersyst/xrpl-go), a pure Go library built to interact with the XRP Ledger.
|
||||
|
||||
This tutorial is intended for beginners and should take no longer than 30 minutes to complete.
|
||||
|
||||
## Learning Goals
|
||||
|
||||
In this tutorial, you'll learn:
|
||||
|
||||
- The basic building blocks of XRP Ledger-based applications.
|
||||
- How to connect to the XRP Ledger using `xrpl-go`.
|
||||
- How to get an account on the [Testnet](/resources/dev-tools/xrp-faucets) using `xrpl-go`.
|
||||
- How to use the `xrpl-go` library to look up information about an account on the XRP Ledger.
|
||||
|
||||
## Requirements
|
||||
|
||||
To follow this tutorial, you should have Go version `1.22.0` or later installed.
|
||||
[Download latest Go version](https://go.dev/dl/).
|
||||
|
||||
## Installation
|
||||
|
||||
The [`xrpl-go` library](https://github.com/Peersyst/xrpl-go) is available on [pkg.go.dev](https://pkg.go.dev/github.com/Peersyst/xrpl-go).
|
||||
|
||||
Start a new project (or use an existing one) and install the `xrpl-go` library via Go modules:
|
||||
|
||||
```bash
|
||||
# Initialize your module (if you haven't already)
|
||||
go mod init your-module-name
|
||||
|
||||
# Fetch the latest version of xrpl-go
|
||||
go get -u github.com/Peersyst/xrpl-go
|
||||
```
|
||||
|
||||
## Start Building
|
||||
|
||||
When you're working with the XRP Ledger, there are a few things you'll need to manage, whether you're adding XRP to your [account](../../../concepts/accounts/index.md), integrating with the [decentralized exchange](../../../concepts/tokens/decentralized-exchange/index.md), or [issuing tokens](../../../concepts/tokens/index.md). This tutorial walks you through basic patterns common to getting started with all of these use cases and provides sample code for implementing them.
|
||||
|
||||
Here are the basic steps you'll need to cover for almost any XRP Ledger project:
|
||||
|
||||
1. [Connect to the XRP Ledger.](#1.-connect-to-the-xrp-ledger)
|
||||
2. [Get an account.](#2.-get-account)
|
||||
3. [Query the XRP Ledger.](#3.-query-the-xrp-ledger)
|
||||
|
||||
### 1. Connect to the XRP Ledger
|
||||
|
||||
To make queries and submit transactions, you need to connect to the XRP Ledger. To do this with `xrpl-go`, you have two main options:
|
||||
|
||||
1. Via WebSocket:
|
||||
|
||||
{% code-snippet file="/_code-samples/get-started/go/base/ws/main.go" from="func main()" language="go" /%}
|
||||
|
||||
2. Via RPC:
|
||||
|
||||
{% code-snippet file="/_code-samples/get-started/go/base/rpc/main.go" from="func main()" language="go" /%}
|
||||
|
||||
#### Connect to the production XRP Ledger
|
||||
|
||||
The sample code in the previous section shows you how to connect to the Testnet, which is a [parallel network](../../../concepts/networks-and-servers/parallel-networks.md) for testing where the money has no real value. When you're ready to integrate with the production XRP Ledger, you'll need to connect to the Mainnet. You can do that in two ways:
|
||||
|
||||
- By [installing the core server](../../../infrastructure/installation/index.md) (`rippled`) and running a node yourself. The core server connects to the Mainnet by default, but you can [change the configuration to use Testnet or Devnet](../../../infrastructure/configuration/connect-your-rippled-to-the-xrp-test-net.md). [There are good reasons to run your own core server](../../../concepts/networks-and-servers/index.md#reasons-to-run-your-own-server). If you run your own server, you can connect to it like so:
|
||||
|
||||
```go
|
||||
import "github.com/Peersyst/xrpl-go/xrpl/websocket"
|
||||
|
||||
const MY_SERVER = "ws://localhost:6006/"
|
||||
|
||||
func main() {
|
||||
client := websocket.NewClient(websocket.NewClientConfig().WithHost(MY_SERVER))
|
||||
|
||||
// ... custom code goes here
|
||||
}
|
||||
```
|
||||
|
||||
See the example [core server config file](https://github.com/XRPLF/rippled/blob/c0a0b79d2d483b318ce1d82e526bd53df83a4a2c/cfg/rippled-example.cfg#L1562) for more information about default values.
|
||||
|
||||
- By using one of the available [public servers][]:
|
||||
|
||||
```go
|
||||
import "github.com/Peersyst/xrpl-go/xrpl/websocket"
|
||||
|
||||
const PUBLIC_SERVER = "wss://xrplcluster.com/"
|
||||
|
||||
func main() {
|
||||
client := websocket.NewClient(websocket.NewClientConfig().WithHost(PUBLIC_SERVER))
|
||||
|
||||
// ... custom code goes here
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Get account
|
||||
|
||||
In `xrpl-go`, account creation and key management live in the `wallet` package, and on Testnet you can use the built-in faucet provider on your WebSocket (or RPC) client to fund a brand-new account immediately.
|
||||
|
||||
On Testnet, you can fund a new ED25519 account like this:
|
||||
|
||||
```go
|
||||
w, err := wallet.New(crypto.ED25519())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := client.FundWallet(&w); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
```
|
||||
|
||||
This constructor returns a Go `Wallet` value with the following fields:
|
||||
|
||||
```go
|
||||
type Wallet struct {
|
||||
PublicKey string // the hex-encoded public key
|
||||
PrivateKey string // the hex-encoded private key
|
||||
ClassicAddress types.Address // the XRPL “r…” address
|
||||
Seed string // the base58 seed
|
||||
}
|
||||
```
|
||||
|
||||
If you already have a seed encoded in [base58][], you can make a `Wallet` instance from it like this:
|
||||
|
||||
```go
|
||||
w, err := wallet.FromSeed("sn3nxiW7v8KXzPzAqzyHXbSSKNuN9", "")
|
||||
```
|
||||
|
||||
### 3. Query the XRP Ledger
|
||||
|
||||
You can query the XRP Ledger to get information about [a specific account](../../../references/http-websocket-apis/public-api-methods/account-methods/index.md), [a specific transaction](../../../references/http-websocket-apis/public-api-methods/transaction-methods/tx.md), the state of a [current or a historical ledger](../../../references/http-websocket-apis/public-api-methods/ledger-methods/index.md), and [the XRP Ledger's decentralized exchange](../../../references/http-websocket-apis/public-api-methods/path-and-order-book-methods/index.md). You need to make these queries, among other reasons, to look up account info to follow best practices for [reliable transaction submission](../../../concepts/transactions/reliable-transaction-submission.md).
|
||||
|
||||
Use the Client's `Request()` method to access the XRP Ledger's [WebSocket API](../../../references/http-websocket-apis/api-conventions/request-formatting.md). For example:
|
||||
|
||||
{% code-snippet file="/_code-samples/get-tx/go/main.go" from="// Get the latest validated ledger" language="go" /%}
|
||||
|
||||
Or, use the getter methods from the [`websocket`](https://pkg.go.dev/github.com/Peersyst/xrpl-go@v0.1.12/xrpl/websocket) or [`rpc`](https://pkg.go.dev/github.com/Peersyst/xrpl-go@v0.1.12/xrpl/rpc) packages:
|
||||
|
||||
{% code-snippet file="/_code-samples/get-started/go/get-acc-info/ws/main.go" from="// Get info from" before="// Get info about" language="go" /%}
|
||||
|
||||
## Keep on Building
|
||||
|
||||
Now that you know how to use `xrpl-go` to connect to the XRP Ledger, get an account, and look up information about it, you can also:
|
||||
|
||||
- [Send XRP](../../how-tos/send-xrp.md).
|
||||
|
||||
{% raw-partial file="/docs/_snippets/common-links.md" /%}
|
||||
10
docs/tutorials/go/build-apps/index.md
Normal file
10
docs/tutorials/go/build-apps/index.md
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
metadata:
|
||||
indexPage: true
|
||||
---
|
||||
|
||||
# Build Applications with Go Library
|
||||
|
||||
Build full-featured applications in Go.
|
||||
|
||||
{% child-pages /%}
|
||||
21
docs/tutorials/go/index.md
Normal file
21
docs/tutorials/go/index.md
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
metadata:
|
||||
indexPage: true
|
||||
---
|
||||
|
||||
# Go
|
||||
|
||||
You can create your own interface to try out the capabilities and support your specific business needs. These tutorials build a test harness interface to try out features of the XRP Ledger.
|
||||
|
||||
Typically, the example functions involve four steps.
|
||||
|
||||
- Connect to the XRP Ledger and instantiate your wallet.
|
||||
- Make changes to the XRP Ledger using transactions.
|
||||
- Get the state of accounts and tokens on the XRP Ledger using requests.
|
||||
- Disconnect from the XRP Ledger.
|
||||
|
||||
Once familiar with the library functions, you can build sample applications in Go. We anticipate that the applications you build greatly improve upon these examples. Your feedback and contributions are most welcome.
|
||||
|
||||
## Tutorial Modules
|
||||
|
||||
{% child-pages /%}
|
||||
@@ -28,7 +28,7 @@ To interact with the XRP Ledger, you need to set up a dev environment with the n
|
||||
- **Python** with the [`xrpl-py` library](https://xrpl-py.readthedocs.io/). See [Get Started using Python](../python/build-apps/get-started.md) for setup steps.
|
||||
- **Java** with the [xrpl4j library](https://github.com/XRPLF/xrpl4j). See [Get Started Using Java](../java/build-apps/get-started.md) for setup steps.
|
||||
- **PHP** with the [XRPL_PHP library](https://github.com/AlexanderBuzz/xrpl-php). See [Get Started Using PHP](../php/build-apps/get-started.md) for setup steps.
|
||||
|
||||
- **Go** with the [xrpl-go library](https://github.com/Peersyst/xrpl-go). See [Get Started Using Go](../go/build-apps/get-started.md) for setup steps.
|
||||
|
||||
## Send a Payment on the Test Net
|
||||
|
||||
@@ -54,6 +54,10 @@ To transact on the XRP Ledger, you need an address and secret key, and some XRP.
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Example credentials" before="// Create" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Go" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/go/ws/main.go" from="// Example credentials" before="// Funding" language="go" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
The secret key shown here is for example only. For development purposes, you can get your own credentials, pre-funded with XRP, on the Testnet using the following interface:
|
||||
@@ -87,6 +91,10 @@ The following code connects to a public Testnet servers:
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Create a client" before="// Transaction definition" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Go" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/go/ws/main.go" from="func main()" before="if !client.IsConnected() " language="go" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
For this tutorial, click the following button to connect:
|
||||
@@ -142,6 +150,10 @@ Here's an example of preparing the above payment:
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Transaction definition" before="// Sign" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Go" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/go/ws/main.go" from="// Prepare " before="// Sign" language="go" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
{% interactive-block label="Prepare" steps=$frontmatter.steps %}
|
||||
@@ -172,6 +184,7 @@ Signing a transaction uses your credentials to authorize the transaction on your
|
||||
- **Python:** Use the [`xrpl.transaction.safe_sign_transaction()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.safe_sign_transaction) with a model and `Wallet` object.
|
||||
- **Java:** Use a [`SignatureService`](https://javadoc.io/doc/org.xrpl/xrpl4j-crypto-core/latest/org/xrpl/xrpl4j/crypto/signing/SignatureService.html) instance to sign the transaction. For this tutorial, use the [`SingleKeySignatureService`](https://javadoc.io/doc/org.xrpl/xrpl4j-crypto-bouncycastle/latest/org/xrpl/xrpl4j/crypto/signing/SingleKeySignatureService.html).
|
||||
- **PHP:** Use a [`sign()` method of a `Wallet` instance](https://alexanderbuzz.github.io/xrpl-php-docs/wallet.html#signing-a-transaction) instance to sign the transaction. The input to this step is a completed array of transaction instructions.
|
||||
- **Go:** Use the [`Sign()` method of the `Wallet` package](https://pkg.go.dev/github.com/Peersyst/xrpl-go@v0.1.12/xrpl/wallet) to sign the transaction.
|
||||
|
||||
{% tabs %}
|
||||
|
||||
@@ -191,6 +204,10 @@ Signing a transaction uses your credentials to authorize the transaction on your
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Sign" before="// Submit" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Go" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/go/ws/main.go" from="// Sign" before="// Submit" language="go" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
The result of the signing operation is a transaction object containing a signature. Typically, XRP Ledger APIs expect a signed transaction to be the hexadecimal representation of the transaction's canonical [binary format](../../references/protocol/binary-format.md), called a "blob".
|
||||
@@ -199,6 +216,7 @@ The result of the signing operation is a transaction object containing a signatu
|
||||
- In `xrpl-py`, you can get the transaction's hash in the response to submitting it in the next step.
|
||||
- In xrpl4j, `SignatureService.sign` returns a `SignedTransaction`, which contains the transaction's hash, which you can use to look up the transaction later.
|
||||
- In `XRPL_PHP`, the signing API also returns the transaction's ID, or identifying hash, which you can use to look up the transaction later. This is a 64-character hexadecimal string that is unique to this transaction.
|
||||
- In `xrpl-go`, the signing API also returns the transaction's ID, or identifying hash, which you can use to look up the transaction later. This is a 64-character hexadecimal string that is unique to this transaction.
|
||||
|
||||
{% interactive-block label="Sign" steps=$frontmatter.steps %}
|
||||
|
||||
@@ -217,6 +235,7 @@ Now that you have a signed transaction, you can submit it to an XRP Ledger serve
|
||||
- **Python:** Use the [`xrpl.transaction.submit_and_wait()` method](https://xrpl-py.readthedocs.io/en/stable/source/xrpl.transaction.html#xrpl.transaction.submit_and_wait) to submit a transaction to the network and wait for a response.
|
||||
- **Java:** Use the [`XrplClient.submit(SignedTransaction)` method](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#submit(org.xrpl.xrpl4j.crypto.signing.SignedTransaction)) to submit a transaction to the network. Use the [`XrplClient.ledger()`](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#ledger(org.xrpl.xrpl4j.model.client.ledger.LedgerRequestParams)) method to get the latest validated ledger index.
|
||||
- **PHP:** Use the [`submitAndWait()` method of the Client](https://alexanderbuzz.github.io/xrpl-php-docs/client.html) to submit a transaction to the network and wait for the response.
|
||||
- **Go:** Use [`SubmitTxAndWait()` or `SubmitTxBlobAndWait()` methods os the Client](https://pkg.go.dev/github.com/Peersyst/xrpl-go@v0.1.12/xrpl/websocket#Client.SubmitTxAndWait) to submit a transaction to the network and wait for the response.
|
||||
|
||||
{% tabs %}
|
||||
|
||||
@@ -236,6 +255,10 @@ Now that you have a signed transaction, you can submit it to an XRP Ledger serve
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Submit" before="// Wait" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Go" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/go/ws/main.go" from="// Submit" before="// Wait" language="go" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
This method returns the **tentative** result of trying to apply the transaction to the open ledger. This result _can_ change when the transaction is included in a validated ledger: transactions that succeed initially might ultimately fail, and transactions that fail initially might ultimately succeed. Still, the tentative result often matches the final result, so it's OK to get excited if you see `tesSUCCESS` here. 😁
|
||||
@@ -273,6 +296,8 @@ Most transactions are accepted into the next ledger version after they're submit
|
||||
|
||||
- **PHP:** If you used the [`.submitAndWait()` method](https://alexanderbuzz.github.io/xrpl-php-docs/client.html), you can wait until the returned Promise resolves. Other, more asynchronous approaches are also possible.
|
||||
|
||||
- **Go:** If you used the `SubmitTxAndWait()` or `SubmitTxBlobAndWait()` methods, the client will handle submission and wait until the transaction is confirmed in a ledger. Internally, these methods use a polling mechanism, querying the transaction status with the client's `Request()` method and a `TxRequest`.
|
||||
|
||||
{% tabs %}
|
||||
|
||||
{% tab label="JavaScript" %}
|
||||
@@ -291,6 +316,10 @@ Most transactions are accepted into the next ledger version after they're submit
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Wait" before="// Check" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Go" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/go/ws/main.go" from="// Wait" before="// Check" language="go" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
{% partial file="/docs/_snippets/interactive-tutorials/wait-step.md" /%}
|
||||
@@ -310,6 +339,8 @@ To know for sure what a transaction did, you must look up the outcome of the tra
|
||||
|
||||
- **PHP:** Use the response from `submitAndWait()` or call the `tx method` using [`$client->syncRequest()`](https://alexanderbuzz.github.io/xrpl-php-docs/client.html).
|
||||
|
||||
- **Go:** Use the response from `SubmitTxAndWait()` or `SubmitTxBlobAndWait()`, or manually query the transaction status using a `TxRequest` with the client's `Request()` method.
|
||||
|
||||
{% tabs %}
|
||||
|
||||
{% tab label="JavaScript" %}
|
||||
@@ -328,6 +359,10 @@ To know for sure what a transaction did, you must look up the outcome of the tra
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Check" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Go" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/go/ws/main.go" from="// Check" language="go" /%}
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
{% admonition type="warning" name="Caution" %}XRP Ledger APIs may return tentative results from ledger versions that have not yet been validated. For example, in [tx method][] response, be sure to look for `"validated": true` to confirm that the data comes from a validated ledger version. Transaction results that are not from a validated ledger version are subject to change. For more information, see [Finality of Results](../../concepts/transactions/finality-of-results/index.md).{% /admonition %}
|
||||
@@ -391,6 +426,16 @@ print_r("Seed: " . $wallet->getSeed()); // Example: sp6JS7f14BuwFY8Mw6bTtLKWauoU
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Go" %}
|
||||
|
||||
```go
|
||||
wallet, err := wallet.New(crypto.ED25519())
|
||||
fmt.Println("Classic Address:", wallet.ClassicAddress) // Example: r9ESeQQswbTxV8neiDTLTHXbXfUwiihyJk
|
||||
fmt.Println("Seed:", wallet.Seed) // Example: sEd7XGFGSWteam777HQHvw7vHypEWy2
|
||||
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
{% admonition type="danger" name="Warning" %}You should only use an address and secret that you generated securely, on your local machine. If another computer generated the address and secret and sent it to you over a network, it's possible that someone else on the network may see that information. If they do, they'll have as much control over your XRP as you do. It's also recommended not to use the same address for the Testnet and Mainnet, because transactions that you created for use on one network could also be valid to execute on the other network, depending on the parameters you provided.{% /admonition %}
|
||||
@@ -433,6 +478,20 @@ $client = new JsonRpcClient("https://xrplcluster.com");
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Go" %}
|
||||
|
||||
```go
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("wss://xrplcluster.com")
|
||||
)
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
If you [install `rippled`](../../infrastructure/installation/index.md) yourself, it connects to the production network by default. (You can also [configure it to connect to the test net](../../infrastructure/configuration/connect-your-rippled-to-the-xrp-test-net.md) instead.) After the server has synced (typically within about 15 minutes of starting it up), you can connect to it locally, which has [various benefits](../../concepts/networks-and-servers/index.md). The following example shows how to connect to a server running the default configuration:
|
||||
@@ -469,6 +528,20 @@ $client = new JsonRpcClient("http://localhost:5005");
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Go" %}
|
||||
|
||||
```go
|
||||
client := websocket.NewClient(
|
||||
websocket.NewClientConfig().
|
||||
WithHost("ws://localhost:6006")
|
||||
)
|
||||
if err := client.Connect(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
{% admonition type="success" name="Tip" %}The local connection uses an unencrypted protocol (`ws` or `http`) rather than the TLS-encrypted version (`wss` or `https`). This is secure only because the communications never leave the same machine, and is easier to set up because it does not require a TLS certificate. For connections on an outside network, always use `wss` or `https`.{% /admonition %}
|
||||
|
||||
@@ -16,7 +16,7 @@ These tutorials walk you through the basics of building a very simple XRP Ledger
|
||||
|
||||
{% xrpl-card title="Python" body="Using xrpl.py, a pure Python library." href="/docs/tutorials/python/" image="/img/logos/python.svg" imageAlt="Python logo" /%}
|
||||
|
||||
<br/>
|
||||
{% xrpl-card title="Go" body="Using xrpl-go, a pure Go library." href="/docs/tutorials/go/" image="/img/logos/golang.svg" imageAlt="Go logo" /%}
|
||||
|
||||
{% xrpl-card title="Java" body="Using xrpl4j, a pure Java library." href="/docs/tutorials/java/" image="/img/logos/java.svg" imageAlt="Java logo" /%}
|
||||
|
||||
|
||||
@@ -247,6 +247,13 @@
|
||||
- page: docs/tutorials/python/compliance/index.md
|
||||
items:
|
||||
- page: docs/tutorials/python/compliance/verify-credential.md
|
||||
- page: docs/tutorials/go/index.md
|
||||
expanded: false
|
||||
items:
|
||||
- page: docs/tutorials/go/build-apps/index.md
|
||||
expanded: false
|
||||
items:
|
||||
- page: docs/tutorials/go/build-apps/get-started.md
|
||||
- page: docs/tutorials/java/index.md
|
||||
expanded: false
|
||||
items:
|
||||
@@ -471,6 +478,9 @@
|
||||
- label: Ruby Client Library
|
||||
href: https://www.rubydoc.info/gems/xrbp
|
||||
external: true
|
||||
- label: Go Client Library
|
||||
href: https://pkg.go.dev/github.com/Peersyst/xrpl-go
|
||||
external: true
|
||||
- page: docs/references/http-websocket-apis/index.md
|
||||
expanded: false
|
||||
items:
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
- page: ./docs/tutorials/python/index.md
|
||||
- page: ./docs/tutorials/java/index.md
|
||||
- page: ./docs/tutorials/php/index.md
|
||||
- page: ./docs/tutorials/go/index.md
|
||||
- page: ./docs/tutorials/http-websocket-apis/index.md
|
||||
|
||||
- group: Resources
|
||||
|
||||
Reference in New Issue
Block a user