Skip to content

Commit af25cf3

Browse files
committed
Closes #3 - Added support for CTID Encode
1 parent bc496d7 commit af25cf3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

models/transaction.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package models
22

3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
38
// Set of common fields for every transaction
49
type BaseTransaction struct {
510
Account string
@@ -394,3 +399,25 @@ type Transaction struct {
394399
TransactionTicketCreate
395400
TransactionTrustSet
396401
}
402+
403+
/*
404+
* CTID spec: https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0037d-concise-transaction-identifier-ctid
405+
*/
406+
type CTID struct {
407+
LeadIn uint64
408+
LedgerIndex uint64
409+
TransactionIndex uint64
410+
NetworkId uint64
411+
}
412+
413+
/*
414+
* Encode CTID struct to XLS-37 CTID
415+
*/
416+
func (c *CTID) Encode() string {
417+
if c.LeadIn == 0 {
418+
c.LeadIn = uint64(0xC0000000)
419+
}
420+
cti := (c.LeadIn+c.LedgerIndex)<<32 + c.TransactionIndex<<16 + c.NetworkId
421+
ctid := fmt.Sprintf("%x", cti)
422+
return strings.ToUpper(ctid)
423+
}

0 commit comments

Comments
 (0)