-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature 69 spo gov votes notifications (#71)
* work in progress Signed-off-by: Alessio <[email protected]> * initial implementation of pool votes notification system. Nedes to be tested Signed-off-by: Alessio <[email protected]> * tested at runtime (no votes yet) Signed-off-by: Alessio <[email protected]> * Added integration tests Signed-off-by: Alessio <[email protected]> * Completed tests Signed-off-by: Alessio <[email protected]> --------- Signed-off-by: Alessio <[email protected]> Co-authored-by: Alessio <[email protected]>
- Loading branch information
1 parent
582b77b
commit 719ded9
Showing
15 changed files
with
7,871 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- Create new Pools Votes table | ||
CREATE TABLE public.pool_votes ( | ||
id bigint NOT NULL, | ||
gov_id character varying(128) NOT NULL, | ||
pool_id character varying(128) NOT NULL, | ||
block_time bigint NOT NULL | ||
); | ||
|
||
CREATE SEQUENCE public.pool_votes_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE public.pool_votes_id_seq OWNED BY public.pool_votes.id; | ||
ALTER TABLE ONLY public.pool_votes ALTER COLUMN id SET DEFAULT nextval('public.pool_votes_id_seq'::regclass); | ||
|
||
ALTER TABLE ONLY public.pool_votes | ||
ADD CONSTRAINT pool_votes_pkey PRIMARY KEY (id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.devpool.thothBot.dao; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.jdbc.support.GeneratedKeyHolder; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Repository | ||
public class PoolVotesDao { | ||
private static final Logger LOG = LoggerFactory.getLogger(PoolVotesDao.class); | ||
private static final String FIELD_GOV_ID = "gov_id"; | ||
private static final String FIELD_BLOCK_TIME = "block_time"; | ||
private static final String FIELD_POOL_ID = "pool_id"; | ||
|
||
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; | ||
|
||
public PoolVotesDao(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { | ||
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; | ||
} | ||
|
||
@PostConstruct | ||
public void post() { | ||
LOG.info("Pool Votes DAO initialised"); | ||
} | ||
|
||
/** | ||
* Get the votes for a given gov action of a pool, lower than the given block time | ||
* | ||
* @param govId gov action | ||
* @param poolId the Pool ID | ||
* @param blockTime latest block time of the vote | ||
* @return the list of block times of all the pool votes for a given gov action | ||
*/ | ||
public List<Long> getVotesForGovAction(String govId, String poolId, long blockTime) { | ||
return this.namedParameterJdbcTemplate.query( | ||
""" | ||
select block_time | ||
from pool_votes | ||
where gov_id = :gov_id and | ||
pool_id = :pool_id and | ||
block_time <= :block_time | ||
""", | ||
Map.of(FIELD_GOV_ID, govId, | ||
FIELD_POOL_ID, poolId, | ||
FIELD_BLOCK_TIME, blockTime), | ||
(rs, numRow) -> rs.getLong(FIELD_BLOCK_TIME)); | ||
} | ||
|
||
public void addPoolVote(String govId, String poolId, Long blockTime) { | ||
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder(); | ||
namedParameterJdbcTemplate.update( | ||
""" | ||
insert into pool_votes (gov_id, pool_id, block_time) | ||
values (:gov_id, :pool_id, :block_time) | ||
""", | ||
new MapSqlParameterSource(Map.of( | ||
FIELD_GOV_ID, govId, | ||
FIELD_POOL_ID, poolId, | ||
FIELD_BLOCK_TIME, blockTime)), | ||
keyHolder, new String[]{"id"}); | ||
|
||
LOG.trace("Inserted new pool vote with key {} for gov action {} and pool {} ", | ||
keyHolder.getKeyAs(Long.class), govId, poolId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.