-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsend_tx.go
58 lines (46 loc) · 2.18 KB
/
send_tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package bloxroute_sdk_go
import (
"context"
"encoding/json"
"fmt"
bxgateway "github.com/bloXroute-Labs/gateway/v2"
"github.com/bloXroute-Labs/gateway/v2/jsonrpc"
)
// SendTxParams are the parameters for sending transactions faster with
// bloxroute & configuring semi-private transactions
type SendTxParams struct {
// The hex-encoded bytes of the transaction (without 0x prefix)
Transaction string `json:"transaction"`
// BlockchainNetwork is the blockchain network to subscribe to.
// Optional (defaults to "Mainnet")
BlockchainNetwork string `json:"blockchain_network,omitempty"`
// A boolean flag indicating if Tx Nonce Monitoring should be
// enabled for the transaction.
NonceMonitoring bool `json:"nonce_monitoring,omitempty"`
// A boolean flag used to send the transaction only to validators
// accessible via the BDN. Available only for Ethereum, BSC & Polygon
ValidatorsOnly bool `json:"validators_only,omitempty"`
// A boolean flag used to send the transaction only to the validators
// that are next-in-turn, if they are accessible via the BDN. Available
// only for BSC & Polygon
NextValidator bool `json:"next_validator,omitempty"`
// When using next_validator, fall_back is the duration of time (in ms)
// that your transaction will be delayed before propagation by the
// BDN as a normal transaction. Default is 0, which indicates no fallback.
Fallback uint `json:"fallback,omitempty"`
// A boolean flag indicating if the transaction should be validated by the
// connected blockchain node via the Gateway. Default is false.
NodeValidation bool `json:"node_validation,omitempty"`
}
// SendTx sends a single transaction faster than the p2p network using the BDN
func (c *Client) SendTx(ctx context.Context, params *SendTxParams) (*json.RawMessage, error) {
// set blockchain network to match the config if not set
if params.BlockchainNetwork == "" {
params.BlockchainNetwork = c.blockchainNetwork
}
// error if the user is using mainnet and next validator
if params.BlockchainNetwork == bxgateway.Mainnet && params.NextValidator {
return nil, fmt.Errorf("NextValidator is not supported on Ethereum Mainnet")
}
return c.handler.Request(ctx, jsonrpc.RPCTx, params)
}