Skip to content

Commit

Permalink
WIP: add function to generate soroban config upgrade transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Dec 10, 2024
1 parent 0130091 commit defe84f
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions clients/stellarcore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"io"
"net/http"
"net/url"
"os/exec"
"path"
"strconv"
"strings"
"time"

"github.com/stellar/go/keypair"
proto "github.com/stellar/go/protocols/stellarcore"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
Expand Down Expand Up @@ -80,6 +82,56 @@ func (c *Client) UpgradeSorobanConfig(ctx context.Context, configKey xdr.ConfigU
return c.setUpgradesAt(ctx, at, queryParams)
}

type GenSorobanConfig struct {
BaseSeqNum uint32
NetworkPassphrase string
// TODO: Should we ask core to sign the tx or should we do it ourselves?
SigningKey keypair.Full
// looks for `stellar-core` in the system PATH if empty
StellarCorePath string
}

func GenSorobanConfigUpgradeTxAndKey(
config GenSorobanConfig, upgradeConfig xdr.ConfigUpgradeSet) ([]xdr.TransactionEnvelope, xdr.ConfigUpgradeSetKey, error) {
upgradeConfigB64, err := xdr.MarshalBase64(upgradeConfig)
if err != nil {
return nil, xdr.ConfigUpgradeSetKey{}, err
}
corePath := config.StellarCorePath
if corePath == "" {
corePath = "stellar-core"
}
cmd := exec.Command(corePath, "get-settings-upgrade-txs",
config.SigningKey.Address(),
strconv.FormatUint(uint64(config.BaseSeqNum), 10),
config.NetworkPassphrase,
"--xdr", upgradeConfigB64,
"--signtxs")
inputStr := config.SigningKey.Seed()
cmd.Stdin = strings.NewReader(inputStr)
out, err := cmd.CombinedOutput()
if err != nil {
return nil, xdr.ConfigUpgradeSetKey{}, err
}
fields := strings.Fields(string(out))
if len(fields) < 4 {
return nil, xdr.ConfigUpgradeSetKey{}, fmt.Errorf("get-settings-upgrade-txs: unexpected output: %q", string(out))
}
txsB64 := fields[0:3]
keyB64 := fields[3]

txs := make([]xdr.TransactionEnvelope, len(txsB64))
for i, txB64 := range txsB64 {
err := xdr.SafeUnmarshalBase64(txB64, &txs[i])

Check failure on line 125 in clients/stellarcore/client.go

View workflow job for this annotation

GitHub Actions / check (ubuntu-22.04, 1.22.1)

declaration of "err" shadows declaration at line 96
if err != nil {
return nil, xdr.ConfigUpgradeSetKey{}, err
}
}
var key xdr.ConfigUpgradeSetKey
err = xdr.SafeUnmarshalBase64(keyB64, &key)
return txs, key, err
}

// UpgradeTxSetSize upgrades the maximum number of transactions per ledger
func (c *Client) UpgradeTxSetSize(ctx context.Context, maxTxSetSize uint32, at time.Time) error {
queryParams := url.Values{}
Expand Down

0 comments on commit defe84f

Please sign in to comment.