|
| 1 | +package query |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "math/big" |
| 7 | + |
| 8 | + "github.com/0xPolygon/cdk-contracts-tooling/contracts/fep/aggchain-ecdsa-multisig/aggchainecdsamultisig" |
| 9 | + "github.com/agglayer/aggkit/aggsender/types" |
| 10 | + aggkittypes "github.com/agglayer/aggkit/types" |
| 11 | + "github.com/ethereum/go-ethereum/accounts/abi/bind" |
| 12 | + "github.com/ethereum/go-ethereum/common" |
| 13 | +) |
| 14 | + |
| 15 | +var ( |
| 16 | + _ types.MultisigQuerier = (*ECDSAMultisigCommitteeQuery)(nil) |
| 17 | + _ types.MultisigContract = (*aggchainecdsamultisig.Aggchainecdsamultisig)(nil) |
| 18 | +) |
| 19 | + |
| 20 | +type ECDSAMultisigCommitteeQuery struct { |
| 21 | + multisigCommitteeSC types.MultisigContract |
| 22 | + multisigCommitteeAddr common.Address |
| 23 | +} |
| 24 | + |
| 25 | +// NewECDSAMultisigCommitteeQuery creates a new instance of ECDSAMultisigCommitteeQuery |
| 26 | +func NewECDSAMultisigCommitteeQuery(multisigCommitteeAddr common.Address, |
| 27 | + l1Client aggkittypes.BaseEthereumClienter) (*ECDSAMultisigCommitteeQuery, error) { |
| 28 | + multisigCommitteeSC, err := aggchainecdsamultisig.NewAggchainecdsamultisig( |
| 29 | + multisigCommitteeAddr, l1Client) |
| 30 | + if err != nil { |
| 31 | + return nil, err |
| 32 | + } |
| 33 | + |
| 34 | + return &ECDSAMultisigCommitteeQuery{ |
| 35 | + multisigCommitteeSC: multisigCommitteeSC, |
| 36 | + multisigCommitteeAddr: multisigCommitteeAddr, |
| 37 | + }, nil |
| 38 | +} |
| 39 | + |
| 40 | +// GetMultisigCommittee reads the multisig committee from the smart contract for a certain block |
| 41 | +func (m *ECDSAMultisigCommitteeQuery) GetMultisigCommittee( |
| 42 | + ctx context.Context, blockNum *big.Int) (*types.MultisigCommittee, error) { |
| 43 | + callOpts := &bind.CallOpts{Pending: false, BlockNumber: blockNum} |
| 44 | + threshold, err := m.multisigCommitteeSC.Threshold(callOpts) |
| 45 | + if err != nil { |
| 46 | + return nil, fmt.Errorf("failed to query the signatures threshold for block %d: %w", blockNum, err) |
| 47 | + } |
| 48 | + |
| 49 | + signers, err := m.multisigCommitteeSC.GetSigners(callOpts) |
| 50 | + if err != nil { |
| 51 | + return nil, fmt.Errorf("failed to query the committee signers for block %d: %w", blockNum, err) |
| 52 | + } |
| 53 | + |
| 54 | + members := make([]*types.SignerInfo, 0, len(signers)) |
| 55 | + for _, signer := range signers { |
| 56 | + // TODO: Populate the URLs once they are on the smart contract |
| 57 | + members = append(members, types.NewSignerInfo("", signer)) |
| 58 | + } |
| 59 | + |
| 60 | + return types.NewMultisigCommittee(members, threshold) |
| 61 | +} |
0 commit comments