Skip to content

Commit

Permalink
Merge branch 'main' into feature/env_config
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Oct 20, 2023
2 parents 4cfa7c8 + 812542c commit cc2303c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ COPY --from=builder /go/pkg/mod/github.com/wasmerio/[email protected]/wasmer/pack
/go/pkg/mod/github.com/wasmerio/[email protected]/wasmer/packaged/lib/linux-amd64/libwasmer.so
# Support for go-rapidsnark prover (https://github.com/iden3/go-rapidsnark/tree/main/prover)
RUN apt-get update && \
apt-get install -y libc6-dev libomp-dev openmpi-common libgomp1 curl && \
apt-get install --no-install-recommends -y libc6-dev libomp-dev openmpi-common libgomp1 curl && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
Expand Down
27 changes: 25 additions & 2 deletions api/censuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/vocdoni/census3/census"
queries "github.com/vocdoni/census3/db/sqlc"
"github.com/vocdoni/census3/state"
"go.vocdoni.io/dvote/httprouter"
api "go.vocdoni.io/dvote/httprouter/apirest"
"go.vocdoni.io/dvote/log"
Expand Down Expand Up @@ -134,9 +135,31 @@ func (capi *census3API) createAndPublishCensus(req *CreateCensusRequest, qID str
if len(strategyTokens) == 0 {
return 0, ErrNoStrategyTokens.WithErr(err)
}

// any census strategy is identified by id created from the concatenation of
// the block number, the strategy id and the anonymous flag. The creation of
// censuses on specific block is not supported yet, so we need to get the
// last block of every token chain id to sum them and get the total block
// number, used to create the census id.
totalTokensBlockNumber := uint64(0)
w3 := state.Web3{}
defer cancel()
// get correct web3 uri provider
for _, token := range strategyTokens {
w3uri, exists := capi.w3p[token.ChainID]
if !exists {
return 0, ErrChainIDNotSupported.With("chain ID not supported")
}
if err := w3.Init(internalCtx, w3uri, common.BytesToAddress(token.ID), state.TokenType(token.TypeID)); err != nil {
return 0, ErrInitializingWeb3.WithErr(err)
}
currentBlockNumber, err := w3.LatestBlockNumber(internalCtx)
if err != nil {
return 0, ErrCantGetLastBlockNumber.WithErr(err)
}
totalTokensBlockNumber += currentBlockNumber
}
// compute the new censusId and censusType
newCensusID := census.InnerCensusID(req.BlockNumber, req.StrategyID, req.Anonymous)
newCensusID := census.InnerCensusID(totalTokensBlockNumber, req.StrategyID, req.Anonymous)
// check if the census already exists
_, err = qtx.CensusByID(internalCtx, newCensusID)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ type TokenHoldersResponse struct {
}

type CreateCensusRequest struct {
StrategyID uint64 `json:"strategyID"`
BlockNumber uint64 `json:"blockNumber"`
Anonymous bool `json:"anonymous"`
StrategyID uint64 `json:"strategyID"`
Anonymous bool `json:"anonymous"`
}

type CreateCensusResponse struct {
Expand Down
6 changes: 4 additions & 2 deletions service/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ var (
common.HexToAddress("0xe54d702f98E312aBA4318E3c6BDba98ab5e11012"): new(big.Int).SetUint64(16000000000000000000),
common.HexToAddress("0x38d2BC91B89928f78cBaB3e4b1949e28787eC7a3"): new(big.Int).SetUint64(13000000000000000000),
common.HexToAddress("0xF752B527E2ABA395D1Ba4C0dE9C147B763dDA1f4"): new(big.Int).SetUint64(12000000000000000000),
common.HexToAddress("0xdeb8699659bE5d41a0e57E179d6cB42E00B9200C"): new(big.Int).SetUint64(9000000000000000000),
common.HexToAddress("0xe1308a8d0291849bfFb200Be582cB6347FBE90D9"): new(big.Int).SetUint64(9000000000000000000),
common.HexToAddress("0xB1F05B11Ba3d892EdD00f2e7689779E2B8841827"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0xdeb8699659bE5d41a0e57E179d6cB42E00B9200C"): new(big.Int).SetUint64(7000000000000000000),
common.HexToAddress("0xB1F05B11Ba3d892EdD00f2e7689779E2B8841827"): new(big.Int).SetUint64(5000000000000000000),
common.HexToAddress("0xF3C456FAAa70fea307A073C3DA9572413c77f58B"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0x45D3a03E8302de659e7Ea7400C4cfe9CAED8c723"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0x313c7f7126486fFefCaa9FEA92D968cbf891b80c"): new(big.Int).SetUint64(3000000000000000000),
common.HexToAddress("0x1893eD78480267D1854373A99Cee8dE2E08d430F"): new(big.Int).SetUint64(2000000000000000000),
common.HexToAddress("0xa2E4D94c5923A8dd99c5792A7B0436474c54e1E1"): new(big.Int).SetUint64(2000000000000000000),
common.HexToAddress("0x2a4636A5a1138e35F7f93e81FA56d3c970BC6777"): new(big.Int).SetUint64(1000000000000000000),
}
)

Expand Down
6 changes: 4 additions & 2 deletions state/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ var (
common.HexToAddress("0xe54d702f98E312aBA4318E3c6BDba98ab5e11012"): new(big.Int).SetUint64(16000000000000000000),
common.HexToAddress("0x38d2BC91B89928f78cBaB3e4b1949e28787eC7a3"): new(big.Int).SetUint64(13000000000000000000),
common.HexToAddress("0xF752B527E2ABA395D1Ba4C0dE9C147B763dDA1f4"): new(big.Int).SetUint64(12000000000000000000),
common.HexToAddress("0xdeb8699659bE5d41a0e57E179d6cB42E00B9200C"): new(big.Int).SetUint64(9000000000000000000),
common.HexToAddress("0xe1308a8d0291849bfFb200Be582cB6347FBE90D9"): new(big.Int).SetUint64(9000000000000000000),
common.HexToAddress("0xB1F05B11Ba3d892EdD00f2e7689779E2B8841827"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0xdeb8699659bE5d41a0e57E179d6cB42E00B9200C"): new(big.Int).SetUint64(7000000000000000000),
common.HexToAddress("0xB1F05B11Ba3d892EdD00f2e7689779E2B8841827"): new(big.Int).SetUint64(5000000000000000000),
common.HexToAddress("0xF3C456FAAa70fea307A073C3DA9572413c77f58B"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0x45D3a03E8302de659e7Ea7400C4cfe9CAED8c723"): new(big.Int).SetUint64(6000000000000000000),
common.HexToAddress("0x313c7f7126486fFefCaa9FEA92D968cbf891b80c"): new(big.Int).SetUint64(3000000000000000000),
common.HexToAddress("0x1893eD78480267D1854373A99Cee8dE2E08d430F"): new(big.Int).SetUint64(2000000000000000000),
common.HexToAddress("0xa2E4D94c5923A8dd99c5792A7B0436474c54e1E1"): new(big.Int).SetUint64(2000000000000000000),
common.HexToAddress("0x2a4636A5a1138e35F7f93e81FA56d3c970BC6777"): new(big.Int).SetUint64(1000000000000000000),
}
)

Expand Down
2 changes: 1 addition & 1 deletion state/web3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func Test_transferLogs(t *testing.T) {

logs, err := w.transferLogs(MonkeysCreationBlock, MonkeysCreationBlock+500)
c.Assert(err, qt.IsNil)
c.Assert(logs, qt.HasLen, 10)
c.Assert(logs, qt.HasLen, len(MonkeysHolders))
}

func Test_calcPartialBalances(t *testing.T) {
Expand Down

0 comments on commit cc2303c

Please sign in to comment.