Skip to content

Commit

Permalink
extension: expose generation of management contract uuid to allow ext…
Browse files Browse the repository at this point in the history
…ernal 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
  • Loading branch information
rodion-lim-partior authored Mar 29, 2023
1 parent b7476db commit 3594225
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
56 changes: 56 additions & 0 deletions extension/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,62 @@ func (api *PrivateExtensionAPI) doMultiTenantChecks(ctx context.Context, address
return nil
}

// GenerateExtensionApprovalUuid generates a uuid to be used for contract state extension approval when calling doVote within the management contract,
// allowing the approval method to be called with an external signer
func (api *PrivateExtensionAPI) GenerateExtensionApprovalUuid(ctx context.Context, addressToVoteOn common.Address, externalSignerAddress common.Address, txa ethapi.SendTxArgs) (string, error) {
err := api.doMultiTenantChecks(ctx, txa.From, txa)
if err != nil {
return "", err
}

psm, err := api.privacyService.apiBackendHelper.PSMR().ResolveForUserContext(ctx)
if err != nil {
return "", err
}
psi := psm.ID

// check if the extension has been completed. if yes
// no acceptance required
status, err := api.checkIfExtensionComplete(addressToVoteOn, externalSignerAddress, psi)
if err != nil {
return "", err
}

if status {
return "", errors.New("contract extension process complete. nothing to accept")
}

// get all participants for the contract being extended
participants, err := api.privacyService.GetAllParticipants(api.privacyService.stateFetcher.getCurrentBlockHash(), addressToVoteOn, psi)
if err == nil {
txa.PrivateFor = append(txa.PrivateFor, participants...)
}

txArgs, err := api.privacyService.GenerateTransactOptions(txa)
if err != nil {
return "", err
}

psiManagementContractClient := api.privacyService.managementContract(psi)
defer psiManagementContractClient.Close()
voterList, err := psiManagementContractClient.GetAllVoters(addressToVoteOn)
if err != nil {
return "", err
}
if isVoter := checkAddressInList(externalSignerAddress, voterList); !isVoter {
return "", errNotAcceptor
}

if api.checkAlreadyVoted(addressToVoteOn, externalSignerAddress, psi) {
return "", errors.New("already voted")
}
uuid, err := generateUuid(addressToVoteOn, txArgs.PrivateFrom, txArgs.PrivateFor, api.privacyService.ptm)
if err != nil {
return "", err
}
return uuid, nil
}

// ApproveContractExtension submits the vote to the specified extension management contract. The vote indicates whether to extend
// a given contract to a new participant or not
func (api *PrivateExtensionAPI) ApproveExtension(ctx context.Context, addressToVoteOn common.Address, vote bool, txa ethapi.SendTxArgs) (string, error) {
Expand Down
7 changes: 7 additions & 0 deletions extension/proxy_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func (api *PrivateExtensionProxyAPI) ActiveExtensionContracts(ctx context.Contex
return extracted
}

func (api *PrivateExtensionProxyAPI) GenerateExtensionApprovalUuid(ctx context.Context, addressToVoteOn common.Address, externalSignerAddress common.Address, txa ethapi.SendTxArgs) (string, error) {
log.Info("QLight - proxy enabled")
var result string
err := api.proxyClient.CallContext(ctx, &result, "quorumExtension_generateExtensionApprovalUuid", addressToVoteOn, externalSignerAddress, txa)
return result, err
}

// ApproveContractExtension submits the vote to the specified extension management contract. The vote indicates whether to extend
// a given contract to a new participant or not
func (api *PrivateExtensionProxyAPI) ApproveExtension(ctx context.Context, addressToVoteOn common.Address, vote bool, txa ethapi.SendTxArgs) (string, error) {
Expand Down
6 changes: 6 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,12 @@ web3._extend({
property: 'quorumExtension',
methods:
[
new web3._extend.Method({
name: 'generateExtensionApprovalUuid',
call: 'quorumExtension_generateExtensionApprovalUuid',
params: 2,
inputFormatter: [web3._extend.formatters.inputAddressFormatter, web3._extend.formatters.inputAddressFormatter, web3._extend.formatters.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'approveExtension',
call: 'quorumExtension_approveExtension',
Expand Down

0 comments on commit 3594225

Please sign in to comment.