SSC 토큰을 정식으로 출시하면 매일 매일 홀더에게 보팅을 해 주어야 합니다. 아직은 홀더 수가 적어서 수동으로 가능하지만 홀더 수가 늘어나면 프로그램의 도움을 받아야 합니다.
저는 C와 C++를 이용하던 세대라서 요즘 나오는 언어는 다시 배워야합니다. 스팀 블록체인을 접근할 수 있는 패키지는 파이썬과 node.js가 나와 있는데, 일단 익숙한 파이썬으로 작업을 해 봅니다.
스팀 엔진과 관련된 부분은 @wonsama님이 도와주실 예정입니다.
우선 보팅 대상 글을 뽑는 파이선 코드입니다.
def findTargetPosts(username):
fromDate, toDate = getTargetDate()
acc = Account(username)
operations = acc.get_account_history(-1, 3000, filter_by=["comment"])
for h in operations:
if ( h["parent_author"] == '') : # post
link = "@"+h["author"]+"/"+h["permlink"]
post = Post(link)
crTime = post["created"].strftime('%Y-%m-%dT%H:%M:%S')
if ( crTime == h["timestamp"] ) : # original post
if ( post["created"] > fromDate and post["created"] < toDate) :
print("%s steemit.com/@%s/%s %s"% (h["timestamp"], h["author"], h["permlink"], h["title"]))
elif (post["created"] < fromDate ) :
return
else :
print(["timestamp"], fromDate, toDate)
return
글을 수정하는 경우에도 새로운 글로 계속 검색이 되더군요. 그래서 확인을 해보니 글 생성시간과 블록의 timestamp가 같은 경우가 첫 글이라는 사실을 발견하고 해당 코드를 추가했습니다.
그리고 만 하루 동안 작성한 글을 찾기 위하여 아래 코드도 추가하였고요. 블록체인에는 GMT 기준으로 시간이 저장되어 있어서 KST와 차이를 고려하여 from, to 를 구했습니다.
def getTargetDate() :
t1 = t.time()
timestampVar = t.gmtime(t1); #현재 시각 가져옴 gmt +9(KST)
year = t.strftime('%Y', timestampVar);
month = t.strftime('%m', timestampVar);
day = t.strftime('%d', timestampVar); #년 월 일 분리
dt = datetime.date( int(year), int(month), int(day) )
tm = datetime.time( 13, 0, 0 ) # kst기준 22시
endDate = datetime.datetime.combine(dt, tm)
startDate = newDt - datetime.timedelta(hours=24) # 전일 22시
return startDate, endDate
이렇게 해서 홀더들의 새로운 글에 대하여 보팅할 준비가 완료되었습니다. 다음 할 일은 홀더들의 새로운 글에 대하여 자동으로 보팅해주는 기능을 개발하는 것입니다.