Files
sdk/contract/blockchain_tx.go
zeekay 1db81a7b50 Ask the node for addresses and names it serves
Three drifts, none of which failed to compile and none of which failed a
test, because a JSON-RPC address and a JSON-RPC method name are strings.

The prefix. The node serves /v1 and nothing else — "the legacy /ext
prefix is gone", server/http/server.go — and twelve places here spelled
/ext. Every P-chain and X-chain call in this SDK was a 404.

The service. vms/xvm/vm.go registers the X-chain under "xvm". Eleven
methods here said "exchangevm", while buildGenesis in the same package
said "xvm" — the disagreement was already visible in the source.

The field. vms/platformvm/service.go reads netID; eleven types here sent
and read chainID. This one does not even fail: the node finds no netID,
leaves the id empty, and an empty id is the primary network, so asking an
L1 for its validators quietly answers with the wrong set.

The prefix drift is the one worth naming, because twelve copies is what
made it twelve bugs. constants.Route is now the one place this SDK
composes a node address, and Chain reads ChainAliasPrefix rather than
spelling the segment, because that segment MOVED — it was "bc" and is
"chain", and the node serves both only until its callers have rolled.

exchangevm had no tests at all. It has one now, and it is about the two
things that were wrong: the name on the wire and the path it goes to.
2026-08-29 14:36:00 -07:00

56 lines
1.4 KiB
Go

// Copyright (C) 2025, Lux Industries Inc All rights reserved.
// See the file LICENSE for licensing terms.
package contract
import (
"fmt"
"github.com/luxfi/sdk/constants"
"github.com/luxfi/formatting"
"github.com/luxfi/ids"
"github.com/luxfi/proto/p/txs"
"github.com/luxfi/rpc"
)
type getTxArgs struct {
TxID ids.ID `json:"txID"`
Encoding formatting.Encoding `json:"encoding"`
}
type formattedTx struct {
Tx string `json:"tx"`
Encoding formatting.Encoding `json:"encoding"`
}
// GetBlockchainTx retrieves a blockchain CreateChainTx from the network.
func GetBlockchainTx(endpoint string, blockchainID ids.ID) (*txs.CreateChainTx, error) {
requester := rpc.NewEndpointRequester(constants.Chain(endpoint, "P"))
ctx, cancel := apiRequestContext()
defer cancel()
reply := &formattedTx{}
if err := requester.SendRequest(ctx, "platform.getTx", &getTxArgs{
TxID: blockchainID,
Encoding: formatting.Hex,
}, reply); err != nil {
return nil, err
}
txBytes, err := formatting.Decode(reply.Encoding, reply.Tx)
if err != nil {
return nil, err
}
// The tx decodes itself from its own ZAP wire bytes.
tx, err := txs.Parse(txBytes)
if err != nil {
return nil, fmt.Errorf("failed parsing the createChainTx: %w", err)
}
createChainTx, ok := tx.Unsigned.(*txs.CreateChainTx)
if !ok {
return nil, fmt.Errorf("expected a CreateChainTx, got %T", tx.Unsigned)
}
return createChainTx, nil
}