arweave

package
v0.2.90 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 28 Imported by: 2

Documentation

Index

Constants

View Source
const (
	HEIGHT_2_5 = int64(812970)
	HEIGHT_2_6 = int64(1132210)
	HEIGHT_2_7 = int64(1275480)
)
View Source
const (
	// Setting this flag disables retrying request with peers
	ContextDisablePeers = value("disablePeers")

	// Forces the URL of the peer, otherwise the default one is picked
	ContextForcePeer = value("forcePeer")

	//
	CancelFunc = value("cancelFunc")
)

Variables

View Source
var (
	ErrFailedToParse    = errors.New("failed to parse response")
	ErrBadResponse      = errors.New("bad response")
	ErrDataSizeMismatch = errors.New("data size mismatch")
	ErrNotFound         = errors.New("data not found")
	ErrPending          = errors.New("tx is pending")
	ErrOverspend        = errors.New("overspend")
)

Functions

func DeepHash

func DeepHash(data []any) [48]byte

Types

type Base64String

type Base64String []byte

func Base64StringFromBase64 added in v0.2.70

func Base64StringFromBase64(v string) (out Base64String, err error)

func (Base64String) Base64

func (self Base64String) Base64() string

func (Base64String) Bytes

func (self Base64String) Bytes() []byte

func (*Base64String) Decode

func (self *Base64String) Decode(s string) error

func (Base64String) Head

func (self Base64String) Head(i int) []byte

func (Base64String) MarshalJSON

func (self Base64String) MarshalJSON() (out []byte, err error)

func (*Base64String) MarshalTo added in v0.1.200

func (self *Base64String) MarshalTo(buf []byte) (n int, err error)

func (*Base64String) Scan

func (self *Base64String) Scan(src interface{}) error

func (Base64String) Size added in v0.1.200

func (self Base64String) Size() int

func (*Base64String) Unmarshal added in v0.1.200

func (self *Base64String) Unmarshal(buf []byte) error

func (*Base64String) UnmarshalJSON

func (self *Base64String) UnmarshalJSON(data []byte) error

func (Base64String) Value

func (self Base64String) Value() (driver.Value, error)

type BaseClient

type BaseClient struct {
	// contains filtered or unexported fields
}

func (*BaseClient) CleanupContext

func (self *BaseClient) CleanupContext(ctx context.Context) error

Converts HTTP status to errors

func (*BaseClient) GetCachedPeers added in v0.1.219

func (self *BaseClient) GetCachedPeers() []string

func (*BaseClient) Request

func (self *BaseClient) Request(ctx context.Context) (*resty.Request, context.CancelFunc)

func (*BaseClient) Reset

func (self *BaseClient) Reset()

func (*BaseClient) SetPeers

func (self *BaseClient) SetPeers(peers []string)

Set the list of potential peers in order they should be used Uses only peers that are proper urls

type BigInt

type BigInt struct {
	big.Int
	Valid bool
}

func (BigInt) MarshalJSON

func (b BigInt) MarshalJSON() ([]byte, error)

func (*BigInt) UnmarshalJSON

func (b *BigInt) UnmarshalJSON(p []byte) error

type Block

type Block struct {
	MerkleRebaseSupportThreshold BigInt         `json:"merkle_rebase_support_threshold"`
	ChunkHash                    Base64String   `json:"chunk_hash"`
	Chunk2Hash                   Base64String   `json:"chunk2_hash"`
	BlockTimeHistoryHash         Base64String   `json:"block_time_history_hash"`
	Nonce                        Base64String   `json:"nonce"`
	PreviousBlock                Base64String   `json:"previous_block"`
	Timestamp                    int64          `json:"timestamp"`
	LastRetarget                 int64          `json:"last_retarget"`
	Diff                         BigInt         `json:"diff"`
	Height                       int64          `json:"height"`
	Hash                         Base64String   `json:"hash"`
	IndepHash                    Base64String   `json:"indep_hash"`
	Txs                          []Base64String `json:"txs"`
	TxRoot                       Base64String   `json:"tx_root"`
	TxTree                       interface{}    `json:"tx_tree"`
	HashList                     interface{}    `json:"hash_list"`
	HashListMerkle               Base64String   `json:"hash_list_merkle"`
	WalletList                   Base64String   `json:"wallet_list"`
	RewardAddr                   RewardAddr     `json:"reward_addr"`
	Tags                         []interface{}  `json:"tags"`
	RewardPool                   BigInt         `json:"reward_pool"`
	WeaveSize                    BigInt         `json:"weave_size"`
	BlockSize                    BigInt         `json:"block_size"`
	CumulativeDiff               BigInt         `json:"cumulative_diff"`
	SizeTaggedTxs                interface{}    `json:"size_tagged_txs"`
	Poa                          POA            `json:"poa"`
	UsdToArRate                  []BigInt       `json:"usd_to_ar_rate"`
	ScheduledUsdToArRate         []BigInt       `json:"scheduled_usd_to_ar_rate"`
	Packing25Threshold           BigInt         `json:"packing_2_5_threshold"`
	StrictDataSplitThreshold     BigInt         `json:"strict_data_split_threshold"`

	// Fields added in v2.6
	HashPreimage                  Base64String       `json:"hash_preimage"`
	RecallByte                    BigInt             `json:"recall_byte"`
	Reward                        BigInt             `json:"reward"`
	PreviousSolutionHash          Base64String       `json:"previous_solution_hash"`
	PartitionNumber               uint64             `json:"partition_number"`
	NonceLimiterInfo              NonceLimiterInfo   `json:"nonce_limiter_info"`
	Poa2                          POA                `json:"poa2"`
	RecallByte2                   BigInt             `json:"recall_byte2"`
	Signature                     Base64String       `json:"signature"`
	RewardKey                     Base64String       `json:"reward_key"`
	PricePerGibMinute             BigInt             `json:"price_per_gib_minute"`
	ScheduledPricePerGibMinute    BigInt             `json:"scheduled_price_per_gib_minute"`
	RewardHistoryHash             Base64String       `json:"reward_history_hash"`
	DebtSupply                    BigInt             `json:"debt_supply"`
	KryderPlusRateMultiplier      BigInt             `json:"kryder_plus_rate_multiplier"`
	KryderPlusRateMultiplierLatch BigInt             `json:"kryder_plus_rate_multiplier_latch"`
	Denomination                  BigInt             `json:"denomination"`
	RedenominationHeight          uint64             `json:"redenomination_height"`
	DoubleSigningProof            DoubleSigningProof `json:"double_signing_proof"`
	PreviousCumulativeDiff        BigInt             `json:"previous_cumulative_diff"`
}

func (*Block) IsValid

func (b *Block) IsValid() bool

func (*Block) IsValid_2_5

func (b *Block) IsValid_2_5() bool

func (*Block) IsValid_2_6

func (b *Block) IsValid_2_6() bool

type Chunk

type Chunk struct {
	DataHash     []byte
	MinByteRange int
	MaxByteRange int
}

type ChunkData

type ChunkData struct {
	Chunk    Base64String `json:"chunk"`
	TxPath   string       `json:"tx_path"`
	DataPath string       `json:"data_path"`
}

type Chunks

type Chunks struct {
	DataRoot []byte   `json:"data_root"`
	Chunks   []Chunk  `json:"chunks"`
	Proofs   []*Proof `json:"proofs"`
}

type Client

type Client struct {
	*BaseClient
}

func NewClient

func NewClient(ctx context.Context, config *config.Config) (self *Client)

func (*Client) CheckPeerConnection

func (self *Client) CheckPeerConnection(ctx context.Context, peer string) (out *NetworkInfo, duration time.Duration, err error)

func (*Client) GetBlockByHash added in v0.2.40

func (self *Client) GetBlockByHash(ctx context.Context, hash string) (out *Block, resp *resty.Response, err error)

https://docs.arweave.org/developers/server/http-api#blocks

func (*Client) GetBlockByHeight

func (self *Client) GetBlockByHeight(ctx context.Context, height int64) (out *Block, resp *resty.Response, err error)

https://docs.arweave.org/developers/server/http-api#get-block-by-height

func (*Client) GetChunks

func (self *Client) GetChunks(ctx context.Context, tx *Transaction) (out bytes.Buffer, err error)

type DoubleSigningProof

type DoubleSigningProof struct {
	Key                     Base64String `json:"pub_key"`
	Sig1                    Base64String `json:"sig1"`
	CumulativeDiff1         BigInt       `json:"cdiff1"`
	PreviousCumulativeDiff1 BigInt       `json:"prev_cdiff1"`
	Preimage1               Base64String `json:"preimage1"`
	Sig2                    Base64String `json:"sig2"`
	CumulativeDiff2         BigInt       `json:"cdiff2"`
	PreviousCumulativeDiff2 BigInt       `json:"prev_cdiff2"`
	Preimage2               Base64String `json:"preimage2"`
}

func (DoubleSigningProof) Bytes

func (d DoubleSigningProof) Bytes() []byte

type Encoder

type Encoder struct {
	*bytes.Buffer
}

func NewEncoder

func NewEncoder() Encoder

func (Encoder) Base64

func (self Encoder) Base64() string

func (Encoder) RawWrite

func (self Encoder) RawWrite(val any)

func (Encoder) RawWriteBase64StringSlice

func (self Encoder) RawWriteBase64StringSlice(val []Base64String)

func (Encoder) RawWriteSize

func (self Encoder) RawWriteSize(val any, sizeBytes int)

func (Encoder) RawWriteUint64

func (self Encoder) RawWriteUint64(val uint64)

Erlang's binary:encode_unsigned

func (Encoder) Trim

func (self Encoder) Trim(val []byte) []byte

func (Encoder) Write

func (self Encoder) Write(val any, sizeBytes int)

func (Encoder) WriteBase64StringSlice

func (self Encoder) WriteBase64StringSlice(bins []Base64String, lenBytes, elemSizeBytes int)

func (Encoder) WriteBigInt

func (self Encoder) WriteBigInt(val BigInt, sizeBytes int)

Erlang's ar_serialize:encode_int but for big int

func (Encoder) WriteBuffer

func (self Encoder) WriteBuffer(val []byte, sizeBytes int)

Erlang's ar_serialize:encode_bin

func (Encoder) WriteSlice

func (self Encoder) WriteSlice(val any, lenBytes, elemSizeBytes int)

func (Encoder) WriteSliceAny

func (self Encoder) WriteSliceAny(bins []any, lenBytes, elemSizeBytes int)

func (Encoder) WriteSliceByte

func (self Encoder) WriteSliceByte(bins [][]byte, lenBytes, elemSizeBytes int)

func (Encoder) WriteUint

func (self Encoder) WriteUint(val uint, sizeBytes int)

func (Encoder) WriteUint16

func (self Encoder) WriteUint16(val uint16, sizeBytes int)

func (Encoder) WriteUint64

func (self Encoder) WriteUint64(val uint64, sizeBytes int)

Erlang's ar_serialize:encode_int

func (Encoder) WriteUint8

func (self Encoder) WriteUint8(val uint8, sizeBytes int)

type Error

type Error struct {
	Error string `json:"error"`
}

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Transforms all logs to debug

func NewLogger

func NewLogger(isForceTrace bool) (self *Logger)

func (*Logger) Debugf

func (self *Logger) Debugf(format string, v ...interface{})

func (*Logger) Errorf

func (self *Logger) Errorf(format string, v ...interface{})

func (*Logger) Warnf

func (self *Logger) Warnf(format string, v ...interface{})

type NetworkInfo

type NetworkInfo struct {
	Network          string `json:"network"`
	Version          int64  `json:"version"`
	Release          int64  `json:"release"`
	Height           int64  `json:"height"`
	Current          string `json:"current"`
	Blocks           int64  `json:"blocks"`
	Peers            int64  `json:"peers"`
	QueueLength      int64  `json:"queue_length"`
	NodeStateLatency int64  `json:"node_state_latency"`
}

type NonceLimiterInfo

type NonceLimiterInfo struct {
	Output              Base64String   `json:"output"`
	GlobalStepNumber    uint64         `json:"global_step_number"`
	Seed                Base64String   `json:"seed"`
	NextSeed            Base64String   `json:"next_seed"`
	ZoneUpperBound      uint64         `json:"zone_upper_bound"`
	NextZoneUpperBound  uint64         `json:"next_zone_upper_bound"`
	PrevOutput          Base64String   `json:"prev_output"`
	LastStepCheckpoints []Base64String `json:"last_step_checkpoints"`
	Checkpoints         []Base64String `json:"checkpoints"`
	VdfDifficulty       BigInt         `json:"vdf_difficulty"`
	NextVdfDifficulty   BigInt         `json:"next_vdf_difficulty"`
}

type OffsetInfo

type OffsetInfo struct {
	Offset BigInt `json:"offset"`
	Size   BigInt `json:"size"`
}

type POA

type POA struct {
	Option   string       `json:"option"`
	TxPath   Base64String `json:"tx_path"`
	DataPath Base64String `json:"data_path"`
	Chunk    Base64String `json:"chunk"`
}

type PeerList

type PeerList []string

type Proof

type Proof struct {
	Offest int
	Proof  []byte
}

type RewardAddr

type RewardAddr []byte

func (RewardAddr) Bytes

func (self RewardAddr) Bytes() []byte

func (*RewardAddr) IsUnclaimed

func (self *RewardAddr) IsUnclaimed() bool

func (*RewardAddr) UnmarshalJSON

func (self *RewardAddr) UnmarshalJSON(data []byte) error

type Tag

type Tag struct {
	Name  Base64String `json:"name"`
	Value Base64String `json:"value"`
}

type Transaction

type Transaction struct {
	Format    int          `json:"format"`
	ID        Base64String `json:"id"`
	LastTx    Base64String `json:"last_tx"`
	Owner     Base64String `json:"owner"` // utils.Base64Encode(wallet.PubKey.N.Bytes())
	Tags      []Tag        `json:"tags"`
	Target    Base64String `json:"target"`
	Quantity  string       `json:"quantity"`
	Data      Base64String `json:"data"`
	DataSize  BigInt       `json:"data_size"`
	DataRoot  Base64String `json:"data_root"`
	Reward    string       `json:"reward"`
	Signature Base64String `json:"signature"`

	// Computed when needed.
	Chunks *Chunks `json:"-"`
}

func (*Transaction) GetTag

func (tx *Transaction) GetTag(name string) (value string, ok bool)

func (Transaction) MarshalJSON added in v0.2.26

func (tx Transaction) MarshalJSON() ([]byte, error)

func (Transaction) MarshalTo added in v0.2.24

func (tx Transaction) MarshalTo(buf []byte) (int, error)

func (*Transaction) Size added in v0.2.24

func (tx *Transaction) Size() int

func (*Transaction) Unmarshal added in v0.2.24

func (tx *Transaction) Unmarshal(data []byte) error

func (*Transaction) UnmarshalJSON added in v0.2.26

func (tx *Transaction) UnmarshalJSON(data []byte) error

func (*Transaction) Verify

func (tx *Transaction) Verify() (err error)

https://docs.arweave.org/developers/server/http-api#transaction-signing Transaction signatures are generated by computing a merkle root of the SHA-384 hashes of transaction fields: format, owner, target, data_root, data_size, quantity, reward, last_tx, tags, then signing the hash. Signatures are RSA-PSS with SHA-256 as the hashing function.

Jump to

Keyboard shortcuts

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