Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce pools #631

Merged
merged 18 commits into from
Mar 22, 2021
3 changes: 3 additions & 0 deletions api/blockchain_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ var (
types.DeployContract: "deployContract",
types.CallContract: "callContract",
types.TerminateContract: "terminateContract",
types.DelegateTx: "delegate",
types.UndelegateTx: "undelegate",
types.KillDelegatorTx: "killDelegator",
}
)

Expand Down
47 changes: 47 additions & 0 deletions api/dna_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ type ActivateInviteArgs struct {
BaseTxArgs
}

type DelegateTxArgs struct {
To *common.Address `json:"to"`
BaseTxArgs
}

type KillDelegatorTxArgs struct {
To *common.Address `json:"to"`
BaseTxArgs
}

type Invite struct {
Hash common.Hash `json:"hash"`
Receiver common.Address `json:"receiver"`
Expand Down Expand Up @@ -186,6 +196,37 @@ func (api *DnaApi) BecomeOffline(ctx context.Context, args BaseTxArgs) (common.H
return hash, nil
}

func (api *DnaApi) Delegate(ctx context.Context, args DelegateTxArgs) (common.Hash, error) {
from := api.baseApi.getCurrentCoinbase()
hash, err := api.baseApi.sendTx(ctx, from, args.To, types.DelegateTx, decimal.Zero, decimal.Zero, decimal.Zero, args.Nonce, args.Epoch, nil, nil)

if err != nil {
return common.Hash{}, err
}

return hash, nil
}

func (api *DnaApi) Undelegate(ctx context.Context, args BaseTxArgs) (common.Hash, error) {
from := api.baseApi.getCurrentCoinbase()
hash, err := api.baseApi.sendTx(ctx, from, nil, types.UndelegateTx, decimal.Zero, decimal.Zero, decimal.Zero, args.Nonce, args.Epoch, nil, nil)

if err != nil {
return common.Hash{}, err
}
return hash, nil
}

func (api *DnaApi) KillDelegator(ctx context.Context, args KillDelegatorTxArgs) (common.Hash, error) {
from := api.baseApi.getCurrentCoinbase()
hash, err := api.baseApi.sendTx(ctx, from, args.To, types.KillDelegatorTx, decimal.Zero, decimal.Zero, decimal.Zero, args.Nonce, args.Epoch, nil, nil)

if err != nil {
return common.Hash{}, err
}
return hash, nil
}

func (api *DnaApi) SendTransaction(ctx context.Context, args SendTxArgs) (common.Hash, error) {

var payload []byte
Expand Down Expand Up @@ -228,6 +269,9 @@ type Identity struct {
Invitees []state.TxAddr `json:"invitees"`
Penalty decimal.Decimal `json:"penalty"`
LastValidationFlags []string `json:"lastValidationFlags"`
Delegatee *common.Address `json:"delegatee"`
DelegationEpoch uint16 `json:"delegationEpoch"`
DelegationNonce uint32 `json:"delegationNonce"`
}

func (api *DnaApi) Identities() []Identity {
Expand Down Expand Up @@ -373,6 +417,9 @@ func convertIdentity(currentEpoch uint16, address common.Address, data state.Ide
Invitees: invitees,
Penalty: blockchain.ConvertToFloat(data.Penalty),
LastValidationFlags: flags,
Delegatee: data.Delegatee,
DelegationEpoch: data.DelegationEpoch,
DelegationNonce: data.DelegationNonce,
}
}

Expand Down
Loading