Beispiel #1
0
// Extract is a helper function to extract information from an xdr.Asset
// structure.  It extracts the asset's type to the `typ` input parameter (which
// must be either a *string or *xdr.AssetType).  It also extracts the asset's
// code and issuer to `code` and `issuer` respectively if they are of type
// *string and the asset is non-native
func (a Asset) Extract(typ interface{}, code interface{}, issuer interface{}) error {
	switch typ := typ.(type) {
	case *AssetType:
		*typ = a.Type
	case *string:
		switch a.Type {
		case AssetTypeAssetTypeNative:
			*typ = "native"
		case AssetTypeAssetTypeCreditAlphanum4:
			*typ = "credit_alphanum4"
		case AssetTypeAssetTypeCreditAlphanum12:
			*typ = "credit_alphanum12"
		}
	default:
		return errors.New("can't extract type")
	}

	if code != nil {
		switch code := code.(type) {
		case *string:
			switch a.Type {
			case AssetTypeAssetTypeCreditAlphanum4:
				an := a.MustAlphaNum4()
				*code = strings.TrimRight(string(an.AssetCode[:]), "\x00")
			case AssetTypeAssetTypeCreditAlphanum12:
				an := a.MustAlphaNum12()
				*code = strings.TrimRight(string(an.AssetCode[:]), "\x00")
			}
		default:
			return errors.New("can't extract code")
		}
	}

	if issuer != nil {
		switch issuer := issuer.(type) {
		case *string:
			switch a.Type {
			case AssetTypeAssetTypeCreditAlphanum4:
				an := a.MustAlphaNum4()
				raw := an.Issuer.MustEd25519()
				*issuer = strkey.MustEncode(strkey.VersionByteAccountID, raw[:])
			case AssetTypeAssetTypeCreditAlphanum12:
				an := a.MustAlphaNum12()
				raw := an.Issuer.MustEd25519()
				*issuer = strkey.MustEncode(strkey.VersionByteAccountID, raw[:])
			}
		default:
			return errors.New("can't extract issuer")
		}
	}

	return nil
}
Beispiel #2
0
// SourceAddress returns the strkey-encoded account id that paid the fee for
// `tx`.
func (tx *Transaction) SourceAddress() string {
	sa := tx.Envelope.Tx.SourceAccount
	pubkey := sa.MustEd25519()
	raw := make([]byte, 32)
	copy(raw, pubkey[:])
	return strkey.MustEncode(strkey.VersionByteAccountID, raw)
}
Beispiel #3
0
// Address returns the strkey encoded form of this AccountId.  This method will
// panic if the accountid is backed by a public key of an unknown type.
func (aid *AccountId) Address() string {
	if aid == nil {
		return ""
	}

	switch aid.Type {
	case CryptoKeyTypeKeyTypeEd25519:
		ed := aid.MustEd25519()
		raw := make([]byte, 32)
		copy(raw, ed[:])
		return strkey.MustEncode(strkey.VersionByteAccountID, raw)
	default:
		panic(fmt.Errorf("Unknown account id type: %v", aid.Type))
	}
}
Beispiel #4
0
func (kp *Full) Address() string {
	return strkey.MustEncode(strkey.VersionByteAccountID, kp.publicKey()[:])
}
Beispiel #5
0
// Address returns the StrKey encoded form of the PublicKey associated with this
// PrivateKey.
func (privateKey *PrivateKey) Address() string {
	return strkey.MustEncode(strkey.VersionByteAccountID, privateKey.keyData[32:])
}
Beispiel #6
0
// Address returns the StrKey encoded form of the PublicKey
func (publicKey *PublicKey) Address() string {
	return strkey.MustEncode(strkey.VersionByteAccountID, publicKey.keyData[:])
}
Beispiel #7
0
// Seed returns the strkey encoded Seed for this PrivateKey
func (privateKey *PrivateKey) Seed() string {
	return strkey.MustEncode(strkey.VersionByteSeed, privateKey.rawSeed[:])
}