Skip to content

Commit

Permalink
feat: required signers (extra tx witnesses)
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed Feb 6, 2024
1 parent fe321c8 commit a056107
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
12 changes: 12 additions & 0 deletions api_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ func TestTransactionRedeemersIntegration(t *testing.T) {
testIntUtil(t, fp, &got, &want)
}

func TestTransactionRequiredSignersIntegration(t *testing.T) {
hash := "b024ad35c6309a71a8e613d8bfea2a8185d81eda379ca9128877adefcde1c515"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
got, err := api.TransactionRequiredSigners(context.TODO(), hash)
if err != nil {
t.Fatal(err)
}
fp := filepath.Join(testdata, strings.ToLower(strings.TrimPrefix(t.Name(), "Test"))+".golden")
want := []blockfrost.TransactionRequiredSigner{}
testIntUtil(t, fp, &got, &want)
}

func TestTransactionDelegationCertsIntegration(t *testing.T) {
hash := "6d619f41ba2e11b78c0d5647fb71ee5df05622fda1748a9124446226e54e6b50"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
Expand Down
53 changes: 39 additions & 14 deletions api_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ import (
)

const (
resourceTxs = "txs"
resourceTx = "tx"
resourceTxStakes = "stakes"
resourceTxUTXOs = "utxos"
resourceTxWithdrawals = "withdrawals"
resourceTxMetadata = "metadata"
resourceTxRedeemers = "redeemers"
resourceCbor = "cbor"
resourceTxDelegations = "delegations"
resourceTxPoolUpdates = "pool_updates"
resourceTxPoolRetires = "pool_retires"
resourceTxSubmit = "submit"
resourceTxEvaluate = "utils/txs/evaluate"
resourceTxEvaluateUtxos = "utils/txs/evaluate/utxos"
resourceTxs = "txs"
resourceTx = "tx"
resourceTxStakes = "stakes"
resourceTxUTXOs = "utxos"
resourceTxWithdrawals = "withdrawals"
resourceTxMetadata = "metadata"
resourceTxRedeemers = "redeemers"
resourceTxRequiredSigners = "required_signers"
resourceCbor = "cbor"
resourceTxDelegations = "delegations"
resourceTxPoolUpdates = "pool_updates"
resourceTxPoolRetires = "pool_retires"
resourceTxSubmit = "submit"
resourceTxEvaluate = "utils/txs/evaluate"
resourceTxEvaluateUtxos = "utils/txs/evaluate/utxos"
)

type TransactionContent struct {
Expand Down Expand Up @@ -284,6 +285,10 @@ type TransactionRedeemer struct {
Fee string `json:"fee"`
}

type TransactionRequiredSigner struct {
WitnessHash string `json:"witness_hash"`
}

type Quantity string

type Value struct {
Expand Down Expand Up @@ -563,6 +568,26 @@ func (c *apiClient) TransactionPoolRetirementCerts(ctx context.Context, hash str
return tcs, nil
}

func (c *apiClient) TransactionRequiredSigners(ctx context.Context, hash string) (tm []TransactionRequiredSigner, err error) {
requestUrl, err := url.Parse(fmt.Sprintf("%s/%s/%s/%s", c.server, resourceTxs, hash, resourceTxRequiredSigners))
if err != nil {
return
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestUrl.String(), nil)
if err != nil {
return
}
res, err := c.handleRequest(req)
if err != nil {
return
}
defer res.Body.Close()
if err = json.NewDecoder(res.Body).Decode(&tm); err != nil {
return
}
return tm, nil
}

func (c *apiClient) TransactionSubmit(ctx context.Context, cbor []byte) (hash string, err error) {
requestUrl, err := url.Parse(fmt.Sprintf("%s/%s/%s", c.server, resourceTx, resourceTxSubmit))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ type APIClient interface {
TransactionMetadata(ctx context.Context, hash string) ([]TransactionMetadata, error)
TransactionMetadataInCBORs(ctx context.Context, hash string) ([]TransactionMetadataCbor, error)
TransactionRedeemers(ctx context.Context, hash string) ([]TransactionRedeemer, error)
TransactionRequiredSigners(ctx context.Context, hash string) ([]TransactionRequiredSigner, error)
TransactionDelegationCerts(ctx context.Context, hash string) ([]TransactionDelegation, error)
TransactionPoolUpdates(ctx context.Context, hash string) ([]TransactionPoolCert, error)
TransactionPoolUpdateCerts(ctx context.Context, hash string) ([]TransactionPoolCert, error)
Expand Down
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
const (
Major = 0
Minor = 2
Patch = 0
Patch = 1
Prerelease = ""
)

Expand Down

0 comments on commit a056107

Please sign in to comment.