load

package
v0.2.0-alpha.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PostLoaderConfig = dataloader.PostLoaderConfig{
	Wait:     2 * time.Millisecond,
	MaxBatch: 100,
	Fetch: func(txHashStrings []string) ([]*model.Post, []error) {
		var posts = make([]*model.Post, len(txHashStrings))
		var errors = make([]error, len(txHashStrings))
		for i, txHashString := range txHashStrings {
			txHash, err := chainhash.NewHashFromStr(txHashString)
			if err != nil {
				errors[i] = jerr.Get("error getting tx hash from string", err)
				continue
			}
			memoPost, err := memo.GetPost(*txHash)
			if err != nil && !client.IsEntryNotFoundError(err) {
				errors[i] = jerr.Get("error getting lock memo post", err)
				continue
			}
			if memoPost == nil {
				errors[i] = jerr.Getf(postNotFoundError, "error post not found: "+txHashString)
				continue
			}
			posts[i] = &model.Post{
				TxHash:  txHash.String(),
				Address: wallet.Addr(memoPost.Addr).String(),
				Text:    memoPost.Post,
			}
		}
		return posts, errors
	},
}
View Source
var ProfileLoaderConfig = dataloader.ProfileLoaderConfig{
	Wait:     2 * time.Millisecond,
	MaxBatch: 100,
	Fetch: func(addressStrings []string) ([]*model.Profile, []error) {
		var profiles = make([]*model.Profile, len(addressStrings))
		var errors = make([]error, len(addressStrings))
		ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
		defer cancel()
		for i, addressString := range addressStrings {
			addr, err := wallet.GetAddrFromString(addressString)
			if err != nil {
				errors[i] = jerr.Get("error getting address from string", err)
				continue
			}
			addrString := addr.String()
			var profile = &model.Profile{Address: addrString}
			addrMemoName, err := memo.GetAddrName(ctx, *addr)
			if err != nil && !client.IsEntryNotFoundError(err) {
				errors[i] = jerr.Get("error getting memo name", err)
				continue
			}
			if addrMemoName != nil {
				profile.Name = &model.SetName{
					TxHash:  chainhash.Hash(addrMemoName.TxHash).String(),
					Name:    addrMemoName.Name,
					Address: addrString,
				}
			}
			addrMemoProfile, err := memo.GetAddrProfile(ctx, *addr)
			if err != nil && !client.IsEntryNotFoundError(err) {
				errors[i] = jerr.Get("error getting addr memo profile", err)
				continue
			}
			if addrMemoProfile != nil {
				profile.Profile = &model.SetProfile{
					TxHash:  chainhash.Hash(addrMemoProfile.TxHash).String(),
					Text:    addrMemoProfile.Profile,
					Address: addrString,
				}
			}
			addrMemoProfilePic, err := memo.GetAddrProfilePic(ctx, *addr)
			if err != nil && !client.IsEntryNotFoundError(err) {
				errors[i] = jerr.Get("error getting addr memo profile pic", err)
				continue
			}
			if addrMemoProfilePic != nil {
				profile.Pic = &model.SetPic{
					TxHash:  chainhash.Hash(addrMemoProfilePic.TxHash).String(),
					Address: addrString,
					Pic:     addrMemoProfilePic.Pic,
				}
			}
			profiles[i] = profile
		}
		return profiles, errors
	},
}

Functions

func IsPostNotFoundError

func IsPostNotFoundError(err error) bool

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL