forked from achal126/hedera-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
transaction.go
60 lines (47 loc) · 1.31 KB
/
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
package hedera
// #include <stdlib.h>
// #include "hedera.h"
import "C"
import "unsafe"
type transaction struct {
inner *C.HederaTransaction
}
type RawTransaction struct {
inner *C.HederaTransaction
}
func (tx transaction) Operator(id AccountID) transaction {
C.hedera_transaction_set_operator(tx.inner, cAccountID(id))
return tx
}
func (tx transaction) Node(id AccountID) transaction {
C.hedera_transaction_set_node(tx.inner, cAccountID(id))
return tx
}
func (tx transaction) Memo(memo string) transaction {
cStr := C.CString(memo)
defer C.free(unsafe.Pointer(cStr))
C.hedera_transaction_set_memo(tx.inner, cStr)
return tx
}
func (tx transaction) Fee(fee uint64) transaction {
C.hedera_transaction_set_fee(tx.inner, C.ulonglong(fee))
return tx
}
func (tx transaction) Sign(key SecretKey) RawTransaction {
return RawTransaction{tx.inner}.Sign(key)
}
func (tx transaction) Execute() (TransactionID, error) {
return RawTransaction{tx.inner}.Execute()
}
func (tx RawTransaction) Sign(key SecretKey) RawTransaction {
C.hedera_transaction_sign(tx.inner, &key.inner)
return tx
}
func (tx RawTransaction) Execute() (TransactionID, error) {
var id C.HederaTransactionId
res := C.hedera_transaction_execute(tx.inner, &id)
if res != 0 {
return TransactionID{}, hederaLastError()
}
return goTransactionID(id), nil
}