| 33 | ) |
| 34 | |
| 35 | func SendBlobTx( |
| 36 | addr string, |
| 37 | to common.Address, |
| 38 | prv string, |
| 39 | data []byte, |
| 40 | needEncoding bool, |
| 41 | nonce int64, |
| 42 | value string, |
| 43 | gasLimit uint64, |
| 44 | gasPrice string, |
| 45 | priorityGasPrice string, |
| 46 | maxFeePerDataGas string, |
| 47 | chainID string, |
| 48 | calldata string, |
| 49 | ) *types.Transaction { |
| 50 | chainId, _ := new(big.Int).SetString(chainID, 0) |
| 51 | |
| 52 | ctx := context.Background() |
| 53 | client, err := ethclient.DialContext(ctx, addr) |
| 54 | if err != nil { |
| 55 | lg.Crit("Failed to connect to the Ethereum client", "error", err) |
| 56 | } |
| 57 | |
| 58 | h := crypto.Keccak256Hash([]byte(`upfrontPayment()`)) |
| 59 | callMsg := ethereum.CallMsg{ |
| 60 | To: &to, |
| 61 | Data: h[:], |
| 62 | } |
| 63 | bs, err := client.CallContract(context.Background(), callMsg, new(big.Int).SetInt64(-2)) |
| 64 | if err != nil { |
| 65 | lg.Crit("Failed to get upfront fee", "error", err) |
| 66 | } |
| 67 | |
| 68 | uint256Type, _ := abi.NewType("uint256", "", nil) |
| 69 | res, err := abi.Arguments{{Type: uint256Type}}.UnpackValues(bs) |
| 70 | if err != nil { |
| 71 | lg.Crit("Failed to unpack values", "error", err) |
| 72 | } |
| 73 | |
| 74 | val, success := new(big.Int).SetString(value, 0) |
| 75 | if !success { |
| 76 | lg.Crit("Invalid value param") |
| 77 | } |
| 78 | |
| 79 | if res[0].(*big.Int).Cmp(val) == 1 { |
| 80 | val = res[0].(*big.Int) |
| 81 | } |
| 82 | |
| 83 | value256, overflow := uint256.FromBig(val) |
| 84 | if overflow { |
| 85 | lg.Crit("Invalid value param", "error", err) |
| 86 | } |
| 87 | |
| 88 | key, err := crypto.HexToECDSA(prv) |
| 89 | if err != nil { |
| 90 | lg.Crit("Invalid private key", "error", err) |
| 91 | } |
| 92 | |