@@ -94,8 +94,8 @@ def self.transfer_multiple_ethscriptions(
9494 from_address :,
9595 to_address :,
9696 ethscription_ids :,
97- source_type : :input ,
98- source_index : 0
97+ source_type :,
98+ source_index :
9999 )
100100 new (
101101 from_address : Address20 . from_hex ( from_address . is_a? ( String ) ? from_address : from_address . to_hex ) ,
@@ -109,16 +109,33 @@ def self.transfer_multiple_ethscriptions(
109109 )
110110 end
111111
112+ # Get function selector for this operation
113+ def function_selector
114+ function_signature = case ethscription_operation
115+ when 'create'
116+ 'createEthscription((bytes32,bytes32,address,bytes,string,string,string,bool,(string,string,string,uint256,uint256,uint256)))'
117+ when 'transfer'
118+ if transfer_ids && transfer_ids . any?
119+ 'transferMultipleEthscriptions(bytes32[],address)'
120+ else
121+ 'transferEthscription(address,bytes32)'
122+ end
123+ when 'transfer_with_previous_owner'
124+ 'transferEthscriptionForPreviousOwner(address,bytes32,address)'
125+ else
126+ raise "Unknown ethscription operation: #{ ethscription_operation } "
127+ end
128+
129+ Eth ::Util . keccak256 ( function_signature ) [ 0 ...4 ]
130+ end
131+
112132 # Unified source hash computation following Optimism pattern
113133 def compute_source_hash ( operation_source , index )
114134 raise "Operation must have source metadata" if operation_source . nil? || index . nil?
115135
116136 source_tag = operation_source . to_s # "input" or "event"
117137 source_tag_hash = Eth ::Util . keccak256 ( source_tag . bytes . pack ( 'C*' ) ) # Hash for constant width
118138
119- # Get function selector from input for operation type safety
120- function_selector = input . to_bin [ 0 ...4 ]
121-
122139 payload = ByteString . from_bin (
123140 eth_transaction . block_hash . to_bin +
124141 source_tag_hash + # 32 bytes (hashed source tag)
@@ -202,9 +219,7 @@ def to_deposit_payload
202219 # Build calldata for create operations (same for both input and event-based)
203220 def build_create_calldata
204221 # Get function selector as binary
205- function_sig = Eth ::Util . keccak256 (
206- 'createEthscription((bytes32,bytes32,address,bytes,string,string,string,bool,(string,string,string,uint256,uint256,uint256)))'
207- ) [ 0 ...4 ] . b
222+ function_sig = function_selector . b
208223
209224 # Both input and event-based creates use data URI format
210225 # Events are "equivalent of an EOA hex-encoding contentURI and putting it in the calldata"
@@ -248,7 +263,7 @@ def build_create_calldata
248263
249264 def build_transfer_calldata
250265 # Get function selector as binary
251- function_sig = Eth :: Util . keccak256 ( 'transferEthscription(address,bytes32)' ) [ 0 ... 4 ] . b
266+ function_sig = function_selector . b
252267
253268 # Convert to binary for ABI
254269 to_bin = address_to_bin ( transfer_to_address )
@@ -262,9 +277,7 @@ def build_transfer_calldata
262277
263278 def build_transfer_with_previous_owner_calldata
264279 # Get function selector as binary
265- function_sig = Eth ::Util . keccak256 (
266- 'transferEthscriptionForPreviousOwner(address,bytes32,address)'
267- ) [ 0 ...4 ] . b
280+ function_sig = function_selector . b
268281
269282 # Convert to binary for ABI
270283 to_bin = address_to_bin ( transfer_to_address )
@@ -279,7 +292,7 @@ def build_transfer_with_previous_owner_calldata
279292
280293 def build_transfer_multiple_calldata
281294 # Get function selector as binary
282- function_sig = Eth :: Util . keccak256 ( 'transferMultipleEthscriptions(bytes32[],address)' ) [ 0 ... 4 ] . b
295+ function_sig = function_selector . b
283296
284297 ids_bin = ( transfer_ids || [ ] ) . map { |id | hex_to_bin ( id ) }
285298 to_bin = address_to_bin ( transfer_to_address )
0 commit comments