newTransactionFromObject() added.
@@ -14,32 +14,14 @@ import (
"github.com/icon-project/goloop/module"
)
-// TODO consider how to provide a convenient way of JSON string conversion
-// for JSON-RPC (But still it's optional)
-// TODO refactoring for the variation of serialization format and TX API version
-func newTransaction(b []byte) (module.Transaction, error) {
- if len(b) < 1 {
- return nil, common.ErrIllegalArgument
- }
-
- // Check serialization format
- // We assumes the legacy JSON format starts with '{'
- // Conceptually, serialization format version must be specified
- // from external modules.
- if b[0] == '{' {
- return newTransactionLegacy(b)
- } else {
- return nil, nil
- }
-}
-
-type source interface {
+type (
+ source interface {
bytes() []byte
hash() []byte
verifySignature() error
}
-type transaction struct {
+ transaction struct {
source
group module.TransactionGroup
@@ -57,6 +39,38 @@ type transaction struct {
hash []byte
bytes []byte
}
+)
+
+// TODO consider how to provide a convenient way of JSON string conversion
+// for JSON-RPC (But still it's optional)
+// TODO refactoring for the variation of serialization format and TX API version
+func newTransaction(b []byte) (*transaction, error) {
+ if len(b) < 1 {
+ return nil, common.ErrIllegalArgument
+ }
+
+ // Check serialization format
+ // We assumes the legacy JSON format starts with '{'
+ // Conceptually, serialization format version must be specified
+ // from external modules.
+ if b[0] == '{' {
+ return newTransactionLegacy(b)
+ } else {
+ return nil, nil
+ }
+}
+
+// TODO redesign
+// newTransactionFromObject copies or creates transaction instance.
+func newTransactionFromObject(tx module.Transaction) (*transaction, error) {
+ t, ok := tx.(*transaction)
+ if ok {
+ // TODO deep copy or shallow copy?
+ return t, nil
+ }
+
+ panic("not implemented yet")
+}
func (tx *transaction) Group() module.TransactionGroup {
return tx.group
@@ -141,6 +155,7 @@ func (tx *transaction) validate(state trie.Mutable, txdb db.Bucket) error {
return tx.checkBalance(state)
}
+// TODO checkBalance should subtract from balance
func (tx *transaction) checkBalance(state trie.Mutable) error {
addr := tx.From().Bytes()
if serializedAccount, err := state.Get(addr); err == nil {
