Skip to content

Commit

Permalink
Merge pull request #24 from maestro-org/feat/contracts/linear-vesting
Browse files Browse the repository at this point in the history
feat: contracts/linear-vesting
  • Loading branch information
Vardominator authored Oct 29, 2023
2 parents f16ce64 + 2135ed1 commit 413d626
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 26 deletions.
29 changes: 23 additions & 6 deletions client/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
"github.com/maestro-org/go-sdk/utils"
)

func (c *Client) AccountAddresses(stakeAddr string, params *utils.Parameters) (*models.AccountAddresses, error) {
func (c *Client) AccountAddresses(
stakeAddr string,
params *utils.Parameters,
) (*models.AccountAddresses, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -27,7 +30,10 @@ func (c *Client) AccountAddresses(stakeAddr string, params *utils.Parameters) (*
return &accountAddresses, nil
}

func (c *Client) AccountAssets(stakeAddr string, params *utils.Parameters) (*models.AccountAssets, error) {
func (c *Client) AccountAssets(
stakeAddr string,
params *utils.Parameters,
) (*models.AccountAssets, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -46,7 +52,10 @@ func (c *Client) AccountAssets(stakeAddr string, params *utils.Parameters) (*mod
return &accountAssets, nil
}

func (c *Client) StakeAccountHistory(stakeAddr string, params *utils.Parameters) (*models.StakeAccountHistory, error) {
func (c *Client) StakeAccountHistory(
stakeAddr string,
params *utils.Parameters,
) (*models.StakeAccountHistory, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -65,7 +74,9 @@ func (c *Client) StakeAccountHistory(stakeAddr string, params *utils.Parameters)
return &stakeAccountHistory, nil
}

func (c *Client) StakeAccountInformation(stakeAddr string) (*models.StakeAccountInformation, error) {
func (c *Client) StakeAccountInformation(
stakeAddr string,
) (*models.StakeAccountInformation, error) {
url := fmt.Sprintf("/accounts/%s", stakeAddr)
resp, err := c.get(url)
if err != nil {
Expand All @@ -80,7 +91,10 @@ func (c *Client) StakeAccountInformation(stakeAddr string) (*models.StakeAccount
return &stakeAccountInformation, nil
}

func (c *Client) StakeAccountRewards(stakeAddr string, params *utils.Parameters) (*models.StakeAccountRewards, error) {
func (c *Client) StakeAccountRewards(
stakeAddr string,
params *utils.Parameters,
) (*models.StakeAccountRewards, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -99,7 +113,10 @@ func (c *Client) StakeAccountRewards(stakeAddr string, params *utils.Parameters)
return &stakeAccountRewards, nil
}

func (c *Client) StakeAccountUpdates(stakeAddr string, params *utils.Parameters) (*models.StakeAccountUpdates, error) {
func (c *Client) StakeAccountUpdates(
stakeAddr string,
params *utils.Parameters,
) (*models.StakeAccountUpdates, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand Down
30 changes: 24 additions & 6 deletions client/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ func (c *Client) AddressTransactionCount(address string) (*models.AddressTransac
return &addressTransactionCount, nil
}

func (c *Client) AddressTransactions(address string, params *utils.Parameters) (*models.AddressTransactions, error) {
func (c *Client) AddressTransactions(
address string,
params *utils.Parameters,
) (*models.AddressTransactions, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -57,7 +60,10 @@ func (c *Client) AddressTransactions(address string, params *utils.Parameters) (
return &addressTransactions, nil
}

func (c *Client) PaymentCredentialTransactions(paymentCredential string, params *utils.Parameters) (*models.AddressTransactions, error) {
func (c *Client) PaymentCredentialTransactions(
paymentCredential string,
params *utils.Parameters,
) (*models.AddressTransactions, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -76,7 +82,10 @@ func (c *Client) PaymentCredentialTransactions(paymentCredential string, params
return &addressTransactions, nil
}

func (c *Client) UtxoReferencesAtAddress(address string, params *utils.Parameters) (*models.UtxoReferencesAtAddress, error) {
func (c *Client) UtxoReferencesAtAddress(
address string,
params *utils.Parameters,
) (*models.UtxoReferencesAtAddress, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -95,7 +104,10 @@ func (c *Client) UtxoReferencesAtAddress(address string, params *utils.Parameter
return &utxoReferencesAtAddress, nil
}

func (c *Client) UtxosAtAddress(address string, params *utils.Parameters) (*models.UtxosAtAddress, error) {
func (c *Client) UtxosAtAddress(
address string,
params *utils.Parameters,
) (*models.UtxosAtAddress, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -114,7 +126,10 @@ func (c *Client) UtxosAtAddress(address string, params *utils.Parameters) (*mode
return &utxosAtAddress, nil
}

func (c *Client) UtxosAtAddresses(addresses []string, params *utils.Parameters) (*models.UtxosAtAddress, error) {
func (c *Client) UtxosAtAddresses(
addresses []string,
params *utils.Parameters,
) (*models.UtxosAtAddress, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -134,7 +149,10 @@ func (c *Client) UtxosAtAddresses(addresses []string, params *utils.Parameters)
return &utxosAtAddress, nil
}

func (c *Client) UtxosByPaymentCredential(paymentCredential string, params *utils.Parameters) (*models.UtxosAtAddress, error) {
func (c *Client) UtxosByPaymentCredential(
paymentCredential string,
params *utils.Parameters,
) (*models.UtxosAtAddress, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand Down
20 changes: 16 additions & 4 deletions client/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
"github.com/maestro-org/go-sdk/utils"
)

func (c *Client) AccountsHoldingAsset(assetId string, params *utils.Parameters) (*models.AccountsHoldingAsset, error) {
func (c *Client) AccountsHoldingAsset(
assetId string,
params *utils.Parameters,
) (*models.AccountsHoldingAsset, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -27,7 +30,10 @@ func (c *Client) AccountsHoldingAsset(assetId string, params *utils.Parameters)
return &accountsHoldingAsset, nil
}

func (c *Client) AddressHoldingAsset(assetId string, params *utils.Parameters) (*models.AddressesHoldingAsset, error) {
func (c *Client) AddressHoldingAsset(
assetId string,
params *utils.Parameters,
) (*models.AddressesHoldingAsset, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand Down Expand Up @@ -61,7 +67,10 @@ func (c *Client) Asset(assetId string) (*models.AssetInformations, error) {
return &assetInformation, nil
}

func (c *Client) AssetTransactions(assetId string, params *utils.Parameters) (*models.AssetTransactions, error) {
func (c *Client) AssetTransactions(
assetId string,
params *utils.Parameters,
) (*models.AssetTransactions, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -80,7 +89,10 @@ func (c *Client) AssetTransactions(assetId string, params *utils.Parameters) (*m
return &assetTransactions, nil
}

func (c *Client) AssetUpdates(assetId string, params *utils.Parameters) (*models.AssetUpdates, error) {
func (c *Client) AssetUpdates(
assetId string,
params *utils.Parameters,
) (*models.AssetUpdates, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand Down
25 changes: 20 additions & 5 deletions client/asset_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
"github.com/maestro-org/go-sdk/utils"
)

func (c *Client) AccountsHoldingPolicy(policy string, params *utils.Parameters) (*models.AccountsHoldingPolicy, error) {
func (c *Client) AccountsHoldingPolicy(
policy string,
params *utils.Parameters,
) (*models.AccountsHoldingPolicy, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -27,7 +30,10 @@ func (c *Client) AccountsHoldingPolicy(policy string, params *utils.Parameters)
return &response, err
}

func (c *Client) AddressesHoldingPolicy(policy string, params *utils.Parameters) (*models.AddressesHoldingPolicy, error) {
func (c *Client) AddressesHoldingPolicy(
policy string,
params *utils.Parameters,
) (*models.AddressesHoldingPolicy, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -46,7 +52,10 @@ func (c *Client) AddressesHoldingPolicy(policy string, params *utils.Parameters)
return &response, err
}

func (c *Client) SpecificPolicyInformations(policy string, params *utils.Parameters) (*models.PolicyInformation, error) {
func (c *Client) SpecificPolicyInformations(
policy string,
params *utils.Parameters,
) (*models.PolicyInformation, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -65,7 +74,10 @@ func (c *Client) SpecificPolicyInformations(policy string, params *utils.Paramet
return &response, err
}

func (c *Client) TransactionsMovingPolicy(policy string, params *utils.Parameters) (*models.PolicyTransactions, error) {
func (c *Client) TransactionsMovingPolicy(
policy string,
params *utils.Parameters,
) (*models.PolicyTransactions, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -84,7 +96,10 @@ func (c *Client) TransactionsMovingPolicy(policy string, params *utils.Parameter
return &response, err
}

func (c *Client) UtxosContainingPolicy(policy string, params *utils.Parameters) (*models.UtxosContainingPolicy, error) {
func (c *Client) UtxosContainingPolicy(
policy string,
params *utils.Parameters,
) (*models.UtxosContainingPolicy, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand Down
68 changes: 68 additions & 0 deletions client/linear_vesting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package client

import (
"encoding/json"
"fmt"

"github.com/maestro-org/go-sdk/models"
)

type LockBody struct {
Sender string `json:"sender"`
Beneficiary string `json:"beneficiary"`
AssetPolicyId string `json:"asset_policy_id"`
AssetTokenName string `json:"asset_token_name"`
TotalVestingQuantity int64 `json:"total_vesting_quantity"`
VestingPeriodStart int64 `json:"vesting_period_start"`
VestingPeriodEnd int64 `json:"vesting_period_end"`
FirstUnlockPossibleAfter int64 `json:"first_unlock_possible_after"`
TotalInstallments int64 `json:"total_installments"`
}

func (c *Client) LockAssets(lockBody LockBody) (*models.LockTransaction, error) {
url := "/contracts/vesting/lock"

body := lockBody
resp, err := c.post(url, body)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var lockTransaction models.LockTransaction
err = json.NewDecoder(resp.Body).Decode(&lockTransaction)
if err != nil {
return nil, err
}
return &lockTransaction, nil
}

func (c *Client) StateOfVestingAssets(beneficiary string) (*[]models.VestingState, error) {
url := fmt.Sprintf("/contracts/vesting/state/%s", beneficiary)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var vestingStates []models.VestingState
err = json.NewDecoder(resp.Body).Decode(&vestingStates)
if err != nil {
return nil, err
}
return &vestingStates, nil

}

func (c *Client) CollectAssets(beneficiary string) (*models.CollectTransaction, error) {
url := fmt.Sprintf("/contracts/vesting/collect/%s", beneficiary)
resp, err := c.post(url, nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var collectTransaction models.CollectTransaction
err = json.NewDecoder(resp.Body).Decode(&collectTransaction)
if err != nil {
return nil, err
}
return &collectTransaction, nil
}
15 changes: 12 additions & 3 deletions client/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ func (c *Client) ListOfRegisteredPools(params *utils.Parameters) (*models.Regist
return &registeredPools, nil
}

func (c *Client) StakePoolMintedBlocks(poolId string, params *utils.Parameters) (*models.PoolMintedBlocks, error) {
func (c *Client) StakePoolMintedBlocks(
poolId string,
params *utils.Parameters,
) (*models.PoolMintedBlocks, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -46,7 +49,10 @@ func (c *Client) StakePoolMintedBlocks(poolId string, params *utils.Parameters)
return &poolMintedBlocks, nil
}

func (c *Client) StakePoolDelegators(poolId string, params *utils.Parameters) (*models.StakePoolDelegators, error) {
func (c *Client) StakePoolDelegators(
poolId string,
params *utils.Parameters,
) (*models.StakePoolDelegators, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -65,7 +71,10 @@ func (c *Client) StakePoolDelegators(poolId string, params *utils.Parameters) (*
return &stakePoolDelegators, nil
}

func (c *Client) StakePoolHistory(poolId string, params *utils.Parameters) (*models.StakePoolHistory, error) {
func (c *Client) StakePoolHistory(
poolId string,
params *utils.Parameters,
) (*models.StakePoolHistory, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand Down
11 changes: 9 additions & 2 deletions client/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func (c *Client) TransactionDetails(txHash string) (*models.TransactionDetails,

}

func (c *Client) TransactionOutputFromReference(txHash string, index int, params *utils.Parameters) (*models.TransactionOutputFromReference, error) {
func (c *Client) TransactionOutputFromReference(
txHash string,
index int,
params *utils.Parameters,
) (*models.TransactionOutputFromReference, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand All @@ -90,7 +94,10 @@ func (c *Client) TransactionOutputFromReference(txHash string, index int, params
return &transactionOutputFromReference, nil
}

func (c *Client) TransactionOutputsFromReferences(references []models.TxoReference, params *utils.Parameters) (*models.TransactionOutputsFromReferences, error) {
func (c *Client) TransactionOutputsFromReferences(
references []models.TxoReference,
params *utils.Parameters,
) (*models.TransactionOutputsFromReferences, error) {
formattedParams := ""
if params != nil {
formattedParams = params.Format()
Expand Down
Loading

0 comments on commit 413d626

Please sign in to comment.