summaryrefslogtreecommitdiff
path: root/ledger/ledgercore/accountresource.go
blob: 4d22ec0dc1ac944d0a66b61f312ab9ce1ff22ea2 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand.  If not, see <https://www.gnu.org/licenses/>.

package ledgercore

import (
	"github.com/algorand/go-algorand/data/basics"
)

// AccountResource used to retrieve a generic resource information from the data tier
type AccountResource struct {
	AssetParams   *basics.AssetParams
	AssetHolding  *basics.AssetHolding
	AppLocalState *basics.AppLocalState
	AppParams     *basics.AppParams
}

// AssetResource used to retrieve a generic asset resource information from the data tier
type AssetResource struct {
	AssetParams  *basics.AssetParams
	AssetHolding *basics.AssetHolding
}

// AppResource used to retrieve a generic app resource information from the data tier
type AppResource struct {
	AppLocalState *basics.AppLocalState
	AppParams     *basics.AppParams
}

// AssignAccountResourceToAccountData assigns the Asset/App params/holdings contained
// in the AccountResource to the given basics.AccountData, creating maps if necessary.
// Returns true if the AccountResource contained a new or updated resource,
// and false if the AccountResource contained no changes (indicating the resource was deleted).
func AssignAccountResourceToAccountData(cindex basics.CreatableIndex, resource AccountResource, ad *basics.AccountData) (assigned bool) {
	if resource.AssetParams != nil {
		if ad.AssetParams == nil {
			ad.AssetParams = make(map[basics.AssetIndex]basics.AssetParams)
		}
		ad.AssetParams[basics.AssetIndex(cindex)] = *resource.AssetParams
		assigned = true
	}
	if resource.AssetHolding != nil {
		if ad.Assets == nil {
			ad.Assets = make(map[basics.AssetIndex]basics.AssetHolding)
		}
		ad.Assets[basics.AssetIndex(cindex)] = *resource.AssetHolding
		assigned = true
	}
	if resource.AppParams != nil {
		if ad.AppParams == nil {
			ad.AppParams = make(map[basics.AppIndex]basics.AppParams)
		}
		ad.AppParams[basics.AppIndex(cindex)] = *resource.AppParams
		assigned = true
	}
	if resource.AppLocalState != nil {
		if ad.AppLocalStates == nil {
			ad.AppLocalStates = make(map[basics.AppIndex]basics.AppLocalState)
		}
		ad.AppLocalStates[basics.AppIndex(cindex)] = *resource.AppLocalState
		assigned = true
	}
	return
}