Improve naming
This commit is contained in:
parent
3d58df10e8
commit
b124787015
|
@ -12,12 +12,12 @@ type InstructionDecoder func(instructionAccounts []*AccountMeta, data []byte) (i
|
|||
var InstructionDecoderRegistry = map[string]InstructionDecoder{}
|
||||
|
||||
func RegisterInstructionDecoder(programID PublicKey, decoder InstructionDecoder) {
|
||||
p := programID.String()
|
||||
if _, found := InstructionDecoderRegistry[p]; found {
|
||||
panic(fmt.Sprintf("unable to re-register instruction decoder for program %q", p))
|
||||
pid := programID.String()
|
||||
if _, found := InstructionDecoderRegistry[pid]; found {
|
||||
panic(fmt.Sprintf("unable to re-register instruction decoder for program %q", pid))
|
||||
}
|
||||
|
||||
InstructionDecoderRegistry[p] = decoder
|
||||
InstructionDecoderRegistry[pid] = decoder
|
||||
}
|
||||
|
||||
func DecodeInstruction(programID PublicKey, accounts []*AccountMeta, data []byte) (interface{}, error) {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/gagliardetto/solana-go/rpc/ws"
|
||||
)
|
||||
|
||||
func (cl *Client) SendAndConfirmTransactionWithOpts(
|
||||
ctx context.Context,
|
||||
transaction *solana.Transaction,
|
||||
skipPreflight bool, // if true, skip the preflight transaction checks (default: false)
|
||||
preflightCommitment CommitmentType, // optional; Commitment level to use for preflight (default: "finalized").
|
||||
) (signature solana.Signature, err error) {
|
||||
|
||||
sig, err := cl.SendTransactionWithOpts(
|
||||
ctx,
|
||||
transaction,
|
||||
skipPreflight,
|
||||
preflightCommitment,
|
||||
)
|
||||
if err != nil {
|
||||
return sig, err
|
||||
}
|
||||
|
||||
client, err := ws.Connect(context.Background(), TestNet_WS)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
txSig := solana.MustSignatureFromBase58("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
|
||||
|
||||
sub, err := client.SignatureSubscribe(
|
||||
txSig,
|
||||
"",
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer sub.Unsubscribe()
|
||||
|
||||
for {
|
||||
got, err := sub.Recv()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
spew.Dump(got)
|
||||
}
|
||||
return
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package sendandconfirmtransaction
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/gagliardetto/solana-go/rpc"
|
||||
"github.com/gagliardetto/solana-go/rpc/ws"
|
||||
)
|
||||
|
||||
func SendAndConfirmTransactionWithOpts(
|
||||
ctx context.Context,
|
||||
rpcClient *rpc.Client,
|
||||
wsClient *ws.Client,
|
||||
transaction *solana.Transaction,
|
||||
skipPreflight bool, // if true, skip the preflight transaction checks (default: false)
|
||||
preflightCommitment rpc.CommitmentType, // optional; Commitment level to use for preflight (default: "finalized").
|
||||
) (signature solana.Signature, err error) {
|
||||
|
||||
sig, err := rpcClient.SendTransactionWithOpts(
|
||||
ctx,
|
||||
transaction,
|
||||
skipPreflight,
|
||||
preflightCommitment,
|
||||
)
|
||||
if err != nil {
|
||||
return sig, err
|
||||
}
|
||||
|
||||
sub, err := wsClient.SignatureSubscribe(
|
||||
sig,
|
||||
rpc.CommitmentConfirmed,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer sub.Unsubscribe()
|
||||
|
||||
for {
|
||||
got, err := sub.Recv()
|
||||
if err != nil {
|
||||
return sig, err
|
||||
}
|
||||
spew.Dump(got)
|
||||
if got.Value.Err != nil {
|
||||
return sig, fmt.Errorf("confirmation error: %v", got.Value.Err)
|
||||
} else {
|
||||
return sig, nil
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue