aboutsummaryrefslogtreecommitdiffstats
path: root/mobile/common.go
diff options
context:
space:
mode:
authorNicolas Guillaume <gunicolas@sqli.com>2017-05-23 17:16:25 +0800
committerNicolas Guillaume <gunicolas@sqli.com>2017-05-23 17:16:25 +0800
commit30cc1c3bf0a4747bef6b01d835b291721ba5dcb3 (patch)
tree359e72100099616553a3739a92685d3c244bd87c /mobile/common.go
parentda636c53d6ebb2588b2a7b8b2cdaeecd06d7dcf0 (diff)
downloadgo-tangerine-30cc1c3bf0a4747bef6b01d835b291721ba5dcb3.tar
go-tangerine-30cc1c3bf0a4747bef6b01d835b291721ba5dcb3.tar.gz
go-tangerine-30cc1c3bf0a4747bef6b01d835b291721ba5dcb3.tar.bz2
go-tangerine-30cc1c3bf0a4747bef6b01d835b291721ba5dcb3.tar.lz
go-tangerine-30cc1c3bf0a4747bef6b01d835b291721ba5dcb3.tar.xz
go-tangerine-30cc1c3bf0a4747bef6b01d835b291721ba5dcb3.tar.zst
go-tangerine-30cc1c3bf0a4747bef6b01d835b291721ba5dcb3.zip
mobile: Add management methods to {Addresses,Topics,Hashes} structures
Diffstat (limited to 'mobile/common.go')
-rw-r--r--mobile/common.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/mobile/common.go b/mobile/common.go
index 779f22b4e..3090014c5 100644
--- a/mobile/common.go
+++ b/mobile/common.go
@@ -89,6 +89,18 @@ func (h *Hash) GetHex() string {
// Hashes represents a slice of hashes.
type Hashes struct{ hashes []common.Hash }
+// NewHashes creates a slice of uninitialized Hashes.
+func NewHashes(size int) *Hashes {
+ return &Hashes{
+ hashes: make([]common.Hash, size),
+ }
+}
+
+// NewHashesEmpty creates an empty slice of Hashes values.
+func NewHashesEmpty() *Hashes {
+ return NewHashes(0)
+}
+
// Size returns the number of hashes in the slice.
func (h *Hashes) Size() int {
return len(h.hashes)
@@ -102,6 +114,20 @@ func (h *Hashes) Get(index int) (hash *Hash, _ error) {
return &Hash{h.hashes[index]}, nil
}
+// Set sets the Hash at the given index in the slice.
+func (h *Hashes) Set(index int, hash *Hash) error {
+ if index < 0 || index >= len(h.hashes) {
+ return errors.New("index out of bounds")
+ }
+ h.hashes[index] = hash.hash
+ return nil
+}
+
+// Append adds a new Hash element to the end of the slice.
+func (h *Hashes) Append(hash *Hash) {
+ h.hashes = append(h.hashes, hash.hash)
+}
+
// Address represents the 20 byte address of an Ethereum account.
type Address struct {
address common.Address
@@ -164,6 +190,18 @@ func (a *Address) GetHex() string {
// Addresses represents a slice of addresses.
type Addresses struct{ addresses []common.Address }
+// NewAddresses creates a slice of uninitialized addresses.
+func NewAddresses(size int) *Addresses {
+ return &Addresses{
+ addresses: make([]common.Address, size),
+ }
+}
+
+// NewAddressesEmpty creates an empty slice of Addresses values.
+func NewAddressesEmpty() *Addresses {
+ return NewAddresses(0)
+}
+
// Size returns the number of addresses in the slice.
func (a *Addresses) Size() int {
return len(a.addresses)
@@ -185,3 +223,8 @@ func (a *Addresses) Set(index int, address *Address) error {
a.addresses[index] = address.address
return nil
}
+
+// Append adds a new address element to the end of the slice.
+func (a *Addresses) Append(address *Address) {
+ a.addresses = append(a.addresses, address.address)
+}