From 530513726c367edbc8bbd4093c337ba070acba98 Mon Sep 17 00:00:00 2001 From: siddharth0a Date: Sat, 6 Apr 2024 12:25:15 +0900 Subject: [PATCH] EIPs: add transact method EIP-1559.md --- EIPs/eip-1559.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/EIPs/eip-1559.md b/EIPs/eip-1559.md index b6edfb522b..e2ac939e4e 100644 --- a/EIPs/eip-1559.md +++ b/EIPs/eip-1559.md @@ -453,6 +453,62 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { } ``` +transact는 실제 트랜잭션 호출을 실행하고, 누락된 authorization 필드를 도출한 다음 트랜잭션을 실행하도록 스케줄링합니다. + +```go +// transact executes an actual transaction invocation, first deriving any missing +// authorization fields, and then scheduling the transaction for execution. +// transact는 실제 트랜잭션 호출을 실행하고, 먼저 누락된 authorization 필드를 도출한 다음 트랜잭션을 실행하도록 스케줄링합니다. +func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, input []byte) (*types.Transaction, error) { + if opts.GasPrice != nil && (opts.GasFeeCap != nil || opts.GasTipCap != nil) { + // 트랜잭션은 GasPrice 혹은 (GasFeeCap or GasTipCap) 중 하나는 지정되어 있어야 합니다. + return nil, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified") + } + // Create the transaction + var ( + rawTx *types.Transaction + err error + ) + if opts.GasPrice != nil { + // GasPrice가 설정되어 있으면 legacy transaction 실행을 실행합니다. + rawTx, err = c.createLegacyTx(opts, contract, input) + } else if opts.GasFeeCap != nil && opts.GasTipCap != nil { + // GasFeeCap, GasTipCap 모두 설정되어 있으면 EIP-1559 transaction을 실행합니다. + rawTx, err = c.createDynamicTx(opts, contract, input, nil) + } else { + // Only query for basefee if gasPrice not specified + // gasPrice가 지정되지 않으면 baseFee만 쿼리하고, baseFee 존재시 EIP-1559 transaction, 없으면 legacy transaction을 실행합니다. + // 사용자가 명시적으로 가스 관련한 field를 지정하지 않았을때 네트워크 config에 맞게 자동으로 트랜잭션 유형을 결정하기 위한 조건입니다. + if head, errHead := c.transactor.HeaderByNumber(ensureContext(opts.Context), nil); errHead != nil { + return nil, errHead + } else if head.BaseFee != nil { + rawTx, err = c.createDynamicTx(opts, contract, input, head) + } else { + // Chain is not London ready -> use legacy transaction + rawTx, err = c.createLegacyTx(opts, contract, input) + } + } + if err != nil { + return nil, err + } + // Sign the transaction and schedule it for execution + if opts.Signer == nil { + return nil, errors.New("no signer to authorize the transaction with") + } + signedTx, err := opts.Signer(opts.From, rawTx) + if err != nil { + return nil, err + } + if opts.NoSend { + return signedTx, nil + } + if err := c.transactor.SendTransaction(ensureContext(opts.Context), signedTx); err != nil { + return nil, err + } + return signedTx, nil +} +``` + ## Reference https://eips.ethereum.org/EIPS/eip-1559