|
3 | 3 | getOrCreateStateChannelBetweenVirtualAppParticipants |
4 | 4 | } from "../methods/app-instance/propose-install-virtual/operation"; |
5 | 5 | import { NO_APP_INSTANCE_ID_TO_INSTALL } from "../methods/errors"; |
| 6 | +import { executeFunctionWithinQueues } from "../methods/queued-execution"; |
6 | 7 | import { AppInstanceProposal } from "../models"; |
7 | 8 | import { RequestHandler } from "../request-handler"; |
8 | 9 | import { |
@@ -74,24 +75,29 @@ export async function handleReceivedProposalMessage( |
74 | 75 | networkContext.MinimumViableMultisig |
75 | 76 | ); |
76 | 77 |
|
77 | | - const stateChannel = await store.getStateChannel(multisigAddress); |
78 | | - |
79 | | - await store.addAppInstanceProposal( |
80 | | - stateChannel, |
81 | | - new AppInstanceProposal( |
82 | | - { |
83 | | - ...params, |
84 | | - proposedByIdentifier, |
85 | | - initiatorDeposit: params.responderDeposit, |
86 | | - initiatorDepositTokenAddress: params.responderDepositTokenAddress!, |
87 | | - responderDeposit: params.initiatorDeposit!, |
88 | | - responderDepositTokenAddress: params.initiatorDepositTokenAddress! |
89 | | - }, |
90 | | - stateChannel |
91 | | - ) |
| 78 | + await executeFunctionWithinQueues( |
| 79 | + [await requestHandler.getShardedQueue(multisigAddress)], |
| 80 | + async () => { |
| 81 | + const stateChannel = await store.getStateChannel(multisigAddress); |
| 82 | + |
| 83 | + await store.addAppInstanceProposal( |
| 84 | + stateChannel, |
| 85 | + new AppInstanceProposal( |
| 86 | + { |
| 87 | + ...params, |
| 88 | + proposedByIdentifier, |
| 89 | + initiatorDeposit: params.responderDeposit, |
| 90 | + initiatorDepositTokenAddress: params.responderDepositTokenAddress!, |
| 91 | + responderDeposit: params.initiatorDeposit!, |
| 92 | + responderDepositTokenAddress: params.initiatorDepositTokenAddress! |
| 93 | + }, |
| 94 | + stateChannel |
| 95 | + ) |
| 96 | + ); |
| 97 | + |
| 98 | + await store.saveStateChannel(stateChannel.bumpProposedApps()); |
| 99 | + } |
92 | 100 | ); |
93 | | - |
94 | | - await store.saveStateChannel(stateChannel.bumpProposedApps()); |
95 | 101 | } |
96 | 102 |
|
97 | 103 | export async function handleRejectProposalMessage( |
@@ -144,28 +150,40 @@ export async function handleReceivedProposeVirtualMessage( |
144 | 150 | } as ProposeVirtualMessage |
145 | 151 | ); |
146 | 152 | } else { |
147 | | - const stateChannel = await getOrCreateStateChannelBetweenVirtualAppParticipants( |
148 | | - proposedByIdentifier, |
149 | | - publicIdentifier, |
150 | | - intermediaryIdentifier, |
151 | | - store, |
152 | | - networkContext |
| 153 | + const multisigAddress = getCreate2MultisigAddress( |
| 154 | + [proposedByIdentifier, proposedToIdentifier], |
| 155 | + networkContext.ProxyFactory, |
| 156 | + networkContext.MinimumViableMultisig |
153 | 157 | ); |
154 | 158 |
|
155 | | - const proposal = new AppInstanceProposal( |
156 | | - { |
157 | | - ...params, |
158 | | - proposedByIdentifier, |
159 | | - initiatorDeposit: responderDeposit, |
160 | | - initiatorDepositTokenAddress: responderDepositTokenAddress!, |
161 | | - responderDeposit: initiatorDeposit, |
162 | | - responderDepositTokenAddress: initiatorDepositTokenAddress! |
163 | | - }, |
164 | | - stateChannel |
| 159 | + await executeFunctionWithinQueues( |
| 160 | + [await requestHandler.getShardedQueue(multisigAddress)], |
| 161 | + async () => { |
| 162 | + const stateChannel = await getOrCreateStateChannelBetweenVirtualAppParticipants( |
| 163 | + multisigAddress, |
| 164 | + proposedByIdentifier, |
| 165 | + proposedToIdentifier, |
| 166 | + intermediaryIdentifier, |
| 167 | + store, |
| 168 | + networkContext |
| 169 | + ); |
| 170 | + |
| 171 | + await store.addVirtualAppInstanceProposal( |
| 172 | + new AppInstanceProposal( |
| 173 | + { |
| 174 | + ...params, |
| 175 | + proposedByIdentifier, |
| 176 | + initiatorDeposit: responderDeposit, |
| 177 | + initiatorDepositTokenAddress: responderDepositTokenAddress!, |
| 178 | + responderDeposit: initiatorDeposit, |
| 179 | + responderDepositTokenAddress: initiatorDepositTokenAddress! |
| 180 | + }, |
| 181 | + stateChannel |
| 182 | + ) |
| 183 | + ); |
| 184 | + |
| 185 | + await store.saveStateChannel(stateChannel.bumpProposedApps()); |
| 186 | + } |
165 | 187 | ); |
166 | | - |
167 | | - await store.addVirtualAppInstanceProposal(proposal); |
168 | | - |
169 | | - await store.saveStateChannel(stateChannel.bumpProposedApps()); |
170 | 188 | } |
171 | 189 | } |
0 commit comments