Skip to content

Commit 85db8bf

Browse files
committed
feat: initial svm txbuilder
1 parent a283651 commit 85db8bf

File tree

5 files changed

+738
-1
lines changed

5 files changed

+738
-1
lines changed

universalClient/chains/chains.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (c *Chains) addChain(ctx context.Context, cfg *uregistrytypes.ChainConfig)
274274
case uregistrytypes.VmType_EVM:
275275
client, err = evm.NewClient(cfg, chainDB, chainConfig, c.pushSigner, c.logger)
276276
case uregistrytypes.VmType_SVM:
277-
client, err = svm.NewClient(cfg, chainDB, chainConfig, c.pushSigner, c.logger)
277+
client, err = svm.NewClient(cfg, chainDB, chainConfig, c.pushSigner, c.config.NodeHome, c.logger)
278278
default:
279279
return fmt.Errorf("unsupported VM type: %v", cfg.VmType)
280280
}

universalClient/chains/svm/client.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ type Client struct {
3535
eventProcessor *common.EventProcessor
3636
eventConfirmer *EventConfirmer
3737
gasOracle *GasOracle
38+
txBuilder *TxBuilder
3839

3940
// Dependencies
4041
pushSigner *pushsigner.Signer
42+
nodeHome string
4143
}
4244

4345
// NewClient creates a new Solana chain client
@@ -46,6 +48,7 @@ func NewClient(
4648
database *db.DB,
4749
chainConfig *config.ChainSpecificConfig,
4850
pushSigner *pushsigner.Signer,
51+
nodeHome string,
4952
logger zerolog.Logger,
5053
) (*Client, error) {
5154
if config == nil {
@@ -78,6 +81,7 @@ func NewClient(
7881
chainConfig: chainConfig,
7982
database: database,
8083
pushSigner: pushSigner,
84+
nodeHome: nodeHome,
8185
}
8286

8387
// Initialize components that don't require RPC client
@@ -179,6 +183,14 @@ func (c *Client) GetConfig() *uregistrytypes.ChainConfig {
179183
return c.registryConfig
180184
}
181185

186+
// GetTxBuilder returns the OutboundTxBuilder for this chain
187+
func (c *Client) GetTxBuilder() (common.OutboundTxBuilder, error) {
188+
if c.txBuilder == nil {
189+
return nil, fmt.Errorf("txBuilder not available for chain %s (gateway not configured)", c.chainIDStr)
190+
}
191+
return c.txBuilder, nil
192+
}
193+
182194
// initializeComponents creates all components that require the RPC client
183195
func (c *Client) initializeComponents() error {
184196
// Create event listener if gateway is configured
@@ -235,6 +247,21 @@ func (c *Client) initializeComponents() error {
235247
)
236248
}
237249

250+
// Create txBuilder if gateway is configured
251+
if c.registryConfig != nil && c.registryConfig.GatewayAddress != "" {
252+
txBuilder, err := NewTxBuilder(
253+
c.rpcClient,
254+
c.chainIDStr,
255+
c.registryConfig.GatewayAddress,
256+
c.nodeHome,
257+
c.logger,
258+
)
259+
if err != nil {
260+
return fmt.Errorf("failed to create txBuilder: %w", err)
261+
}
262+
c.txBuilder = txBuilder
263+
}
264+
238265
return nil
239266
}
240267

universalClient/chains/svm/rpc_client.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,23 @@ func (rc *RPCClient) BroadcastTransaction(ctx context.Context, tx *solana.Transa
296296
return txHash, err
297297
}
298298

299+
// GetAccountData fetches account data for a given public key
300+
func (rc *RPCClient) GetAccountData(ctx context.Context, pubkey solana.PublicKey) ([]byte, error) {
301+
var accountData []byte
302+
err := rc.executeWithFailover(ctx, "get_account_data", func(client *rpc.Client) error {
303+
accountInfo, innerErr := client.GetAccountInfo(ctx, pubkey)
304+
if innerErr != nil {
305+
return innerErr
306+
}
307+
if accountInfo.Value == nil {
308+
return fmt.Errorf("account not found: %s", pubkey.String())
309+
}
310+
accountData = accountInfo.Value.Data.GetBinary()
311+
return nil
312+
})
313+
return accountData, err
314+
}
315+
299316
// Close closes all RPC connections
300317
func (rc *RPCClient) Close() {
301318
rc.mu.Lock()

0 commit comments

Comments
 (0)