Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
clmikestone committed Aug 27, 2024
1 parent 4e7c5da commit aa084c7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ docs/
# Dotenv file
.env

# Ignore report.md
report.md
39 changes: 1 addition & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### `ElectionOracle` Contract - README
### `ElectionOracle` Contract

---

Expand Down Expand Up @@ -80,7 +80,6 @@ Example constructor call:
```solidity
address oracle = 0x123456789abcdef0123456789abcdef012345678;
uint256 minTimestamp = 1730965200; // November 7, 2024, 00:00:00 EST
ElectionOracle oracleContract = new ElectionOracle(oracle, minTimestamp);
```

---
Expand Down Expand Up @@ -265,39 +264,3 @@ contract ElectionConsumer {
}
}
```

### Key Features of the Example Contract:

- **`retrieveFinalResult`**: Fetches the raw election result.
- **`getReadableResult`**: Maps the `ElectionResult` enum to a readable string (e.g., "Trump", "Harris").

### Deployment Instructions:

- Deploy `ElectionOracle` on your network with your chosen oracle and timestamp.
- Use the deployed `ElectionOracle` contract address in your consumer contract when deploying `ElectionConsumer`.

```solidity
ElectionConsumer consumer = new ElectionConsumer(oracleAddress);
```

---

## Conclusion

The `ElectionOracle` contract securely manages and finalizes election results, with strict access control using roles managed by the contract owner. The usage of the contract is transparent, with event emissions and role checks ensuring a robust mechanism for managing election results on the blockchain.

The provided example consumer contract demonstrates a straightforward way to interface with `ElectionOracle`, making it easy for other contracts to consume and interpret finalized election outcomes.

Explanation
Enum in the Interface:
The enum ElectionResult is now included in the IElectionOracle interface, which allows any contract implementing or interacting with this interface to understand the possible outcome values.
Usage of Enum:
Methods like retrieveFinalResult and getReadableResult in the ElectionConsumer contract use the ElectionResult enum to fetch and process the result.
Key Points for External Interaction
When you interact with the ElectionOracle contract from another contract (like ElectionConsumer), having the enum defined in the interface ensures that the contract knows about all possible election outcomes.
This approach also avoids any potential issues related to passing integers around without clearly defined meaning, enhancing both security and code clarity.
Deploying and Using the Contracts
Deploy the ElectionOracle contract with the constructor parameters (oracle address and \_minEndOfElectionTimestamp).
Deploy the ElectionConsumer contract using the address of the deployed ElectionOracle contract.
Interact with ElectionConsumer functions to retrieve the results based on the election outcome.
This method provides a clean, maintainable, and secure way to handle the election results, making your smart contracts modular and easy to interact with.

0 comments on commit aa084c7

Please sign in to comment.