-
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.
- Loading branch information
1 parent
10f19a3
commit ab4e8e8
Showing
4 changed files
with
134 additions
and
4 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,58 @@ | ||
package hedera | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashgraph/hedera-sdk-go/hedera_proto" | ||
) | ||
|
||
type AccountCreateTransaction struct { | ||
TransactionBuilder | ||
client *Client | ||
body hedera_proto.CryptoCreateTransactionBody | ||
maxTransactionFee uint64 | ||
} | ||
|
||
func NewAccountCreateTransaction(client *Client) AccountCreateTransaction { | ||
return AccountCreateTransaction{ | ||
client: client, | ||
body: hedera_proto.CryptoCreateTransactionBody{}, | ||
} | ||
} | ||
|
||
func (transaction AccountCreateTransaction) SetMaxTransactionFee(tinybar uint64) AccountCreateTransaction { | ||
transaction.maxTransactionFee = tinybar | ||
|
||
return transaction | ||
} | ||
|
||
func (transaction AccountCreateTransaction) SetKey(publicKey Ed25519PublicKey) AccountCreateTransaction { | ||
// fixme: use our own built in function for this | ||
protoKey := hedera_proto.Key_Ed25519{Ed25519: publicKey.keyData} | ||
|
||
transaction.body.Key = &hedera_proto.Key{Key: &protoKey} | ||
return transaction | ||
} | ||
|
||
func (transaction AccountCreateTransaction) SetInitialBalance(tinybar uint64) AccountCreateTransaction { | ||
transaction.body.InitialBalance = tinybar | ||
|
||
return transaction | ||
} | ||
|
||
func (transaction AccountCreateTransaction) validate() error { | ||
if transaction.body.Key == nil { | ||
return fmt.Errorf("AccountCreateTransaction requires .setKey") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (transaction AccountCreateTransaction) Build() (Transaction, error) { | ||
if err := transaction.validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
// not implemented yet | ||
return nil, 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
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,25 @@ | ||
package hedera | ||
|
||
import "strings" | ||
|
||
type ErrorTransactionValidation struct { | ||
Messages []string | ||
Err error | ||
} | ||
|
||
func (e *ErrorTransactionValidation) Error() string { | ||
return "The following requirements were not met: \n" + strings.Join(e.Messages, "\n") | ||
} | ||
|
||
// fixme: this should probably be a struct with those functions implementat on it | ||
type Transaction interface { | ||
Execute() error | ||
ExecuteForReceipt() (TransactionReceipt, error) | ||
} | ||
|
||
type TransactionBuilder interface { | ||
SetMaxTransactionFee(uint64) *TransactionBuilder | ||
SetMemo(string) | ||
validate() ErrorTransactionValidation | ||
Build() (Transaction, error) | ||
} |
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,41 @@ | ||
package hedera | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/hashgraph/hedera-sdk-go/hedera_proto" | ||
) | ||
|
||
var ErrNoReceipt = errors.New("response was not `TransactionGetReceipt`") | ||
|
||
type TransactionReceipt struct { | ||
inner *hedera_proto.TransactionReceipt | ||
} | ||
|
||
func TransactionReceiptFromResponse(response hedera_proto.Response) (*TransactionReceipt, error) { | ||
transactionGetReceipt := response.GetTransactionGetReceipt() | ||
|
||
if transactionGetReceipt == nil { | ||
return nil, ErrNoReceipt | ||
} | ||
|
||
receipt := TransactionReceipt{ | ||
transactionGetReceipt.Receipt, | ||
} | ||
|
||
return &receipt, nil | ||
} | ||
|
||
func (transactionReceipt *TransactionReceipt) AccountID() *AccountID { | ||
internalID := transactionReceipt.inner.AccountID | ||
|
||
if internalID == nil { | ||
return nil | ||
} | ||
|
||
return &AccountID{ | ||
uint64(internalID.ShardNum), | ||
uint64(internalID.RealmNum), | ||
uint64(internalID.AccountNum), | ||
} | ||
} |