Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension: expose generation of management contract uuid to allow external signing of approval request #1613

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions extension/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,66 @@ 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, 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, txa.From, psi)
if err != nil {
return "", err
}

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

if !core.CheckIfAdminAccount(txa.From) {
return "", errors.New("account cannot accept extension")
}

// 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(txArgs.From, voterList); !isVoter {
return "", errNotAcceptor
}

if api.checkAlreadyVoted(addressToVoteOn, txArgs.From, 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, txa ethapi.SendTxArgs) (string, error) {
log.Info("QLight - proxy enabled")
var result string
err := api.proxyClient.CallContext(ctx, &result, "quorumExtension_generateExtensionApprovalUuid", addressToVoteOn, 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.inputTransactionFormatter]
}),
new web3._extend.Method({
name: 'approveExtension',
call: 'quorumExtension_approveExtension',
Expand Down