-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement various queries and transactions
- Loading branch information
1 parent
bcbbfb2
commit 9849aed
Showing
16 changed files
with
943 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package hedera | ||
|
||
import ( | ||
"github.com/hashgraph/hedera-sdk-go/proto" | ||
"time" | ||
) | ||
|
||
type AccountDeleteTransaction struct { | ||
TransactionBuilder | ||
pb *proto.CryptoDeleteTransactionBody | ||
} | ||
|
||
func NewAccountDeleteTransaction() AccountDeleteTransaction { | ||
pb := &proto.CryptoDeleteTransactionBody{} | ||
|
||
inner := newTransactionBuilder() | ||
inner.pb.Data = &proto.TransactionBody_CryptoDelete{pb} | ||
|
||
builder := AccountDeleteTransaction{inner, pb} | ||
|
||
return builder | ||
} | ||
|
||
func (builder AccountDeleteTransaction) SetAccountId(id AccountID) AccountDeleteTransaction { | ||
builder.pb.DeleteAccountID = id.toProto() | ||
return builder | ||
} | ||
|
||
func (builder AccountDeleteTransaction) Build(client *Client) Transaction { | ||
return builder.TransactionBuilder.Build(client) | ||
} | ||
|
||
// | ||
// 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 AccountDeleteTransaction) SetMaxTransactionFee(maxTransactionFee uint64) AccountDeleteTransaction { | ||
return AccountDeleteTransaction{builder.TransactionBuilder.SetMaxTransactionFee(maxTransactionFee), builder.pb} | ||
} | ||
|
||
func (builder AccountDeleteTransaction) SetMemo(memo string) AccountDeleteTransaction { | ||
return AccountDeleteTransaction{builder.TransactionBuilder.SetMemo(memo), builder.pb} | ||
} | ||
|
||
func (builder AccountDeleteTransaction) SetTransactionValidDuration(validDuration time.Duration) AccountDeleteTransaction { | ||
return AccountDeleteTransaction{builder.TransactionBuilder.SetTransactionValidDuration(validDuration), builder.pb} | ||
} | ||
|
||
func (builder AccountDeleteTransaction) SetTransactionID(transactionID TransactionID) AccountDeleteTransaction { | ||
return AccountDeleteTransaction{builder.TransactionBuilder.SetTransactionID(transactionID), builder.pb} | ||
} | ||
|
||
func (builder AccountDeleteTransaction) SetNodeAccountID(nodeAccountID AccountID) AccountDeleteTransaction { | ||
return AccountDeleteTransaction{builder.TransactionBuilder.SetNodeAccountID(nodeAccountID), builder.pb} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package hedera | ||
|
||
import ( | ||
"github.com/hashgraph/hedera-sdk-go/proto" | ||
"time" | ||
) | ||
|
||
type AccountInfoQuery struct { | ||
QueryBuilder | ||
pb *proto.CryptoGetInfoQuery | ||
} | ||
|
||
type AccountInfo struct { | ||
AccountID AccountID | ||
ContractAccountID string | ||
Deleted bool | ||
ProxyAccountID AccountID | ||
ProxyReceived int64 | ||
Key Ed25519PublicKey | ||
Balance uint64 | ||
GenerateSendRecordThreshold uint64 | ||
GenerateReceiveRecordThreshold uint64 | ||
ReceiverSigRequired bool | ||
ExpirationTime time.Time | ||
AutoRenewPeriod time.Duration | ||
} | ||
|
||
func NewAccountInfoQuery() *AccountInfoQuery { | ||
pb := &proto.CryptoGetInfoQuery{Header: &proto.QueryHeader{}} | ||
|
||
inner := newQueryBuilder(pb.Header) | ||
inner.pb.Query = &proto.Query_CryptoGetInfo{pb} | ||
|
||
return &AccountInfoQuery{inner, pb} | ||
} | ||
|
||
func (builder *AccountInfoQuery) SetAccountID(id AccountID) *AccountInfoQuery { | ||
builder.pb.AccountID = id.toProto() | ||
return builder | ||
} | ||
|
||
func (builder *AccountInfoQuery) Execute(client *Client) (AccountInfo, error) { | ||
resp, err := builder.execute(client) | ||
if err != nil { | ||
return AccountInfo{}, err | ||
} | ||
|
||
return AccountInfo{ | ||
AccountID: accountIDFromProto(resp.GetCryptoGetInfo().AccountInfo.AccountID), | ||
ContractAccountID: resp.GetCryptoGetInfo().AccountInfo.ContractAccountID, | ||
Deleted: resp.GetCryptoGetInfo().AccountInfo.Deleted, | ||
ProxyAccountID: accountIDFromProto(resp.GetCryptoGetInfo().AccountInfo.ProxyAccountID), | ||
ProxyReceived: resp.GetCryptoGetInfo().AccountInfo.ProxyReceived, | ||
Key: Ed25519PublicKey{keyData: resp.GetCryptoGetInfo().AccountInfo.Key.GetEd25519()}, | ||
Balance: resp.GetCryptoGetInfo().AccountInfo.Balance, | ||
GenerateSendRecordThreshold: resp.GetCryptoGetInfo().AccountInfo.GenerateSendRecordThreshold, | ||
GenerateReceiveRecordThreshold: resp.GetCryptoGetInfo().AccountInfo.GenerateReceiveRecordThreshold, | ||
ReceiverSigRequired: resp.GetCryptoGetInfo().AccountInfo.ReceiverSigRequired, | ||
ExpirationTime: timeFromProto(resp.GetCryptoGetInfo().AccountInfo.ExpirationTime), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package hedera | ||
|
||
import ( | ||
"github.com/hashgraph/hedera-sdk-go/proto" | ||
"time" | ||
) | ||
|
||
type AccountUpdateTransaction struct { | ||
TransactionBuilder | ||
pb *proto.CryptoUpdateTransactionBody | ||
} | ||
|
||
func NewAccountUpdateTransaction() AccountUpdateTransaction { | ||
pb := &proto.CryptoUpdateTransactionBody{} | ||
|
||
inner := newTransactionBuilder() | ||
inner.pb.Data = &proto.TransactionBody_CryptoUpdateAccount{pb} | ||
|
||
builder := AccountUpdateTransaction{inner, pb} | ||
|
||
return builder | ||
} | ||
|
||
func (builder AccountUpdateTransaction) SetAccountID(id AccountID) AccountUpdateTransaction { | ||
builder.pb.AccountIDToUpdate = id.toProto() | ||
return builder | ||
} | ||
|
||
func (builder AccountUpdateTransaction) SetKey(publicKey Ed25519PublicKey) AccountUpdateTransaction { | ||
builder.pb.Key = publicKey.toProto() | ||
return builder | ||
} | ||
|
||
func (builder AccountUpdateTransaction) SetProxyAccountID(id AccountID) AccountUpdateTransaction { | ||
builder.pb.ProxyAccountID = id.toProto() | ||
return builder | ||
} | ||
|
||
func (builder AccountUpdateTransaction) SetAutoRenewPeriod(autoRenewPeriod time.Duration) AccountUpdateTransaction { | ||
builder.pb.AutoRenewPeriod = durationToProto(autoRenewPeriod) | ||
return builder | ||
} | ||
|
||
func (builder AccountUpdateTransaction) SetExpirationTime(expiration time.Time) AccountUpdateTransaction { | ||
builder.pb.ExpirationTime = timeToProto(expiration) | ||
return builder | ||
} | ||
|
||
func (builder AccountUpdateTransaction) Build(client *Client) Transaction { | ||
return builder.TransactionBuilder.Build(client) | ||
} | ||
|
||
// | ||
// 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 AccountUpdateTransaction) SetMaxTransactionFee(maxTransactionFee uint64) AccountUpdateTransaction { | ||
return AccountUpdateTransaction{builder.TransactionBuilder.SetMaxTransactionFee(maxTransactionFee), builder.pb} | ||
} | ||
|
||
func (builder AccountUpdateTransaction) SetMemo(memo string) AccountUpdateTransaction { | ||
return AccountUpdateTransaction{builder.TransactionBuilder.SetMemo(memo), builder.pb} | ||
} | ||
|
||
func (builder AccountUpdateTransaction) SetTransactionValidDuration(validDuration time.Duration) AccountUpdateTransaction { | ||
return AccountUpdateTransaction{builder.TransactionBuilder.SetTransactionValidDuration(validDuration), builder.pb} | ||
} | ||
|
||
func (builder AccountUpdateTransaction) SetTransactionID(transactionID TransactionID) AccountUpdateTransaction { | ||
return AccountUpdateTransaction{builder.TransactionBuilder.SetTransactionID(transactionID), builder.pb} | ||
} | ||
|
||
func (builder AccountUpdateTransaction) SetNodeAccountID(nodeAccountID AccountID) AccountUpdateTransaction { | ||
return AccountUpdateTransaction{builder.TransactionBuilder.SetNodeAccountID(nodeAccountID), builder.pb} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package hedera | ||
|
||
import ( | ||
"github.com/hashgraph/hedera-sdk-go/proto" | ||
"time" | ||
) | ||
|
||
type ContractExecuteTransaction struct { | ||
TransactionBuilder | ||
pb *proto.ContractCallTransactionBody | ||
} | ||
|
||
func NewContractExecuteTransaction() ContractExecuteTransaction { | ||
pb := &proto.ContractCallTransactionBody{} | ||
|
||
inner := newTransactionBuilder() | ||
inner.pb.Data = &proto.TransactionBody_ContractCall{pb} | ||
|
||
builder := ContractExecuteTransaction{inner, pb} | ||
|
||
return builder | ||
} | ||
|
||
func (builder ContractExecuteTransaction) SetContractID(id ContractID) ContractExecuteTransaction { | ||
builder.pb.ContractID = id.toProto() | ||
return builder | ||
} | ||
|
||
func (builder ContractExecuteTransaction) SetGas(gas uint64) ContractExecuteTransaction { | ||
builder.pb.Gas = int64(gas) | ||
return builder | ||
} | ||
|
||
func (builder ContractExecuteTransaction) SetAmount(amount uint64) ContractExecuteTransaction { | ||
builder.pb.Amount = int64(amount) | ||
return builder | ||
} | ||
|
||
func (builder ContractExecuteTransaction) SetFunctionParameters(params []byte) ContractExecuteTransaction { | ||
builder.pb.FunctionParameters = params | ||
return builder | ||
} | ||
|
||
func (builder ContractExecuteTransaction) Build(client *Client) Transaction { | ||
return builder.TransactionBuilder.Build(client) | ||
} | ||
|
||
// | ||
// 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 ContractExecuteTransaction) SetMaxTransactionFee(maxTransactionFee uint64) ContractExecuteTransaction { | ||
return ContractExecuteTransaction{builder.TransactionBuilder.SetMaxTransactionFee(maxTransactionFee), builder.pb} | ||
} | ||
|
||
func (builder ContractExecuteTransaction) SetMemo(memo string) ContractExecuteTransaction { | ||
return ContractExecuteTransaction{builder.TransactionBuilder.SetMemo(memo), builder.pb} | ||
} | ||
|
||
func (builder ContractExecuteTransaction) SetTransactionValidDuration(validDuration time.Duration) ContractExecuteTransaction { | ||
return ContractExecuteTransaction{builder.TransactionBuilder.SetTransactionValidDuration(validDuration), builder.pb} | ||
} | ||
|
||
func (builder ContractExecuteTransaction) SetTransactionID(transactionID TransactionID) ContractExecuteTransaction { | ||
return ContractExecuteTransaction{builder.TransactionBuilder.SetTransactionID(transactionID), builder.pb} | ||
} | ||
|
||
func (builder ContractExecuteTransaction) SetNodeAccountID(nodeAccountID AccountID) ContractExecuteTransaction { | ||
return ContractExecuteTransaction{builder.TransactionBuilder.SetNodeAccountID(nodeAccountID), builder.pb} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package hedera | ||
|
||
import ( | ||
"github.com/hashgraph/hedera-sdk-go/proto" | ||
) | ||
|
||
type ContractBytecodeQuery struct { | ||
QueryBuilder | ||
pb *proto.ContractGetBytecodeQuery | ||
} | ||
|
||
func NewContractBytecodeQuery() *ContractBytecodeQuery { | ||
pb := &proto.ContractGetBytecodeQuery{Header: &proto.QueryHeader{}} | ||
|
||
inner := newQueryBuilder(pb.Header) | ||
inner.pb.Query = &proto.Query_ContractGetBytecode{pb} | ||
|
||
return &ContractBytecodeQuery{inner, pb} | ||
} | ||
|
||
func (builder *ContractBytecodeQuery) SetContractId(id ContractID) *ContractBytecodeQuery { | ||
builder.pb.ContractID = id.toProto() | ||
return builder | ||
} | ||
|
||
func (builder *ContractBytecodeQuery) Execute(client *Client) ([]byte, error) { | ||
resp, err := builder.execute(client) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
|
||
return resp.GetContractGetBytecodeResponse().Bytecode, nil | ||
} |
Oops, something went wrong.