forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
account_create_transaction.go
122 lines (101 loc) · 6.28 KB
/
account_create_transaction.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package hedera
import (
"time"
"github.com/hashgraph/hedera-sdk-go/proto"
)
// AccountCreateTransaction creates a new account. After the account is created, the AccountID for it is in the receipt,
// or by asking for a Record of the transaction to be created, and retrieving that. The account can then automatically
// generate records for large transfers into it or out of it, which each last for 25 hours. Records are generated for
// any transfer that exceeds the thresholds given here. This account is charged hbar for each record generated, so the
// thresholds are useful for limiting Record generation to happen only for large transactions.
//
// The current API ignores shardID, realmID, and newRealmAdminKey, and creates everything in shard 0 and realm 0,
// with a null key. Future versions of the API will support multiple realms and multiple shards.
type AccountCreateTransaction struct {
TransactionBuilder
pb *proto.CryptoCreateTransactionBody
}
// NewAccountCreateTransaction creates an AccountCreateTransaction builder which can be used to construct and
// execute a Crypto Create Transaction.
func NewAccountCreateTransaction() AccountCreateTransaction {
pb := &proto.CryptoCreateTransactionBody{}
inner := newTransactionBuilder()
inner.pb.Data = &proto.TransactionBody_CryptoCreateAccount{CryptoCreateAccount: pb}
builder := AccountCreateTransaction{inner, pb}
builder.SetAutoRenewPeriod(7890000 * time.Second)
// Default to maximum values for record thresholds. Without this records would be
// auto-created whenever a send or receive transaction takes place for this new account.
// This should be an explicit ask.
builder.SetReceiveRecordThreshold(MaxHbar)
builder.SetSendRecordThreshold(MaxHbar)
return builder
}
// SetKey sets the key that must sign each transfer out of the account. If RecieverSignatureRequired is true, then it
// must also sign any transfer into the account.
func (builder AccountCreateTransaction) SetKey(publicKey PublicKey) AccountCreateTransaction {
builder.pb.Key = publicKey.toProto()
return builder
}
// SetInitialBalance sets the initial number of Hbar to put into the account
func (builder AccountCreateTransaction) SetInitialBalance(initialBalance Hbar) AccountCreateTransaction {
builder.pb.InitialBalance = uint64(initialBalance.AsTinybar())
return builder
}
// SetAutoRenewPeriod sets the time duration for when account is charged to extend its expiration date. When the account
// is created, the payer account is charged enough hbars so that the new account will not expire for the next
// auto renew period. When it reaches the expiration time, the new account will then be automatically charged to
// renew for another auto renew period. If it does not have enough hbars to renew for that long, then the remaining
// hbars are used to extend its expiration as long as possible. If it is has a zero balance when it expires,
// then it is deleted.
func (builder AccountCreateTransaction) SetAutoRenewPeriod(autoRenewPeriod time.Duration) AccountCreateTransaction {
builder.pb.AutoRenewPeriod = durationToProto(autoRenewPeriod)
return builder
}
// SetSendRecordThreshold sets the threshold amount for which an account record is created for any send/withdraw
// transaction
func (builder AccountCreateTransaction) SetSendRecordThreshold(recordThreshold Hbar) AccountCreateTransaction {
builder.pb.SendRecordThreshold = uint64(recordThreshold.AsTinybar())
return builder
}
// SetReceiveRecordThreshold sets the threshold amount for which an account record is created for any receive/deposit
// transaction
func (builder AccountCreateTransaction) SetReceiveRecordThreshold(recordThreshold Hbar) AccountCreateTransaction {
builder.pb.ReceiveRecordThreshold = uint64(recordThreshold.AsTinybar())
return builder
}
// SetProxyAccountID sets the ID of the account to which this account is proxy staked. If proxyAccountID is not set,
// is an invalid account, or is an account that isn't a node, then this account is automatically proxy staked to a node
// chosen by the network, but without earning payments. If the proxyAccountID account refuses to accept proxy staking ,
// or if it is not currently running a node, then it will behave as if proxyAccountID was not set.
func (builder AccountCreateTransaction) SetProxyAccountID(id AccountID) AccountCreateTransaction {
builder.pb.ProxyAccountID = id.toProto()
return builder
}
// SetReceiverSignatureRequired sets the receiverSigRequired flag. If the receiverSigRequired flag is set to true, then
// all cryptocurrency transfers must be signed by this account's key, both for transfers in and out. If it is false,
// then only transfers out have to be signed by it. This transaction must be signed by the
// payer account. If receiverSigRequired is false, then the transaction does not have to be signed by the keys in the
// keys field. If it is true, then it must be signed by them, in addition to the keys of the payer account.
func (builder AccountCreateTransaction) SetReceiverSignatureRequired(required bool) AccountCreateTransaction {
builder.pb.ReceiverSigRequired = required
return builder
}
//
// The following _5_ must be copy-pasted at the bottom of **every** _transaction.go file
// We override the embedded fluent setter methods to return the outer type
//
func (builder AccountCreateTransaction) SetMaxTransactionFee(maxTransactionFee Hbar) AccountCreateTransaction {
return AccountCreateTransaction{builder.TransactionBuilder.SetMaxTransactionFee(maxTransactionFee), builder.pb}
}
func (builder AccountCreateTransaction) SetTransactionMemo(memo string) AccountCreateTransaction {
return AccountCreateTransaction{builder.TransactionBuilder.SetTransactionMemo(memo), builder.pb}
}
func (builder AccountCreateTransaction) SetTransactionValidDuration(validDuration time.Duration) AccountCreateTransaction {
return AccountCreateTransaction{builder.TransactionBuilder.SetTransactionValidDuration(validDuration), builder.pb}
}
func (builder AccountCreateTransaction) SetTransactionID(transactionID TransactionID) AccountCreateTransaction {
return AccountCreateTransaction{builder.TransactionBuilder.SetTransactionID(transactionID), builder.pb}
}
func (builder AccountCreateTransaction) SetNodeAccountID(nodeAccountID AccountID) AccountCreateTransaction {
return AccountCreateTransaction{builder.TransactionBuilder.SetNodeAccountID(nodeAccountID), builder.pb}
}