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

Michelson.Typed.Origination

Synopsis

Documentation

data OriginationOperation Source #

Data necessary to originate a contract.

Constructors

forall cp st.(StorageScope st, ParameterScope cp) => OriginationOperation 

Fields

Operation hashing

newtype OperationHash Source #

Constructors

OperationHash 

Instances

Instances details
Eq OperationHash Source # 
Instance details

Defined in Michelson.Typed.Origination

Ord OperationHash Source # 
Instance details

Defined in Michelson.Typed.Origination

Show OperationHash Source # 
Instance details

Defined in Michelson.Typed.Origination

Generic OperationHash Source # 
Instance details

Defined in Michelson.Typed.Origination

Associated Types

type Rep OperationHash :: Type -> Type #

NFData OperationHash Source # 
Instance details

Defined in Michelson.Typed.Origination

Methods

rnf :: OperationHash -> () #

type Rep OperationHash Source # 
Instance details

Defined in Michelson.Typed.Origination

type Rep OperationHash = D1 ('MetaData "OperationHash" "Michelson.Typed.Origination" "morley-1.15.1-inplace" 'True) (C1 ('MetaCons "OperationHash" 'PrefixI 'True) (S1 ('MetaSel ('Just "unOperationHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

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.