@@ -101,20 +101,31 @@ defmodule FileonchainWeb.FileLive.FormComponent do
101
101
chunks_results =
102
102
Enum . map ( chunks , fn chunk ->
103
103
hash = Blake3 . hash ( chunk ) |> Base . encode16 ( case: :lower )
104
- Fileonchain.Chunks . create_chunk ( % { hash: hash , cid: "dummy_cid" , data: chunk } )
104
+ case Fileonchain.Chunks . create_chunk ( % { hash: hash , cid: "dummy_cid" , data: chunk } ) do
105
+ { :ok , _chunk } ->
106
+ # Send remark transaction
107
+ sender_seed = System . get_env ( "POLKADOT_SENDER_SEED" ) || "//Alice"
108
+ { tx_hash , exit_code } = System . cmd ( "node" , [ "dist/sendRemark.js" , sender_seed , hash ] )
109
+ if exit_code == 0 do
110
+ { :ok , String . trim ( tx_hash ) }
111
+ else
112
+ { :error , "Failed to send remark: #{ String . trim ( tx_hash ) } " }
113
+ end
114
+ error -> error
115
+ end
105
116
end )
106
117
107
118
if Enum . all? ( chunks_results , fn { :ok , _ } -> true ; _ -> false end ) do
108
119
notify_parent ( { :saved , file } )
109
120
110
121
{ :noreply ,
111
122
socket
112
- |> put_flash ( :info , "File and Chunks created successfully" )
123
+ |> put_flash ( :info , "File and Chunks created successfully, remarks sent to Polkadot " )
113
124
|> push_patch ( to: socket . assigns . patch ) }
114
125
else
115
126
{ :noreply ,
116
127
socket
117
- |> put_flash ( :error , "File created but failed to create some Chunks" )
128
+ |> put_flash ( :error , "File created but failed to create some Chunks or send remarks " )
118
129
|> push_patch ( to: socket . assigns . patch ) }
119
130
end
120
131
0 commit comments