Skip to content

Commit

Permalink
Merge pull request #201 from tonkeeper/elector
Browse files Browse the repository at this point in the history
Add GetParticipantListExtended to contract/elector package
  • Loading branch information
mr-tron authored Nov 23, 2023
2 parents 0cc0e19 + e8c3d90 commit 3100ade
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 3 deletions.
83 changes: 83 additions & 0 deletions contract/elector/elector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package elector

import (
"context"
"fmt"

"github.com/tonkeeper/tongo/tlb"
"github.com/tonkeeper/tongo/ton"
"github.com/tonkeeper/tongo/utils"
)

type executor interface {
RunSmcMethodByID(context.Context, ton.AccountID, int, tlb.VmStack) (uint32, tlb.VmStack, error)
}

type Validator struct {
Stake int64
MaxFactor int64
Address ton.AccountID
AdnlAddr string
}

type ParticipantList struct {
ElectAt int64
ElectClose int64
MinStake int64
TotalStake int64
Validators []Validator
}

// participantList describes a result type of participant_list_extended method.
// https://github.com/ton-blockchain/governance-contract/blob/master/elector-code.fc#L1461
type participantList struct {
ElectAt int64
ElectClose int64
MinStake int64
TotalStake int64
Validators []struct {
ID tlb.Bits256
Validator struct {
Stake uint32
MaxFactor uint32
Address tlb.Bits256
AdnlAddr tlb.Bits256
}
}
}

func GetParticipantListExtended(ctx context.Context, electorAddr ton.AccountID, e executor) (*ParticipantList, error) {
stack := tlb.VmStack{}
status, result, err := e.RunSmcMethodByID(ctx, electorAddr, utils.MethodIdFromName("participant_list_extended"), stack)
if err != nil {
return nil, err
}
if status != 0 {
return nil, fmt.Errorf("emulator status: %d", status)
}
var list participantList
if err = result.Unmarshal(&list); err != nil {
return nil, err
}
validators := make([]Validator, 0, len(list.Validators))
for _, v := range list.Validators {
accountID := ton.AccountID{
Workchain: -1,
Address: v.Validator.Address,
}
v.Validator.AdnlAddr.Hex()
validators = append(validators, Validator{
Stake: int64(v.Validator.Stake),
MaxFactor: int64(v.Validator.MaxFactor),
Address: accountID,
AdnlAddr: v.Validator.AdnlAddr.Hex(),
})
}
return &ParticipantList{
ElectAt: list.ElectAt,
ElectClose: list.ElectClose,
MinStake: list.MinStake,
TotalStake: list.TotalStake,
Validators: validators,
}, nil
}
35 changes: 35 additions & 0 deletions contract/elector/elector_test.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ FROM docker.io/library/ubuntu:20.04 AS emulator-builder
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get -y install build-essential git cmake clang libgflags-dev zlib1g-dev libssl-dev libreadline-dev libmicrohttpd-dev pkg-config libgsl-dev python3 python3-dev python3-pip libsecp256k1-dev libsodium-dev
RUN git clone --recurse-submodules -b emulator-optional-config https://github.com/dungeon-master-666/ton.git
RUN mkdir build && (cd build && cmake ../ton -DCMAKE_BUILD_TYPE=Release && cmake --build . --target emulator -j 2)
RUN mkdir /output && cp build/emulator/libemulator.so /output
RUN git clone --recurse-submodules -b testnet https://github.com/ton-blockchain/ton.git
RUN mkdir build && (cd build && cmake ../ton -DCMAKE_BUILD_TYPE=Release && cmake --build . --target emulator -j 6)
RUN mkdir /output && cp build/emulator/libemulator.so /output
Binary file modified lib/linux/libemulator.so
Binary file not shown.

0 comments on commit 3100ade

Please sign in to comment.