Skip to content

Commit 3594225

Browse files
extension: expose generation of management contract uuid to allow external signing of approval request (#1613)
* extension: expose generation of management contract uuid to allow external signing of approval request * extension: external signer address required for validation before generating uuid
1 parent b7476db commit 3594225

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

extension/api.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,62 @@ func (api *PrivateExtensionAPI) doMultiTenantChecks(ctx context.Context, address
127127
return nil
128128
}
129129

130+
// GenerateExtensionApprovalUuid generates a uuid to be used for contract state extension approval when calling doVote within the management contract,
131+
// allowing the approval method to be called with an external signer
132+
func (api *PrivateExtensionAPI) GenerateExtensionApprovalUuid(ctx context.Context, addressToVoteOn common.Address, externalSignerAddress common.Address, txa ethapi.SendTxArgs) (string, error) {
133+
err := api.doMultiTenantChecks(ctx, txa.From, txa)
134+
if err != nil {
135+
return "", err
136+
}
137+
138+
psm, err := api.privacyService.apiBackendHelper.PSMR().ResolveForUserContext(ctx)
139+
if err != nil {
140+
return "", err
141+
}
142+
psi := psm.ID
143+
144+
// check if the extension has been completed. if yes
145+
// no acceptance required
146+
status, err := api.checkIfExtensionComplete(addressToVoteOn, externalSignerAddress, psi)
147+
if err != nil {
148+
return "", err
149+
}
150+
151+
if status {
152+
return "", errors.New("contract extension process complete. nothing to accept")
153+
}
154+
155+
// get all participants for the contract being extended
156+
participants, err := api.privacyService.GetAllParticipants(api.privacyService.stateFetcher.getCurrentBlockHash(), addressToVoteOn, psi)
157+
if err == nil {
158+
txa.PrivateFor = append(txa.PrivateFor, participants...)
159+
}
160+
161+
txArgs, err := api.privacyService.GenerateTransactOptions(txa)
162+
if err != nil {
163+
return "", err
164+
}
165+
166+
psiManagementContractClient := api.privacyService.managementContract(psi)
167+
defer psiManagementContractClient.Close()
168+
voterList, err := psiManagementContractClient.GetAllVoters(addressToVoteOn)
169+
if err != nil {
170+
return "", err
171+
}
172+
if isVoter := checkAddressInList(externalSignerAddress, voterList); !isVoter {
173+
return "", errNotAcceptor
174+
}
175+
176+
if api.checkAlreadyVoted(addressToVoteOn, externalSignerAddress, psi) {
177+
return "", errors.New("already voted")
178+
}
179+
uuid, err := generateUuid(addressToVoteOn, txArgs.PrivateFrom, txArgs.PrivateFor, api.privacyService.ptm)
180+
if err != nil {
181+
return "", err
182+
}
183+
return uuid, nil
184+
}
185+
130186
// ApproveContractExtension submits the vote to the specified extension management contract. The vote indicates whether to extend
131187
// a given contract to a new participant or not
132188
func (api *PrivateExtensionAPI) ApproveExtension(ctx context.Context, addressToVoteOn common.Address, vote bool, txa ethapi.SendTxArgs) (string, error) {

extension/proxy_api.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ func (api *PrivateExtensionProxyAPI) ActiveExtensionContracts(ctx context.Contex
4545
return extracted
4646
}
4747

48+
func (api *PrivateExtensionProxyAPI) GenerateExtensionApprovalUuid(ctx context.Context, addressToVoteOn common.Address, externalSignerAddress common.Address, txa ethapi.SendTxArgs) (string, error) {
49+
log.Info("QLight - proxy enabled")
50+
var result string
51+
err := api.proxyClient.CallContext(ctx, &result, "quorumExtension_generateExtensionApprovalUuid", addressToVoteOn, externalSignerAddress, txa)
52+
return result, err
53+
}
54+
4855
// ApproveContractExtension submits the vote to the specified extension management contract. The vote indicates whether to extend
4956
// a given contract to a new participant or not
5057
func (api *PrivateExtensionProxyAPI) ApproveExtension(ctx context.Context, addressToVoteOn common.Address, vote bool, txa ethapi.SendTxArgs) (string, error) {

internal/web3ext/web3ext.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,12 @@ web3._extend({
12511251
property: 'quorumExtension',
12521252
methods:
12531253
[
1254+
new web3._extend.Method({
1255+
name: 'generateExtensionApprovalUuid',
1256+
call: 'quorumExtension_generateExtensionApprovalUuid',
1257+
params: 2,
1258+
inputFormatter: [web3._extend.formatters.inputAddressFormatter, web3._extend.formatters.inputAddressFormatter, web3._extend.formatters.inputTransactionFormatter]
1259+
}),
12541260
new web3._extend.Method({
12551261
name: 'approveExtension',
12561262
call: 'quorumExtension_approveExtension',

0 commit comments

Comments
 (0)