Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions api_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ func TestTransactionContentUnmarshal(t *testing.T) {
testStructGotWant(t, fp, &got, &want)
}

func TestTransactionCBORUnmarshal(t *testing.T) {
want := blockfrost.TransactionCBOR{
Cbor: "83a40081825820c84dbd7b780ff9be2bcc6990f043030fe649342f9fa7ba1bfa6fb5c0079501a400018282582b82d818582183581cf810f5ffa3613a7edcc1e733d0d73c89645d02221648a031436fd840a0001a4f7ed7fd1a45bb41e082581d619fc8d50cd36af0e35f43db0e2f220e4ccb774925f2ef3542875b37701a000f4240021a00030d40031a00f9c7cca102818458205e3eb96f2cfd7844b5eed5498fe487fc5271178fb251ebf3d33c5d8f49036d9358403c9ef2ce22b8a3fce622472f84c932679f95e0f3e139378fe9d6ab5442c60a9b87de374a0bc37667b1bf8d5c6bffb436ffd84b0fa56a7c86342962b9c293390758208ed6ca9faabd8499f021c2e51745436c99f9eab6c92f4b09b255bdd9f39bae2a41a0f6",
}
fp := filepath.Join(testdata, "json", "transactions", "transaction_cbor.json")
got := blockfrost.TransactionCBOR{}
testStructGotWant(t, fp, &got, &want)
}

func TestTransactionStakeAddressCertUnmarshall(t *testing.T) {
fp := filepath.Join(testdata, "json", "transactions", "tx_stakeaddr_cert.json")
want := []blockfrost.TransactionStakeAddressCert{
Expand Down Expand Up @@ -118,6 +127,19 @@ func TestTransactionIntegration(t *testing.T) {
testIntUtil(t, fp, &got, &want)
}

func TestTransactionCBORIntegration(t *testing.T) {
hash := "6e5f825c82c1c6d6b77f2a14092f3b78c8f1b66db6f4cf8caec1555b6f967b3b"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})

got, err := api.TransactionCBOR(context.TODO(), hash)
if err != nil {
t.Fatal(err)
}
fp := filepath.Join(testdata, strings.ToLower(strings.TrimPrefix(t.Name(), "Test"))+".golden")
want := blockfrost.TransactionCBOR{}
testIntUtil(t, fp, &got, &want)
}

func TestTransactionUTXOs(t *testing.T) {
hash := "6d619f41ba2e11b78c0d5647fb71ee5df05622fda1748a9124446226e54e6b50"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
Expand Down Expand Up @@ -270,7 +292,6 @@ func TestTransactionPoolRetirementsIntegration(t *testing.T) {
}

func TestTransactionEvaluateIntegration(t *testing.T) {

api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
got, err := api.TransactionEvaluate(context.TODO(), tx_cbor)
if err != nil {
Expand All @@ -285,8 +306,8 @@ func TestTransactionEvaluateIntegration(t *testing.T) {

testIntUtil(t, fp, &got, &want)
}
func TestTransactionEvaluateUTXOsIntegration(t *testing.T) {

func TestTransactionEvaluateUTXOsIntegration(t *testing.T) {
additionalUtxoSet := blockfrost.AdditionalUtxoSet{
{
TxIn: blockfrost.AdditionalUtxoSetTxIn{
Expand Down
25 changes: 24 additions & 1 deletion api_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ type TransactionContent struct {
WithdrawalCount int `json:"withdrawal_count"`
}

type TransactionCBOR struct {
Cbor string `json:"cbor"`
}

type TxAmount struct {
// The quantity of the unit
Quantity string `json:"quantity"`
Expand Down Expand Up @@ -348,6 +352,26 @@ func (c *apiClient) Transaction(ctx context.Context, hash string) (tc Transactio
return tc, nil
}

func (c *apiClient) TransactionCBOR(ctx context.Context, hash string) (tc TransactionCBOR, err error) {
requestUrl, err := url.Parse(fmt.Sprintf("%s/%s/%s/%s", c.server, resourceTxs, hash, resourceCbor))
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(&tc); err != nil {
return
}
return tc, nil
}

func (c *apiClient) TransactionUTXOs(ctx context.Context, hash string) (tu TransactionUTXOs, err error) {
requestUrl, err := url.Parse(fmt.Sprintf("%s/%s/%s/%s", c.server, resourceTxs, hash, resourceTxUTXOs))
if err != nil {
Expand Down Expand Up @@ -611,7 +635,6 @@ func (c *apiClient) TransactionSubmit(ctx context.Context, cbor []byte) (hash st

func (c *apiClient) TransactionEvaluate(ctx context.Context, cbor []byte) (jsonResponse OgmiosResponse, err error) {
requestUrl, err := url.Parse(fmt.Sprintf("%s/%s", c.server, resourceTxEvaluate))

if err != nil {
return
}
Expand Down
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ type APIClient interface {
PoolUpdates(ctx context.Context, poolID string, query APIQueryParams) ([]PoolUpdate, error)
PoolUpdatesAll(ctx context.Context, poolId string) <-chan PoolUpdateResult
Transaction(ctx context.Context, hash string) (TransactionContent, error)
TransactionCBOR(ctx context.Context, hash string) (TransactionCBOR, error)
TransactionUTXOs(ctx context.Context, hash string) (TransactionUTXOs, error)
TransactionStakeAddressCerts(ctx context.Context, hash string) ([]TransactionStakeAddressCert, error)
TransactionWithdrawals(ctx context.Context, hash string) ([]TransactionWidthrawal, error)
Expand Down
3 changes: 3 additions & 0 deletions testdata/json/transactions/transaction_cbor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cbor": "83a40081825820c84dbd7b780ff9be2bcc6990f043030fe649342f9fa7ba1bfa6fb5c0079501a400018282582b82d818582183581cf810f5ffa3613a7edcc1e733d0d73c89645d02221648a031436fd840a0001a4f7ed7fd1a45bb41e082581d619fc8d50cd36af0e35f43db0e2f220e4ccb774925f2ef3542875b37701a000f4240021a00030d40031a00f9c7cca102818458205e3eb96f2cfd7844b5eed5498fe487fc5271178fb251ebf3d33c5d8f49036d9358403c9ef2ce22b8a3fce622472f84c932679f95e0f3e139378fe9d6ab5442c60a9b87de374a0bc37667b1bf8d5c6bffb436ffd84b0fa56a7c86342962b9c293390758208ed6ca9faabd8499f021c2e51745436c99f9eab6c92f4b09b255bdd9f39bae2a41a0f6"
}
3 changes: 3 additions & 0 deletions testdata/transactioncborintegration.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cbor": "83a4008282582041844abf9fa0e0fc46d630fbb3d99ae21e631387c14a366cec973bdfd1ca98aa00825820ef14f5a183dd72ca968a08a87ab3592dda7932fbba662be27e2a81db1906de2001018282584c82d818584283581c2ffe248da0231ec3c59674b11ae014a359c3d798a39edc02e11accefa101581e581ce6945e2c0be0cba471a1b08c798eb92a6b141b1db087bcda32ef1c75001ae11367521a9208088082584c82d818584283581cf2c29e3bebf516d2ac60216e65f08cec4f49e9cd78fbf4235d124fbaa101581e581c0ddde05acafb9f01b827c5b6439338b7f8a285dd04f17694dcfa26b7001a8642a97f1a0156df90021a0002c8d5031a00d3e1d9a10281845820748e425472fe2849e427571421036ec2ec8c5a5a3bf1cb53fdda52f99571360158407b3145eeabdf3faf7cc5fb396373b562506c20370670337bb934179781c61a2202546b6c0031f595d3092afe0e797c7ea4eea847f74a6a40caf2bc45e0587501582029cb5060793f932ba07669e6c0d38142df2ce5f6f031e0b9b50a197d7b1c8f495822a101581e581c0ddde05acafb9fd2050251b6adf0521e6e396c69f3b98b353fb69744f6"
}
Loading