This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
origination.go
61 lines (55 loc) · 1.62 KB
/
origination.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2020-2021 Blockwatch Data Inc.
// Author: alex@blockwatch.cc
package rpc
import (
"blockwatch.cc/tzgo/micheline"
"blockwatch.cc/tzgo/tezos"
)
// Ensure Origination implements the TypedOperation interface.
var _ TypedOperation = (*Origination)(nil)
// Origination represents a contract creation operation
type Origination struct {
Manager
ManagerPubkey tezos.Address `json:"manager_pubkey"` // proto v1 & >= v4
ManagerPubkey2 tezos.Address `json:"managerPubkey"` // proto v2, v3
Balance int64 `json:"balance,string"`
Spendable *bool `json:"spendable"` // true when missing before v5 Babylon
Delegatable *bool `json:"delegatable"` // true when missing before v5 Babylon
Delegate *tezos.Address `json:"delegate"`
Script *micheline.Script `json:"script"`
}
func (o Origination) ManagerAddress() tezos.Address {
if o.ManagerPubkey2.IsValid() {
return o.ManagerPubkey2
}
return o.ManagerPubkey
}
// Costs returns operation cost to implement TypedOperation interface.
func (o Origination) Costs() tezos.Costs {
res := o.Metadata.Result
cost := tezos.Costs{
Fee: o.Manager.Fee,
GasUsed: res.Gas(),
StorageUsed: res.PaidStorageSizeDiff,
}
var i int
for _, v := range res.BalanceUpdates {
if v.Kind != CONTRACT {
continue
}
if res.PaidStorageSizeDiff > 0 && i == 0 {
burn := v.Amount()
cost.StorageBurn += -burn
cost.Burn += -burn
i++
continue
}
if len(res.OriginatedContracts) > 0 && i == 1 {
burn := v.Amount()
cost.AllocationBurn += -burn
cost.Burn += -burn
i++
}
}
return cost
}