Domain for Organization and User Wallet in trading platform

Posted By : Krishna Verma | 29-Jul-2018

Hello, everyone, this is Krishna Verma, in this blog I am going to tell you about the Domain Structure with some basic general fields that are always there in a crypto Trading platform. First, let's discuss what is organization wallet, Organization wallet is something which is the wallet of admin where admin can see how much total balance in his wallet that users have deposited, organization wallet has a one to many relationships with users wallet because all users wallet are part of organization wallet. Now let us discuss user wallet, a user wallet is a wallet which contains all the details regarding a single user wallet like total balance, whenever a user will deposit amount in his wallet it will reflect that user wallet as well as organization wallet.

Domain for organization wallet :

 
/**
 * @author krishna
 *
 * @Dat28-Jun-2018
 */
@Entity
public class OrganizationWallet {

	public OrganizationWallet(Long adminId, String primaryAddress, Boolean isPrimary, Boolean isActive,
			CryptoCurrencyType cryptoCurrencyType, Long exchangeCountryId) {
		super();
		this.adminId = adminId;
		this.primaryAddress = primaryAddress;
		this.isPrimary = isPrimary;
		this.isActive = isActive;
		this.cryptoCurrencyType = cryptoCurrencyType;
		this.exchangeCountryId = exchangeCountryId;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	private Long adminId;

	private BigDecimal walletBalance = new BigDecimal(0);

	private BigDecimal shadowBalance = new BigDecimal(0);

	public OrganizationWallet() {
		super();
	}

	@Temporal(TemporalType.TIMESTAMP)
	private Date createdDate = new Date();


	private String primaryAddress;

	private Long currencyId;

	private Boolean isPrimary=true;

	private Boolean isActive = true;

	@Column(name = "currency_symbol")
	private FiatCurrencyType currencySymbol;

	public CryptoCurrencyType getCryptoCurrencyType() {
		return cryptoCurrencyType;
	}


	public void setCryptoCurrencyType(CryptoCurrencyType cryptoCurrencyType) {
		this.cryptoCurrencyType = cryptoCurrencyType;
	}

	private CryptoCurrencyType cryptoCurrencyType;
	
	private Long exchangeCountryId;

	@Column(precision = 20, scale = 8)
	private BigDecimal totalFeeCollected = new BigDecimal(0);


	public Boolean getIsPrimary() {
		return isPrimary;
	}


	public void setIsPrimary(Boolean isPrimary) {
		this.isPrimary = isPrimary;
	}

	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "organizationWallet")
	private List usersWallet;
	
	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}


	public Long getAdminId() {
		return adminId;
	}

	public void setAdminId(Long adminId) {
		this.adminId = adminId;
	}

	public BigDecimal getWalletBalance() {
		return walletBalance;
	}

	public void setWalletBalance(BigDecimal walletBalance) {
		this.walletBalance = walletBalance;
	}

	public BigDecimal getShadowBalance() {
		return shadowBalance;
	}

	public void setShadowBalance(BigDecimal shadowBalance) {
		this.shadowBalance = shadowBalance;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public String getPrimaryAddress() {
		return primaryAddress;
	}

	public void setPrimaryAddress(String primaryAddress) {
		this.primaryAddress = primaryAddress;
	}

	public Long getCurrencyId() {
		return currencyId;
	}


	public void setCurrencyId(Long currencyId) {
		this.currencyId = currencyId;
	}


	public Boolean getIsActive() {
		return isActive;
	}


	public void setIsActive(Boolean isActive) {
		this.isActive = isActive;
	}


	public FiatCurrencyType getCurrencySymbol() {
		return currencySymbol;
	}

	public void setCurrencySymbol(FiatCurrencyType currencySymbol) {
		this.currencySymbol = currencySymbol;
	}

	public Long getExchangeCountryId() {
		return exchangeCountryId;
	}

	public void setExchangeCountryId(Long exchangeCountryId) {
		this.exchangeCountryId = exchangeCountryId;
	}


	public BigDecimal getTotalFeeCollected() {
		return totalFeeCollected;
	}


	public void setTotalFeeCollected(BigDecimal totalFeeCollected) {
		this.totalFeeCollected = totalFeeCollected;
	}

	public List getUsersWallet() {
		return usersWallet;
	}


	public void setUsersWallet(List usersWallet) {
		this.usersWallet = usersWallet;
	}

}

here FiatCurrencyType is an enum used for fiat Currency.

 
public enum FiatCurrencyType {
	USD,INR,YEN
}

CryptoCurrencyType is an enum for cryptoCurrencies in which we are dealing with.

public enum CryptoCurrencyType {
	BTC,BCH,ETH,LTC
}
 

Domain for user Wallet with basic general fields is:

/**
 * @author krishna
 *
 * @Dat28-Jun-2018
 */
@Entity
public class UserWallet implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	private BigDecimal walletBalance = new BigDecimal(0);

	private BigDecimal blockChainBalance = new BigDecimal(0);

	private BigDecimal shadowBalance = new BigDecimal(0);

	private Long currencyId;

	private String address = "";
	
	private Long exchangeId;
	
	private CryptoCurrencyType cryptoCurrencyType;

	@Column
	private Boolean isActive = true;

	@Column(name = "currency_symbol")
	private FiatCurrencyType currencySymbol;

	private Long userId;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(updatable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
	private Date updatedDate = new Date();

	@JsonIgnore
	@ManyToOne
	private OrganizationWallet organizationWallet;

	public UserWallet(String address, Long exchangeId, CryptoCurrencyType cryptoCurrencyType,
			OrganizationWallet organizationWallet, Boolean isActive, Long userId) {
		super();
		this.address = address;
		this.exchangeId = exchangeId;
		this.cryptoCurrencyType = cryptoCurrencyType;
		this.organizationWallet = organizationWallet;
		this.isActive = isActive;
		this.userId = userId;
	}

	public CryptoCurrencyType getCryptoCurrencyType() {
		return cryptoCurrencyType;
	}

	public void setCryptoCurrencyType(CryptoCurrencyType cryptoCurrencyType) {
		this.cryptoCurrencyType = cryptoCurrencyType;
	}

	public Long getExchangeId() {
		return exchangeId;
	}

	public void setExchangeId(Long exchangeId) {
		this.exchangeId = exchangeId;
	}



	public OrganizationWallet getOrganizationWallet() {
		return organizationWallet;
	}

	public void setOrganizationWallet(OrganizationWallet organizationWallet) {
		this.organizationWallet = organizationWallet;
	}

	public String getAddress() {
		return address;
	}

	public UserWallet(String address, Boolean isActive, Long userId) {
		super();
		this.address = address;
		this.isActive = isActive;
		this.userId = userId;
	}

	public UserWallet() {
		super();
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public BigDecimal getWalletBalance() {
		return walletBalance;
	}

	public void setWalletBalance(BigDecimal walletBalance) {
		this.walletBalance = walletBalance;
	}

	public BigDecimal getShadowBalance() {
		return shadowBalance;
	}

	public void setShadowBalance(BigDecimal shadowBalance) {
		this.shadowBalance = shadowBalance;
	}

	public Long getCurrencyId() {
		return currencyId;
	}

	public void setCurrencyId(Long currencyId) {
		this.currencyId = currencyId;
	}

	public Boolean getIsActive() {
		return isActive;
	}

	/**
	 * @return the blockChainBalance
	 */
	public BigDecimal getBlockChainBalance() {
		return blockChainBalance;
	}

	/**
	 * @param blockChainBalance
	 *            the blockChainBalance to set
	 */
	public void setBlockChainBalance(BigDecimal blockChainBalance) {
		this.blockChainBalance = blockChainBalance;
	}

	public void setIsActive(Boolean isActive) {
		this.isActive = isActive;
	}

	

	/**
	 * @return the currencySymbol
	 */
	public FiatCurrencyType getCurrencySymbol() {
		return currencySymbol;
	}

	/**
	 * @param currencySymbol the currencySymbol to set
	 */
	public void setCurrencySymbol(FiatCurrencyType currencySymbol) {
		this.currencySymbol = currencySymbol;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Date getUpdatedDate() {
		return updatedDate;
	}

	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}
}

these domain Organization Wallet and User Wallet can store both FiatWallet and cryptoWallet of the user as well as the organization. Now you just have to use the domain and update the user wallet and organization wallet whenever a deposit request comes to user wallet. thanks

About Author

Author Image
Krishna Verma

Krishna is a Software Developer having key skills in java , his hobbies are learning new technologies

Request for Proposal

Name is required

Comment is required

Sending message..