diff --git a/client/accounts.go b/client/accounts.go index 333884d..1bde9a1 100644 --- a/client/accounts.go +++ b/client/accounts.go @@ -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() @@ -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() @@ -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() @@ -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 { @@ -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() @@ -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() diff --git a/client/addresses.go b/client/addresses.go index 815bc20..b7e31d7 100644 --- a/client/addresses.go +++ b/client/addresses.go @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/client/asset.go b/client/asset.go index 94d33cf..e09184e 100644 --- a/client/asset.go +++ b/client/asset.go @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/client/asset_policy.go b/client/asset_policy.go index d11a537..2c34e0e 100644 --- a/client/asset_policy.go +++ b/client/asset_policy.go @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/client/linear_vesting.go b/client/linear_vesting.go new file mode 100644 index 0000000..1e52d3b --- /dev/null +++ b/client/linear_vesting.go @@ -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 +} diff --git a/client/pools.go b/client/pools.go index d58d19b..b22cc07 100644 --- a/client/pools.go +++ b/client/pools.go @@ -27,7 +27,10 @@ func (c *Client) ListOfRegisteredPools(params *utils.Parameters) (*models.Regist return ®isteredPools, 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() @@ -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() @@ -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() diff --git a/client/transactions.go b/client/transactions.go index 52a5b40..e19abe4 100644 --- a/client/transactions.go +++ b/client/transactions.go @@ -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() @@ -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() diff --git a/models/linear_vesting.go b/models/linear_vesting.go new file mode 100644 index 0000000..2333e88 --- /dev/null +++ b/models/linear_vesting.go @@ -0,0 +1,21 @@ +package models + +type LockTransaction struct { + CborHex string `json:"cbor_hex"` + TxHash string `json:"tx_hash"` +} + +type VestingState struct { + AssetName string `json:"asset_name"` + AssetSymbol string `json:"asset_symbol"` + RemainingVestingQuantity int64 `json:"remaining_vesting_quantity"` + TotalInstallments int64 `json:"total_installments"` + TotalVestingQuantity int64 `json:"total_vesting_quantity"` + VestingPeriodStart int64 `json:"vesting_period_start"` + VestingPeriodEnd int64 `json:"vesting_period_end"` +} + +type CollectTransaction struct { + CborHex string `json:"cbor_hex"` + TxHash string `json:"tx_hash"` +}