morley-1.12.0: Developer tools for the Michelson Language
Safe HaskellNone
LanguageHaskell2010

Tezos.Address

Contents

Description

Address in Tezos.

Synopsis

Documentation

newtype ContractHash Source #

Hash of origination command for some contract.

Constructors

ContractHash ByteString 

Instances

Instances details
Eq ContractHash Source # 
Instance details

Defined in Tezos.Address

Ord ContractHash Source # 
Instance details

Defined in Tezos.Address

Show ContractHash Source # 
Instance details

Defined in Tezos.Address

Generic ContractHash Source # 
Instance details

Defined in Tezos.Address

Associated Types

type Rep ContractHash :: Type -> Type #

NFData ContractHash Source # 
Instance details

Defined in Tezos.Address

Methods

rnf :: ContractHash -> () #

type Rep ContractHash Source # 
Instance details

Defined in Tezos.Address

type Rep ContractHash = D1 ('MetaData "ContractHash" "Tezos.Address" "morley-1.12.0-inplace" 'True) (C1 ('MetaCons "ContractHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

data Address Source #

Data type corresponding to address structure in Tezos.

Constructors

KeyAddress KeyHash

tz address which is a hash of a public key.

ContractAddress ContractHash

KT address which corresponds to a callable contract.

Instances

Instances details
Eq Address Source # 
Instance details

Defined in Tezos.Address

Methods

(==) :: Address -> Address -> Bool #

(/=) :: Address -> Address -> Bool #

Ord Address Source # 
Instance details

Defined in Tezos.Address

Show Address Source # 
Instance details

Defined in Tezos.Address

Generic Address Source # 
Instance details

Defined in Tezos.Address

Associated Types

type Rep Address :: Type -> Type #

Methods

from :: Address -> Rep Address x #

to :: Rep Address x -> Address #

ToJSON Address Source # 
Instance details

Defined in Tezos.Address

ToJSONKey Address Source # 
Instance details

Defined in Tezos.Address

FromJSON Address Source # 
Instance details

Defined in Tezos.Address

FromJSONKey Address Source # 
Instance details

Defined in Tezos.Address

NFData Address Source # 
Instance details

Defined in Tezos.Address

Methods

rnf :: Address -> () #

Buildable Address Source # 
Instance details

Defined in Tezos.Address

Methods

build :: Address -> Builder #

HasCLReader Address Source # 
Instance details

Defined in Tezos.Address

IsoValue Address Source # 
Instance details

Defined in Michelson.Typed.Haskell.Value

Associated Types

type ToT Address :: T Source #

TypeHasDoc Address Source # 
Instance details

Defined in Michelson.Typed.Haskell.Doc

type Rep Address Source # 
Instance details

Defined in Tezos.Address

type ToT Address Source # 
Instance details

Defined in Michelson.Typed.Haskell.Value

type TypeDocFieldDescriptions Address Source # 
Instance details

Defined in Michelson.Typed.Haskell.Doc

mkKeyAddress :: PublicKey -> Address Source #

Smart constructor for KeyAddress.

detGenKeyAddress :: ByteString -> Address Source #

Deterministically generate a random KeyAddress and discard its secret key.

newtype OperationHash Source #

Constructors

OperationHash 

Instances

Instances details
Eq OperationHash Source # 
Instance details

Defined in Tezos.Address

Ord OperationHash Source # 
Instance details

Defined in Tezos.Address

Show OperationHash Source # 
Instance details

Defined in Tezos.Address

Generic OperationHash Source # 
Instance details

Defined in Tezos.Address

Associated Types

type Rep OperationHash :: Type -> Type #

NFData OperationHash Source # 
Instance details

Defined in Tezos.Address

Methods

rnf :: OperationHash -> () #

type Rep OperationHash Source # 
Instance details

Defined in Tezos.Address

type Rep OperationHash = D1 ('MetaData "OperationHash" "Tezos.Address" "morley-1.12.0-inplace" 'True) (C1 ('MetaCons "OperationHash" 'PrefixI 'True) (S1 ('MetaSel ('Just "unOperationHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

newtype OriginationIndex Source #

When a transfer operation triggers multiple CREATE_CONTRACT instructions, using GlobalCounter to compute those contracts' addresses is not enough to ensure their uniqueness.

For that reason, we also keep track of an OriginationIndex that starts out as 0 when a transfer is initiated, and is incremented every time a CREATE_CONTRACT instruction is interpreted.

See mkContractAddress.

Constructors

OriginationIndex 

Instances

Instances details
Eq OriginationIndex Source # 
Instance details

Defined in Tezos.Address

Ord OriginationIndex Source # 
Instance details

Defined in Tezos.Address

Show OriginationIndex Source # 
Instance details

Defined in Tezos.Address

Generic OriginationIndex Source # 
Instance details

Defined in Tezos.Address

Associated Types

type Rep OriginationIndex :: Type -> Type #

NFData OriginationIndex Source # 
Instance details

Defined in Tezos.Address

Methods

rnf :: OriginationIndex -> () #

type Rep OriginationIndex Source # 
Instance details

Defined in Tezos.Address

type Rep OriginationIndex = D1 ('MetaData "OriginationIndex" "Tezos.Address" "morley-1.12.0-inplace" 'True) (C1 ('MetaCons "OriginationIndex" 'PrefixI 'True) (S1 ('MetaSel ('Just "unOriginationIndex") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int32)))

newtype GlobalCounter Source #

Represents the network's global counter.

When a new contract is created (either via a "global" origination operation or via a CREATE_CONTRACT instruction), this counter is used to create a new address for it (see mkContractAddress).

The counter is incremented after every operation, and thus ensures that these addresses are unique (i.e. origination of identical contracts with identical metadata will result in different addresses.)

In Tezos each operation has a special field called counter, see here: https://gitlab.com/tezos/tezos/-/blob/397dd233a10cc6df0df959e2a624c7947997dd0c/src/proto_006_PsCARTHA/lib_protocol/operation_repr.ml#L113-120

This counter seems to be a part of global state of Tezos network. In fact, it may be observed in raw JSON representation of the operation in the network explorer.

Our counter is represented as Word64, while in Tezos it is unbounded. We believe that for our interpreter it should not matter.

Constructors

GlobalCounter 

Instances

Instances details
Eq GlobalCounter Source # 
Instance details

Defined in Tezos.Address

Num GlobalCounter Source # 
Instance details

Defined in Tezos.Address

Show GlobalCounter Source # 
Instance details

Defined in Tezos.Address

Generic GlobalCounter Source # 
Instance details

Defined in Tezos.Address

Associated Types

type Rep GlobalCounter :: Type -> Type #

ToJSON GlobalCounter Source # 
Instance details

Defined in Tezos.Address

FromJSON GlobalCounter Source # 
Instance details

Defined in Tezos.Address

NFData GlobalCounter Source # 
Instance details

Defined in Tezos.Address

Methods

rnf :: GlobalCounter -> () #

type Rep GlobalCounter Source # 
Instance details

Defined in Tezos.Address

type Rep GlobalCounter = D1 ('MetaData "GlobalCounter" "Tezos.Address" "morley-1.12.0-inplace" 'True) (C1 ('MetaCons "GlobalCounter" 'PrefixI 'True) (S1 ('MetaSel ('Just "unGlobalCounter") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

mkContractAddress :: OperationHash -> OriginationIndex -> GlobalCounter -> Address Source #

Compute address of a contract from its origination operation, origination index and global counter.

However, in real Tezos encoding of the operation is more than just OriginationOperation. There an Operation has several more meta-fields plus a big sum-type of all possible operations.

See here: https://gitlab.com/tezos/tezos/-/blob/f57c50e3a657956d69a1699978de9873c98f0018/src/proto_006_PsCARTHA/lib_protocol/operation_repr.ml#L78

What is important is that one (big) Operation may lead to origination of multiple contracts. That is why contract address is constructed from hash of the operation that originated and of index of the contract's origination in the execution of that operation.

In other words, contract hash is calculated as the blake2b160 (20-byte) hash of origination operation hash + int32 origination index + word64 global counter.

In Morley we do not yet support full encoding of Tezos Operations, therefore we choose to generate contract addresses in a simplified manner.

Namely, we encode OriginationOperation as we can and concat it with the origination index and the global counter. Then we take blake2b160 hash of the resulting bytes and consider it to be the contract's address.

mkContractHashHack :: ByteString -> ContractHash Source #

Create a dummy ContractHash value by hashing given ByteString.

Use in tests **only**.

Formatting

data ParseAddressError Source #

Errors that can happen during address parsing.

Constructors

ParseAddressWrongBase58Check

Address is not in Base58Check format.

ParseAddressBothFailed CryptoParseError ParseContractAddressError

Both address parsers failed with some error.

Instances

Instances details
Eq ParseAddressError Source # 
Instance details

Defined in Tezos.Address

Show ParseAddressError Source # 
Instance details

Defined in Tezos.Address

Generic ParseAddressError Source # 
Instance details

Defined in Tezos.Address

Associated Types

type Rep ParseAddressError :: Type -> Type #

NFData ParseAddressError Source # 
Instance details

Defined in Tezos.Address

Methods

rnf :: ParseAddressError -> () #

Buildable ParseAddressError Source # 
Instance details

Defined in Tezos.Address

type Rep ParseAddressError Source # 
Instance details

Defined in Tezos.Address

type Rep ParseAddressError = D1 ('MetaData "ParseAddressError" "Tezos.Address" "morley-1.12.0-inplace" 'False) (C1 ('MetaCons "ParseAddressWrongBase58Check" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ParseAddressBothFailed" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 CryptoParseError) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ParseContractAddressError)))

data ParseAddressRawError Source #

Constructors

ParseAddressRawWrongSize ByteString

Raw bytes representation of an address has invalid length.

ParseAddressRawInvalidPrefix ByteString

Raw bytes representation of an address has incorrect prefix.

ParseAddressRawMalformedSeparator ByteString

Raw bytes representation of an address does not end with "00".

Instances

Instances details
Eq ParseAddressRawError Source # 
Instance details

Defined in Tezos.Address

Show ParseAddressRawError Source # 
Instance details

Defined in Tezos.Address

Generic ParseAddressRawError Source # 
Instance details

Defined in Tezos.Address

Associated Types

type Rep ParseAddressRawError :: Type -> Type #

NFData ParseAddressRawError Source # 
Instance details

Defined in Tezos.Address

Methods

rnf :: ParseAddressRawError -> () #

Buildable ParseAddressRawError Source # 
Instance details

Defined in Tezos.Address

type Rep ParseAddressRawError Source # 
Instance details

Defined in Tezos.Address

type Rep ParseAddressRawError = D1 ('MetaData "ParseAddressRawError" "Tezos.Address" "morley-1.12.0-inplace" 'False) (C1 ('MetaCons "ParseAddressRawWrongSize" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ByteString)) :+: (C1 ('MetaCons "ParseAddressRawInvalidPrefix" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ByteString)) :+: C1 ('MetaCons "ParseAddressRawMalformedSeparator" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ByteString))))

data ParseContractAddressError Source #

Instances

Instances details
Eq ParseContractAddressError Source # 
Instance details

Defined in Tezos.Address

Show ParseContractAddressError Source # 
Instance details

Defined in Tezos.Address

Generic ParseContractAddressError Source # 
Instance details

Defined in Tezos.Address

Associated Types

type Rep ParseContractAddressError :: Type -> Type #

NFData ParseContractAddressError Source # 
Instance details

Defined in Tezos.Address

Buildable ParseContractAddressError Source # 
Instance details

Defined in Tezos.Address

type Rep ParseContractAddressError Source # 
Instance details

Defined in Tezos.Address

type Rep ParseContractAddressError = D1 ('MetaData "ParseContractAddressError" "Tezos.Address" "morley-1.12.0-inplace" 'False) (C1 ('MetaCons "ParseContractAddressWrongBase58Check" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "ParseContractAddressWrongSize" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ByteString)) :+: C1 ('MetaCons "ParseContractAddressWrongPrefix" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ByteString))))

parseAddressRaw :: ByteString -> Either ParseAddressRawError Address Source #

Parse the given address in its raw byte form used by Tezos (e.g "01521139f84791537d54575df0c74a8084cc68861c00")) . Or fail otherwise if it's invalid.

parseAddress :: Text -> Either ParseAddressError Address Source #

Parse an address from its human-readable textual representation used by Tezos (e. g. "tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU"). Or fail if it's invalid.

unsafeParseAddressRaw :: ByteString -> Address Source #

Partially parse raw bytes representation of an address and assume that it is correct from the beginning. Can be used in tests.

unsafeParseAddress :: HasCallStack => Text -> Address Source #

Partial version of parseAddress which assumes that the address is correct. Can be used in tests.

unsafeParseContractHash :: HasCallStack => Text -> ContractHash Source #

Parse a KT1 contract address, fail if address does not match the expected format.