Skip to content

Commit

Permalink
[PSL-1193]
Browse files Browse the repository at this point in the history
  • Loading branch information
Matee Ullah authored and Matee Ullah committed Jun 26, 2024
1 parent 11ad8c2 commit d31d465
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pastel/cascade_multi_volume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pastel

type CascadeMultiVolumeTicket struct {
ID string `json:"id"`
HumanReadableIdentifier string `json:"human_readable_identifier"`
SHA3256HashOfOriginalFile string `json:"sha3_256_hash_of_original_file"`
Volumes map[string]string `json:"volumes"`
}
28 changes: 28 additions & 0 deletions pastel/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pastel
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"net"
"strconv"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/pastelnetwork/gonode/common/errors"
"github.com/pastelnetwork/gonode/common/log"
"github.com/pastelnetwork/gonode/pastel/jsonrpc"
"github.com/pastelnetwork/gonode/common/utils"
)

const (
Expand Down Expand Up @@ -531,6 +533,32 @@ func (client *client) RegisterActionTicket(ctx context.Context, request Register
return txID.TxID, nil
}

func (client *client) RegisterCascadeMultiVolumeTicket(ctx context.Context, ticket CascadeMultiVolumeTicket) (string, error){
ticketJSON, err := json.Marshal(ticket)
if err != nil {
return "", errors.Errorf("failed to call register action ticket: %w", err)
}
ticketBlob := base64.StdEncoding.EncodeToString(ticketJSON)

hash, _ := utils.Sha3256hash(ticketJSON)
// Assuming some additional data or parameters are needed, similar to the RegisterNFTRequest example
params := []interface{}{
"register",
"contract",
ticketBlob,
ticket.ID,
hash,
}

resp := make(map[string]interface{})
if err := client.callFor(ctx, &resp, "tickets", params...); err != nil {
return "", errors.Errorf("failed to call register contract: %w", err)
}
log.WithContext(ctx).WithField("resp", resp).WithField("txid", ticket.ID).Info("RegisterCascadeMultiVolumeTicket Response")

return ticket.ID, nil
}

func (client *client) ActivateActionTicket(ctx context.Context, request ActivateActionRequest) (string, error) {
var txID struct {
TxID string `json:"txid"`
Expand Down
3 changes: 3 additions & 0 deletions pastel/pastel.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,7 @@ type Client interface {
//NFTStorageFee returns the fee of NFT storage
//Command `tickets tools estimatenftstoragefee <sizeInMB>`
NFTStorageFee(ctx context.Context, sizeInMB int) (*NFTStorageFeeEstimate, error)

// RegisterCascadeMultiVolumeTicket registers a cascade multi-volume ticket
RegisterCascadeMultiVolumeTicket(ctx context.Context, ticket CascadeMultiVolumeTicket) (string, error)
}

0 comments on commit d31d465

Please sign in to comment.